IRC channel logs

2024-03-20.log

back to list of logs

<dsmith>sneek, botsnack
<sneek>:)
<dsmith>!uptime
<sneek>I've been aware for 8 days
<sneek>This system has been up 1 week, 1 day, 1 hour, 24 minutes
<old>.
<freakingpenguin>Hi Guile! I want to write a macro that takes a function name, then creates a new top-level definition with a modified name (e.g. foo*). I'm having trouble figuring out how to modify the name.
<freakingpenguin> https://paste.debian.net/1311434/
<dthompson>freakingpenguin: I would advice not doing that but you're code is missing datum->syntax around the symbol-append
<dthompson>advise*
<dthompson>your*
<dthompson>oof can't type today
<freakingpenguin>dthompson: Fair, I'll probably wind up doing it with functions in the end but now I'm curious.
<freakingpenguin>So (define-public ((datum->syntax (symbol-append ...))))? That seems to still have the issue where define is given "(stuff)" and not "stuff", and it still complains about pattern variables if I #,.
<dthompson>datum->syntax takes 2 args
<dthompson>and you need to unquote the syntax
<dthompson>since you're in a syntax quasiquote
<freakingpenguin>Sorry, is this what you're talking about? https://paste.debian.net/1311438/
<dthompson>yeah
<dthompson>but you haven't syntax quoted name
<dthompson>(syntax->datum #'name)
<freakingpenguin>My mind is blown
<freakingpenguin>I thought the pattern variables were weird mini syntax objects. What the heck are they?
<freakingpenguin>Thanks for the help!
<dthompson>they are pattern variables :)
<dthompson>they can be converted to syntax objects via syntax-quote and friends
<dthompson>syntax-case is an odd language but it will start making sense eventually
<freakingpenguin>I've not touched match often, does that mean when you move a list through a pattern matcher it loses type information in some capacity?
<freakingpenguin>Please tell me x in the code is a list of two syntax objects.
<dthompson>x is a syntax object, yes
<dthompson>you can think of syntax-case as a pattern matcher for syntax objects
<freakingpenguin>Thanks for all the help! At least I know more than I did yesterday.
<dthompson>np!
<dthompson>I dunno if this helps but it's cool that you can just use syntax-case for whatever: (syntax-case (datum->syntax #f 'foo) () (name #'(list 'name)))
<dthompson>like you can just eval this in your repl, completely outside of a macro, and it works
<freakingpenguin>I think my problem is I was thinking in terms of (match), not (case).
<dthompson>syntax-case is more like match than case
<freakingpenguin>Well nevermind that haha
<dthompson>it's a pattern matcher of sorts :)
<freakingpenguin>Match binds the pattern variables to their value, but it weirds me out that if (syntax (foo bar)) gives a list of syntax objects, when running syntax-case we need to wrap the pattern variables in (syntax). Shouldn't it already be one?
<freakingpenguin>It feels like (syntax (syntax name))
<dthompson>no because syntax bindings are different, they aren't regular variables
<dthompson>if it worked as you said, then you couldn't freely reference pattern variables in a syntax-quote form
<dthompson>like in my example above I could do #'(list 'name) without having to do anything special to the pattern variable 'name'
<freakingpenguin>That's true.
<dthompson>and it makes the use of ellipsis convenient, etc.
<freakingpenguin>Also, nice article on Guile optimizations! You are what I aspire to achieve. :)
<dthompson>freakingpenguin: aww thanks :)