IRC channel logs

2023-08-07.log

back to list of logs

<RhodiumToad>g-golf port successfully added to freebsd ports tree
<daviid>RhodiumToad: wonderful, thanks! - do you have a link i could add to the project?
<RhodiumToad> https://www.freshports.org/devel/g-golf or https://cgit.freebsd.org/ports/tree/devel/g-golf
<daviid>thanks
<rekado>daviid: thanks for the reminder; gitile froze up again :-/
<ekaitz>Hi! i have a simple question about `syntax-rules'
<ekaitz>(define-syntax incr! (syntax-rules (incr!) ((incr! x) (set! x (+ x 1)))))
<ekaitz>why does it work also if I remove incr! from the literals in syntax-rules?
<ekaitz>what's the goal of the literals from syntax-rules then?
<ekaitz>I'm reading also the examples from the Guile docs where literals are used, I removed them and they work
<samplet>ekaitz: Try the ‘cond1’ example without literals. When using it, replace ‘else’ with ‘foo’.
<samplet>Wait.... That’s not right. :S
<ekaitz>it works!
<ekaitz>samplet: :)
<ekaitz>in chibi works too
<samplet>When I try the example as-is, I get “bad use of ‘else’”.
<ekaitz>oh
<samplet>I mean the example without modifications.
<ekaitz>i don't
<samplet>I’m in the REPL. Let me try with a file.
<ekaitz>i'm in a file (guile 3.0.9)
<samplet>Same thing in a file for me....
<ekaitz>what part of the file is failing?
<samplet>When I write ‘(cond1 else "hi")’.
<ekaitz>oh I have that too
<samplet>I get the same error with Chibi....
<ekaitz>yeah I do too
<ekaitz>maybe we are using it wrong
<ekaitz>in any case, i'd like to know how does the (syntax-case (literals...) ...) part work
<ekaitz>does anyone have a good link to describe this'
<ekaitz>?
<samplet>I think the ‘else’ case has to come first before the ‘test’ case. The manual is wrong.
<ekaitz>syntax-rules*
<ekaitz>samplet: with that new order works
<samplet>The problem is that our ‘else’ is matching the ‘test’ pattern. Then, the expander puts a bare ‘else’ as the test case, which causes the expander to expand ‘else’ as independent syntax. The ‘else’ syntax is defined to raise an error in that case to avoid accidental mistakes.
<samplet>Now, if you remove ‘else’ from the literals (leaving the cases in the good order), the error should come back.
<samplet>Oops! Nope. It works the way I said originally!
<ekaitz>samplet: it doesn't but I get what you mean
<samplet>You can do crazy stuff like replace ‘else’ (at the use-site) with ‘(/ 1 0)’ and everything is “fine”.
<ekaitz>so you mark it as a literal so it matches the rules that use the literal instead of the generic ones
<samplet>Exactly! Without the literal, ‘else’ is just a pattern that binds to anything. With the literal, it has to match ‘else’ as a keyword.
<ekaitz>now i understand
<ekaitz>thank you samplet
<samplet>ekaitz: Are you up for sending in a correction to the manual? :)
<ekaitz>yeah why not
<ekaitz>it's just moving the third block and put it in the second, right?
<samplet>Exactly. It would be a huge help, really. People get stuck on Scheme macros. They’re pretty unique in the programming world.
<samplet>I almost understand them, and all I had to do was write a gazillion macros, read a few academic papers, and write my own expander. :D
<ekaitz>hahah I struggled a lot with the macros too yeah
<ekaitz>i'm ok with define-macro
<ekaitz>but syntax-rules and all that is another level
<ekaitz>patch sent samplet !
<samplet>Yeah.... The thing with ‘define-macro’ is that hygiene bugs are very confusing when they happen. Mes does not have proper hygienic macros and I’ve lost a lot of my sanity to a few inscrutable bugs. At this point, I’m a fan of ‘syntax-rules’ even if it’s a little tricky.
<samplet>ekaitz: Awesome! Thank you.
<ekaitz>:)
<ekaitz>samplet: are these patches processed? because I sent a patch long time ago and I'm not sure if anyone read it...
<samplet>ekaitz: It takes a long time. Guile has a few “very part time” maintainers who commit patches every once in a while.
<samplet>I submitted a bug fix and it took a few months to land.
<samplet>Copyright assignment to the FSF can slow things down, too. (I’m a fan of the idea, the FSF has been slow about it lately. I think other groups have ways of moving faster.)
<samplet>I think the manual change is small enough that copyright doesn’t matter, though.
<samplet>Are you the ekaitz doing the RISC-V bootstrapping stuff?
<ekaitz>samplet: yes I am
<samplet>Nice. That’s very impressive work!
<dsmith>sneek, macros?
<sneek>Someone once said macros is http://hipster.home.xs4all.nl/lib/scheme/gauche/define-syntax-primer.txt
<ekaitz>sneek: thank you, there's a lot of people helping me
<ekaitz>dsmith: thanks!
<rlb>samplet: iirc there's also some subtlety around literals, i.e. they're not quite symbol matching. I hit that a while back and civodul (I think maybe it was) explained it to me, but I forget the details. The fix in my case was to switch to an explicit guard clause and syntax->datum to test symbol eq? instead of using literals... Was very confusing at the time.
<dsmith>!uptime
<sneek>I've been serving for 26 days
<sneek>This system has been up 18 weeks, 2 days, 1 hour, 1 minute
<samplet>rlb: Yeah. Under the hood it should be using ‘free-identifier=?’ (cf. https://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-13.html#node_sec_12.5). Things get a little muddy at that level.
<rlb>In my case, I needed it to *always* match the symbol, so I had to go the guard route (it seemed) -- also wondered why the current behavior was the default, since I'd have assumed that most cases would want that, but I assume it's covering some important subtleties. I just need a "really-literal" option :)
<rlb>I forget exactly which forms, but it was for matching clojure syntax, guessing 'catch 'finally, etc.
<daviid>rlb: you would have a link to this 'guard route' code?
<daviid>so we could look at it, (and bookmark :))