IRC channel logs

2020-06-05.log

back to list of logs

<apteryx>I'm trying to compile GNU Anubis with Guile 3, and getting: libguile.h: No such file or directory. Was this file only present in Guile 2?
<apteryx>ah no, it's present in both. probably it's looking at 2.2/libguile.h
<wingo>sneek: later tell civodul it is a good idea :)
<sneek>Got it.
<wingo>sneek: referring to the source slot in syntax objects
<wingo>o/
<regtur>hi civodul/wingo, can I redirect your attention to the PEG patch I sent on May 11 (now that the copyright assignemnt is with the FSF)?
<civodul>hi regtur!
<civodul>thanks for pinging, i'm a bit swamped but i'll see if i can take a look soon
<civodul>sorry for the delay again
<civodul>actually perhaps others more familiar with PEG can comment, too
<regtur>would be greatly appreciated, thanks
<chrislck>manumanumanu: for (match) I always find it easier to write the match pattern whole before adding predicates. eg. (match input ((a b (c . d) e) ...)), then switching predicate inline: (match input ((a b (c . (? string? d)) e) ...))
<dsmith-work>Happy Friday, Guilers!!
<allana>Hi #guile. I am beginning my journey into guile and scheme. I have been using GNU guix for a bit over a year now, maybe two. I have been struggling with package definitions in scheme, and I have decided that it really is time to take a deeper dive. I plan to use it professionally as well. I'm beginning this journey by reading through the guile "info" pages and playing around in the guile repl. Is this a good place to start? Would anyone
<allana>have other recommendations?
<sneek>Welcome back allana, you have 1 message!
<sneek>allana, terpri_ says: the patch should be in guix master very soon, simply haven't gotten around to submitting it properly yet
***rekado_ is now known as rekado
<rekado>allana: welcome! Playing with the REPL is a great way to get more comfortable with Guile.
<allana>rekado: Thanks for the affirmation.
<leoprikler>Can anyone tell me a good "syntax highlighting" package for Guile, that exports to LaTeX?
<rekado>I only know of https://dthompson.us/projects/guile-syntax-highlight.html, but it doesn’t export to LaTeX. It generates SXML or HTML.
<leoprikler>Well, I solved my problem somewhat – it just appears I was using listings the wrong way
<mwette>What's the best latex package for formatting Scheme code?
<leoprikler>I think people would normally point you towards minted, but I'm using listings, since minted is apparently a bit buggy in Guix.
<mwette>Thanks so much! I don't live on guix so I'll check out minted.
<manumanumanu>rekado: thanks. I had tried that, but PEBKAC. The predicate had a type error that I wasn't expecting
<dadinn>hi everyone
<dadinn>I am trying to write some basic simple macros in guile, but I am only finding obscure stuff about syntax-rules
<dadinn>I am used to the sane gensym macros in Clojure, is there anything like that in Guile... rather than this undocumented madness?
<erkin>Not fond of hygiene?
<erkin>syntax-rules is definitely not undocumented. You can find tutorials and guides for it all over the web.
<erkin>I can help you if there's anything in particular you're struggling with.
<dsmith-work>dadinn: Try this: https://www.scheme.com/tspl4/syntax.html#./syntax:h2
<mwette> https://www.gnu.org/software/guile/manual/html_node/Syntax-Rules.html#index-define_002dsyntax_002drule
<erkin>Keep in mind that instead of directly working with lists (as `defmacro' does), Macro-by-Example style macro systems (such as `syntax-rules') work with templates.
<mwette>^ define-syntax-rule is simple
<dadinn>erkin: the only thing I found was this article from 2008: http://www.willdonnelly.net/blog/scheme-syntax-rules/
<erkin>There's this very well-written guide: http://www.phyast.pitt.edu/~micheles/syntax-rules.pdf
<dadinn>erkin: I've tried to read the original higenic macro thesis from 1986, but it's incomprehensible, didn't sounds something a practical person, who write real code, would come up with... so yeah, not that fond of hygiene yet
<dsmith-work>Yes
<erkin>It answers 90% of questions you could have about the workings of `syntax-rules'.
<erkin>Well, if it's any consolation, there are other languages who picked up Scheme's hygienic macro system, including Rust.
<dadinn>erkin: also, Clojure is really practical in this sense, and its gensym+namespaces gives a reasonable safety agains variable capture
<erkin>That's the Common Lisp approach.
<dsmith-work>I don't remember where I read it, I heard syntax-rules macros explained kind of like this,
<erkin>In addition, Racket has a very good and quick guide: https://docs.racket-lang.org/guide/pattern-macros.html
<dsmith-work>when doumenting a macro, you show a pattern of what the macro matches, and then what it would expand to.
<dsmith-work>Syntax-rules *directly* does thats.
<dsmith-work>Just a list of patterns and expansions.
<erkin>I'd say defmacro style isn't very suitable for long and complicated macros. It's very easy to write simple macros without having to think much about it but it quickly turns to spaghetti once it gets complex.
<erkin>The self-documenting nature of MbE templates make for readable and clear macros.
<dadinn>i was trying to write something like this: (define-syntax with-my-output-to-file (syntax-rules () ((_ path body ...) (with-output-to-file path (lambda () body ...)))))
<dadinn>nothing rocket science
<erkin>That macro seems fine to me.
<dsmith-work>Note that ... means zero-or-more
<dadinn>the error says wrong type to apply... and macroexpand returns a tree-il which is not that helpful either
<erkin>For something that simple, you can use the `define-syntax-rule' shorthand. (define-syntax-rule (with-my-output-to-file path body ...) (with-output-to-file path (lambda () body ...)))
<dadinn>this doesn't seem to work: (with-my-output-to-file "shitfuck.txt" (utils:println "FUCK!!!!") (utils:println "SHIT!!!!"))
<dadinn>sorry for the obscenity :/
<erkin>What is utils:println?
<erkin>That macro works for me if I use `displayln'.
<dadinn>ah its just a function display + newline
<erkin>Can I see it?
<dadinn>is there a displayln function?
<erkin>Oh right, that's my own definition. It's a Racketism, sorry.
<dadinn>(define* (println #:rest args) (newline) (display (string-join args " ")) (newline))
<dsmith-work>So here is a simple example, direct from the guile sources:
<dsmith-work>(define-syntax-rule (when test stmt stmt* ...)
<dsmith-work> (if test (begin stmt stmt* ...)))
<dadinn>dsmith-work: hmm... yeah I saw it somewhere, I think in the '86 paper that the template should end with ( body body ...) what's the point in that?
<erkin>Imagine it like a Kleene star.
<erkin>What's the point of having * in regexps be able to match zero arguments? :-)
<dsmith-work>Because (lambda ()) is not valid.
<dadinn>so if i want to have a rest argument called `foo`, then the pattern has to end with (foo foo ...)?
<dsmith-work>Name the second foo something else. But yeah.
<erkin>If you want a syntax list whose car is foo and cdr is bar, just use (foo . bar)
<dsmith-work>Or use .
<dsmith-work>Like page 5 of http://www.phyast.pitt.edu/~micheles/syntax-rules.pdf
<mwette>I like the explanation of macros in this: https://www.scheme.com/tspl4/
<erkin>Like (define-syntax-rule (when-let (value condition) . body) (let ((value condition)) (when value . body)))
<dadinn>dsmith-work: why lambda () is not valid?
<dsmith-work>Can't have an empy body
<erkin>For the same reason () isn't valid. A function needs to return something.
<mwette>Section 3.1
<dsmith-work>(lambda () somthing) is ok, (lambda () ) is not
<dadinn>dsmith-work: sure, but lambda has the body, and it has no arguments because with-output-to-file expects a no-argument thunk only
<dsmith-work>Why is ... like that? It's easy to make one-or-more from zero-or-more, but not the other way around.
<dadinn>dsmith-work: I am not sure, what is wrong with it? In the tutorial I found, that's what it said how ... should be used :/
<dsmith-work>Sure.
<dsmith-work>The usual convention if you want one-or-more is foo foo* ...
<dadinn>I am not getting what's the point of this pattern/template thing, all I wanted is `(with-output-to-file ,path (lambda () ,@body)) but with syntax-rules I have no clue how to achieve that
<erkin>You don't need ... for this.
<dadinn>also, I am not sure how to call my macro with-output-to-file in my utils module, and not to override the builtin version :/
<erkin>(define-syntax-rule (with-my-output-to-file path . body) (with-output-to-file path (lambda () . body)))
<dadinn>hmm, that looks simple... does it take the name from the pattern automatically?
<erkin>`define-syntax-rule'?
<dadinn>yes
<erkin>Yes, it expands to (define with-my-output-to-file (syntax-rules () ((_ path . body) (with-output-to-file path (lambda () . body))))).
<erkin>It's for writing single-clause macros with no literals.
<dadinn>erkin: fair enough
<erkin>In case you're curious, good example of a recursive, multi-clause macro with literals would be the implementation of `cond' using `if'.
<erkin> http://pasterack.org/pastes/341
<dadinn>i am still confused about the meaning of ... , i thought it would behave something like #:rest in define*, but because of the dual variables I am still unsure how to interpret it
<erkin>It matches every token that could fit there (including none), verbatim.