IRC channel logs

2022-07-29.log

back to list of logs

***chris is now known as Guest2590
***Guest2590 is now known as chrislck
<lilyp>sneek: later tell dthompson yeah the joke kinda is that the inner lambda has to roll the main loop – which fwiw would work if your game/engine had a global main-loop:iter
<sneek>Will do.
<lilyp>sneek later tell dthompson I don't think either Tsukundere or Chickadee have something like that though
<sneek>Okay.
<andrzejku>hello
<andrzejku>I am trying to understand macros
<andrzejku>do you have maybe something better than official Guile Reference?
<andrzejku>generally I get and idea
<unmatched-paren>andrzejku: I found this helpful to understand why we use define-syntax instead of define-macro: https://en.wikipedia.org/wiki/Hygienic_macro#The_hygiene_problem
<andrzejku> http://paste.debian.net/1248708/
<andrzejku>there are usually something with (if condition) in examples
<andrzejku>but I want to put a several expressions
<andrzejku>in sequence
<unmatched-paren>one moment
<andrzejku>unmatched-paren: ahh thsi hygiene I read it is about to not capture accidentally outer variables
<andrzejku>I acutally have problem with defining
<unmatched-paren> https://paste.sr.ht/~unmatched-paren/19d8a59b83479a2e8e75247fd845cbf9c81a4178
<andrzejku>also should I always use ...
<andrzejku>as I understood (begin exp ...) will execute all expressions given as the parameters
<unmatched-paren>if you want to be able to do (foo [ARG1] [ARG2] [ARG3]...) then use ..., if you want to do (foo (lambda () [ARG1] [ARG2] [ARG3])) then just accept a lambda argument
<unmatched-paren>although if you're going to accept a lambda you should probably just use a function
<unmatched-paren>(define (smth name body) (display name) (newline) (body))
<unmatched-paren>works just as well
<andrzejku>unmatched-paren: shit thanks for your time
<andrzejku>unmatched-paren: hmm I still got an error
<andrzejku> http://paste.debian.net/1248711/
<andrzejku>I tried to use your function
<unmatched-paren>source expression failed to match any pattern in form (syntax-rules () ((_ name body ...) (display name) (newline) body ...))
<andrzejku>maybe I have to import some module
<unmatched-paren>that's not my function :)
<andrzejku>unmatched-paren: that one https://paste.sr.ht/~unmatched-paren/19d8a59b83479a2e8e75247fd845cbf9c81a4178
<unmatched-paren>Ah, you meant my macro
<andrzejku>yes
<andrzejku>macro
<unmatched-paren>Hmm, that's strange. I'm pretty sure that's the right syntax
<andrzejku>I think too
<andrzejku>I am running the file using guile filename.scm
<unmatched-paren>btw, there's a shorthand for define-syntax/syntax-rules with one pattern
<andrzejku>I found that Guile is not good in errors and maybe some modules must be imported
<unmatched-paren>(define-syntax-rule (smth name body ...) (display name) (newline) body ...)
<unmatched-paren>no, there's no module imports needed here
<andrzejku>unmatched-paren: ya this I saw
<andrzejku>I wanted to improve it later
<unmatched-paren>but "guile is not good in errors" is pretty accurate :)
<andrzejku>unmatched-paren: ok the standard macro when
<andrzejku>works
<unmatched-paren>wdym "standard macro"?
<andrzejku> https://www.gnu.org/software/guile/manual/guile.html#Defining-Macros
<unmatched-paren>ah
<andrzejku>unmatched-paren: it looks for me that we can not put (define-syntax-rule (smth name body ...) (display name))
<andrzejku>the rest of arguments sequentially
<andrzejku>just display is accepted
<unmatched-paren>strange
<andrzejku>oh maybe it must me a lambda?
<unmatched-paren>i guess you could do (begin body ...)
<unmatched-paren>instead of body ...
<unmatched-paren>try that
<andrzejku>I tried already
<unmatched-paren>hmm
<andrzejku>not working
<andrzejku>(define-syntax-rule (smth name body ...) (display name) (begin body ...))
<unmatched-paren>Ah, i think I know the problem
<unmatched-paren>you can only do (syntax-rules ((...) (...)))
<unmatched-paren>you can only have two forms inside the body of the rule
<unmatched-paren>so (syntax-rules ((...) (...) (...) (...))) as we're doing won't worj
<unmatched-paren>work
<unmatched-paren>you need to wrap the body itself in a begin form
<unmatched-paren>and then you don't need the begin around the body ... either
<andrzejku>unmatched-paren: what's begin actually?
<unmatched-paren>begin just executes each of its forms, one after the other
<unmatched-paren>it's like { ... } in C-like language
<unmatched-paren>languages
<andrzejku>ya I pack the second rule argument in (lambda () () ()) but it needs additional () to be executed
<andrzejku>aa ok
<andrzejku>get it
<unmatched-paren>s/executes/evaluates/, mustn't forget the correct terminology :)
<unmatched-paren>if i did the lispers would come after me O_o
<andrzejku>unmatched-paren: thank you it works
<andrzejku>just one more question
<unmatched-paren>okay :)
<andrzejku>body and ... it is the same like the list of expr expr expr
<andrzejku>and expr is the function
<andrzejku>which can be executed
<unmatched-paren>i don't quite follow you
<unmatched-paren>(define-syntax-rules (foo expr ...) (begin expr ...))
<unmatched-paren>the exprs don't have to be functions
<andrzejku>I mean we write (begin expr ...)
<unmatched-paren>in fact they usually aren't
<andrzejku>but I can actually pass (+ 3 2)
<unmatched-paren>the exprs are actually just lists
<unmatched-paren>(list '+ 3 2)
<andrzejku>I read that it will be evaluated as 5
<unmatched-paren>and so is the "template"
<andrzejku>and then we have (begin 5 ...)
<unmatched-paren>(list 'begin 'expr '...')
<andrzejku>begin 5)
<unmatched-paren>the two are spliced together using guile's syntax-rules algorithm
<andrzejku>ohh
<unmatched-paren>and then treated as literal syntax
<unmatched-paren>guile syntax is just lists
<unmatched-paren>this is illustrated by the traditional macro style, define-macro:
<unmatched-paren>(define-macro (foo bar) ...)
<unmatched-paren>now `bar` is bound to a syntax object
<unmatched-paren>which is either a list or an atom like 3, "hello", or 'foo
<unmatched-paren>and a macro is supposed to return a syntax object itself
<unmatched-paren>(define-macro (foo bar) `(display ,foo))
<unmatched-paren>(define-macro (foo bar) `(display ,bar))
<unmatched-paren>sorry, mistake :)
<andrzejku>unmatched-paren: ahh that's enough hard to understand
<unmatched-paren>so define-macro uses quote/unquote to construct actual syntax objects
<unmatched-paren>but it suffers from the hygiene problem
<andrzejku>unmatched-paren: is it explained in any book?
<andrzejku>I started with structure and interpretation
<andrzejku>but just wanted to write a macro
<andrzejku>hehe
<unmatched-paren>andrzejku: https://spritely.institute/static/papers/scheme-primer.html#scheme-extensibility
<andrzejku>unmatched-paren: thank you
<unmatched-paren>there's probably a few books, but it's a simple enough concept
<unmatched-paren>you don't need a book to understand it
<andrzejku>ok
<andrzejku>unmatched-paren: by the way I got a little schemer and The Scheme Programming Language
<andrzejku>looks more than enough :P
<dsmith-work>Happy Friday, Guilers!!
<dthompson>happy friday
<sneek>Welcome back dthompson, you have 2 messages!
<sneek>dthompson, lilyp says: yeah the joke kinda is that the inner lambda has to roll the main loop – which fwiw would work if your game/engine had a global main-loop:iter
<sneek>dthompson, lilyp says: I don't think either Tsukundere or Chickadee have something like that though
<dthompson>lilyp: yeah chickadee just uses coroutines instead. in the context of a coroutine a call-with-cursor procedure would work as expected.
*spk121 just can't autotools any more
***daviid` is now known as daviid