Fork me on GitHub
#beginners
<
2022-06-16
>
Will Sanders00:06:14

is anyone running on VS Code with Calva

dpsutton00:06:12

as of the last Clojure survey just under 20% or so of the Clojure community uses it. Far better to just ask a question than a question about your question. There's also #vscode and #calva channels specific to the editor and tooling

Jim Strieter04:06:17

Is there any way to get a REPL while debugging in Idea? For instance, if I set a breakpoint to line 103, and then debugger pauses at line 103, I want to type stuff at the repl like this:

my-project.core=> (get-in my-map [:key1 :key2 :key3])
Is this possible?

seancorfield05:06:40

That might be a better question for #cursive since it is tool-specific. In general, that sort of thing depends on how breakpoints are handled. There are ways to have exception handlers start REPLs inside the program but there are generally a lot of caveats around it. I think there have been some conference talks about it over the years, although I'm not sure what to search for to find those...

seancorfield05:06:12

Personally, I haven't used a step debugger and breakpoints in years... maybe not in decades... I used to use that approach with C and C++ and a little bit when I first started with Java but haven't felt the need for it since then, and never with Clojure. There are lots of debugging libraries that let you capture local environments, start REPLs, send values to additional visualization tools (REBL, Reveal, Portal). Given Clojure's dynamic nature, I find it easier to just instrument specific functions where I would have used breakpoints in C/C++.

jumar06:06:24

I use cider debugger all the time and I find it very useful. It has a way to evaluate expressions when the program is stopped at a breakpoint but it it's not as convenient as typing into normal buffer or repl. Intellij has a way to evaluate expressions while the program is stopped but I don't know how well that is integrated in Cursive because I don't use Cursive

Yosevu Kilonzo05:06:07

Hello, what am I missing with this regex? I expect a separate string for each markdown link, but I get one string in the seq.

seancorfield05:06:56

The problem is that \[.*\] is "greedy" and matches from the first [ to the *last* ]. You can get around that by using \[[^\]]*\] instead.

seancorfield05:06:46

Or you can use the non-greedy match \[.*?\]

seancorfield05:06:07

