IRC channel logs

2023-01-24.log

back to list of logs

<dadinn>hi all
<dadinn>I am trying to get some better understanding of using hygienic macros with syntax-case.
<dadinn>I am not sure how to generate temporary symbols for bindings, so that I can create a let binding and reuse the same symbols in the body... for some reason they get randomised, and the ones in the body don't refer to the the one in the let bindings
<dadinn>I have this code with a test to show the issue: https://termbin.com/kt72
<dadinn>sorry, some the modules imports for expect where missing: https://termbin.com/b2ys
<dadinn>is this something only possible to do with defmacro and gensym?
<apteryx>how would I go to append a file at the end of another one?
<flatwhatson>apteryx: create the output port with (open-file "path/to/output" "a"), write a loop which reads the input file and writes to this "append" mode output port
<flatwhatson>super lazy version is just to read both the input and output, string-append them, and overwrite the output
<daviid>or (system* "cat" "this-file" ">>" "at-the-end-of-this-file")
<apteryx>flatwhatson: I was looking at sendfile, seems it should be useful here?
<apteryx>strange, Emacs doesn't indent call-with-input-file the same as call-with-output-file
<daviid>apteryx: high chances are one is missing in the .emacs 'put ...' section
<flatwhatson>apteryx: yes sendfile looks much better than writing your own read/write loop, nice
<apteryx>daviid: shouldn't that be in scheme-mode?
<apteryx>seems it should already be there, looking at C-h v scheme-font-lock-keywords-2
<apteryx>perhaps the regexps are tripped
<apteryx>looks like this: https://paste.debian.net/1268276/
<flatwhatson>apteryx: that says "call-with-open-file" not "call-with-output-file"
<flatwhatson>i don't think that exists, but for the same effect you can use (call-with-port (open-file ...) (lambda (port) ...))
<flatwhatson>you can use flycheck-guile to hilight this kind of "possibly undefined variable" warning in-buffer, assuming you've already got geiser set up
<daviid>apteryx: actually i meant (system (string-append "cat " i-file " >> " o-file)) - unless you are willing to do this in 'pure scheme' ...
<old>lloda: oh I see
<old>I learn every day here
<apteryx>flatwhatson: if you navigate to scheme.el, you'll see both listed there: "call-with-input-file" "call-with-output-file"
<apteryx>works in a simple buffer, but not in my code (perhaps the guix gexp readers are confusing it)
<flatwhatson>apteryx: i mean in the snippet you pasted, you had written "call-with-open-file" as a typo
<apteryx>ah? thanks!
<apteryx>it works better without my typo :-)
<apteryx>I'm using sha256 from guile-gcrypt to compute a checksum, and it returns a bytevector. can I get a string representation via bytevector->string?
<apteryx>nope; perhaps via format
<flatwhatson>apteryx: hence my suggestion of flycheck-guile, it helps to catch typos like that ;)
<flatwhatson>(especially with guile 3.0.9 which reports warning locations properly)
<haugh>Can I query the procedure associated with a current hash extension, a la read-hash-extend?
<lloda>haugh: (fluid-ref %read-hash-procedures) will return an alist of the procedures installed
<lloda>be aware that isn't documented and is probably meant to be private, it just leaks because it's in boot-9
<haugh>lloda, BIG UPS, thanks very much. Hopefully won't need it outside of debugging.
<lloda>yw
<dadinn>hi all
<dadinn>I am playing with hygienic macros using syntax-case, and would need some help understanding why my generate-temporaries binding symbols get messed up. Here is the macro definition and some test code:
<dadinn> https://termbin.com/b2ys
<dadinn>it seems that the temporary symbols in the let bindings get randomised compared to the ones I try to reference from the let body
<lloda> https://www.gnu.org/software/guile/manual/html_node/Top-Level.html needs some changes, specifically 'define expression'. Those two words don't appear together in r5rs, which consistently talks about 'defintions' on one hand and 'expressions' on the other
<lloda>for example the manual says 'The return value of a define expression is unspecified', which makes no sense bc you cannot put a definition anywhere where values are expected
<apteryx>flatwhatson: thanks for the suggestion flycheck-guile, I'll try it out!
<apteryx>to answer my question yesterday as to how to format the sha256 bytevector hash as returned by sha256 from (gcrypt hash): (format #f "~{~x~}" (bytevector->u8-list hash-bv))
<old>dadinn: Bindings introduced in a syntax transformer are always mangled with a shasum of something IIRC
<old>To introduce a fix binding, you need to use a syntax as the binding
<old>At least that's what I can remember
<mfiano>flatwhatson: Thanks for flycheck-guile! I was not aware of this when I wrote my Guile config for Emacs.
<mfiano>flatwhatson: One small typo in the README: "...pass an --r6rs or --r7rs argument argument..."
<dadinn>old: this is an example of the expansion in my code: https://termbin.com/sfap
<dadinn>old: as you can see the let bindings get a -1 suffix, while the cond clause tests refer to the same bindings without the -1 suffix. I am not sure what causes guile to try to make mutate these symbols
<dadinn>there is not much documentation on how to use generate-temporaries, I've seen that some places they are used together with with-syntax, but it seems if I use the same binding twice in the same template, then the macro expander thinks these should be made different :/
<dadinn>this is a trivial thing to do with defmacro and gensym. Is this something hygienic macros don't support?
<mirai>Is there a non-google link for "But if for some reason you’re stuck with syntax-rules, you might enjoy Joe Marshall’s syntax-rules Primer for the Merely Eccentric." http://sites.google.com/site/evalapply/eccentric.txt
<mirai>from: https://www.gnu.org/software/guile/manual/html_node/Syntax-Rules.html
<lloda>yeah we shouldn't have an account gated link in the manual :-/
<dadinn>mirai: I've read the merely eccentric guide, it but I don't remember it giving examples of generate-temporaries
<lloda>it's only for syntax-rules so
<dadinn>lloda: the link is actually not working in the manual. I've found this one with DuckDuckGo: http://www.phyast.pitt.edu/~micheles/syntax-rules.pdf
<dadinn>mirai: I've also read this paper, which does talk about generate-temporaries: https://legacy.cs.indiana.edu/~dyb/pubs/tr356.pdf
<dadinn>mirai: but my code is using it the same way, yet it doesn't work for me! :/
<lloda>if no one answers here you could try #scheme or guile-user
<mirai>dadinn: sorry for derailing your question
<mirai>I didn't mean to post it as an answer to you
<mirai>I'm actually interested in learning about how macros in (guile) scheme work
<mirai>and that link was leading me to a login page
<dadinn>lloda: thanks, will there too!
<dadinn>lloda: guile-user seems to be derelict
<lloda>it has ups and downs, but it is an active list