user=> (re-seq
  #_=>    #"\[.*?\]\(\)"
  #_=>    "more text [Link 1]() more text [Link 2]() more text")
("[Link 1]()" "[Link 2]()")
user=>

Yosevu Kilonzo05:06:13

Ah thanks sean, I was missing that concept. I will try it!

seancorfield05:06:29

Regex is hard.

Yosevu Kilonzo05:06:51

Yeah. I'd like to get a better general understanding of all the concepts. Do you have any resource/reading recommendations?

seancorfield05:06:06

Unfortunately, no. All I know about regex I've learned via Bing (and Google before that).

seancorfield05:06:03

I will say it's important to make sure you're reading about the Java regex implementation and not other languages' regexes tho' -- there are some subtle and important differences at times...

Yosevu Kilonzo05:06:34

Oh I see. Well thank you! I didn't think to reference the Java regex docs.

robertfw06:06:39

I've found https://regex101.com/ to be useful when puzzling through regexs. There are a few tools like this out there, this one does have the Java flavour available

๐Ÿ‘ 1
noisesmith20:06:01

there's a really amazing resource for reqular expressions - covers all major flavors including java: https://www.regular-expressions.info/

noisesmith20:06:41

it's where I learned about free-spacing mode, which I love https://www.regular-expressions.info/freespacing.html

noisesmith20:06:26

(def input
  (str "more text [Link 1]()"
       " more text [Lin k 2]()"
       "more text"))

(def regex
  #"(?x)                                  # free-spacing / comments enabled
    \[.*?\]                               # starts with [....] describing link
    \(\) # continues with (...) containing link")



(re-seq regex input)

Yosevu Kilonzo06:06:51

Awesome, thanks robertftw and noisesmith!

zeitstein08:06:30

I'd like to reduce output of db reads when testing. So given:

(defn pull [db id]
  ;; ...
  {:pull-result pull-result :pulled-ids pulled-ids})

(defn test-pull [db id]
  (let [{:keys [pulled-ids]} (pull db ids)]
    {:pull-result pulled-ids ;; note
     :pulled-ids pulled-ids}))
I'd like to be able to do something like this (which obviously can't work):
(with-redefs [pull test-pull]
  ...)
How can I achieve this? Just redefining pull to identity is no good.

delaguardo08:06:32

(defn pull [db id]
  ;; ...
  {:pull-result pull-result :pulled-ids pulled-ids})

(let [origin-pull pull]
  (with-redefs [pull (fn [db id]
                       (let [{:keys [pulled-ids]} (origin-pull db id)]
                         {:pull-result pulled-ids ;; note
                          :pulled-ids pulled-ids}))]
    (pull ...)))
try this

zeitstein12:06:29

Hah, nice workaround ๐Ÿ™‚ Thank you!

the-alchemist20:06:24

quick question about ##. I only see it in the the context of ##Inf ##-Inf ##NaN. is ## used for anything else? what does it actually mean? thanks all ๐Ÿ™‚

Alex Miller (Clojure team)20:06:34

it's a symbolic value and it is not used for anything else

๐Ÿ™‡ 1
Lukas21:06:25

Hey, I'm trying to parse a document with instaparse, but I'm currently stuck parsing multiple lines. This is my grammar so far:

document = line
line = (<spaces*> word)* <eol>
eol = spaces* ('\n' | Epsilon)
spaces = ' '*
word = #'[\S]+'
but when I change the first line to parse multiple lines
document = line*
I get this as output
[:document
 [:line [:word "this"]]
 [:line]
 [:line [:word "is"]]
 [:line]
 [:line [:word "line1"]]
 [:line]
 [:line [:word "this"]]
 [:line]
 [:line [:word "is"]]
 [:line]
 [:line [:word "line2"]]]
does anyone know what I do wrong here? Any help is appreciated ๐Ÿ™‚

phronmophobic21:06:12

this seems to work:

document = line*
line = (<spaces*> word)+ eol
eol = spaces* ('\n' | Epsilon)
spaces = ' '*
word = #'[\S]+'

phronmophobic21:06:42

for this input:

Helloworld!
asdfa
asdfa
asf

Lukas21:06:02

try this as Input

this is the first line
this is the second

Lukas21:06:24

document = line*
line = (spaces* word spaces*)+ eol
eol = ('\n' | Epsilon)
spaces = ' '*
word = #'[\S]+'
this works

phronmophobic21:06:26

ok, I also got this to work:

document = line* lastline
lastline = (<spaces*> word)+ (eol | Epsilon)
line = (<spaces*> word)+ eol
eol = ' '* ('\n')
spaces = ' '*
word = #'[\S]+'

phronmophobic21:06:40

basically, every line must have a newline except the last line

phronmophobic21:06:09

for your most recent example, there are multiple valid parsers and some of them aren't right

Lukas21:06:55

ah cool, I tried something similar but ditched it because the actual grammar inside the line is more complicated and I didn't want to repeat the rules just for the last line ๐Ÿ˜„

phronmophobic21:06:00

Epsilon is just the empty parser. Trying to find if there's some that matches something like EOF

phronmophobic21:06:24

this seems to work:

document = line* 
line = (<spaces*> word)+ (eol | EOF)
eol = ' '* ('\n')
spaces = ' '*
word = #'[\S]+'
EOF= #"$"

Lukas22:06:33

thanks a lot

Lukas22:06:40

instaparse is awesome, isn't it? I wish I could use it more often to get fluent with it ๐Ÿ™‚

metal 1
alpox22:06:58

document = line*
line = (<spaces> word)* <eol>
eol = spaces ('\n' | #'$')
spaces = ' '*
word = #'\S+'

alpox22:06:11

Appears to work as well

phronmophobic22:06:12

I would probably still go with something like:

document = (line-content <eol>)* line-content (<eol> | Epsilon)
line-content = (<spaces*> word)* spaces*
eol =  '\n'
spaces = ' '*
word = #'[\S]+'

hiredman21:06:05

remove the <>

hiredman21:06:09

are you sure that is the grammar you are actually using?

Lukas21:06:18

ye pretty sure

Lukas21:06:05

for example:

document = line line
has the output I expect for 2 lines

hiredman21:06:40

if you remove the <> you can see exactly what instaparse parsed and matched for each production

๐Ÿ‘ 1
hiredman21:06:56

your issue is basically eol matches the empty string

hiredman21:06:24

0 or more spaces fallowed by a newline or the empty string

Lukas21:06:04

Do you know how to express "either new line or eof"?

Drew Verlee22:06:17

"\n" is new line ...