IRC channel logs
2024-12-15.log
back to list of logs
<robin>rlb, i was more wondering about a dir->module prefix map (there isn't one afaict), but that's a good question too <robin>shadowing does work if add-to-load-path is called early enough <lechner>Hi, I took a short dive into 'syntax-case' but have trouble coming back up. Can this code be simplified? Thanks! https://bpa.st/YWNQ <rlb>robin: yeah, I believe whoever goes first wins, but be careful about (IMO) a bug where guile will fall back to a stale file in another dir (wrt .go vs .scm) if the compilation crashes, iirc. <rlb>or if not a bug, certainly not what I expected. <dpk>you almost never want datum->syntax with syntax->datum nested inside it; you are breaking hygiene unnecessarily and the macro is observably unhygienic when it doesn’t need to be <dpk>also, if you do need datum->syntax, its first argument should always be an identifier, not a general syntax object. it is a bug in Guile if that works <lechner>dpk / wow, thanks! that's so much better! by the way, the usage of datum->syntax came from the manual. it said that the argument should be an identifier (and I planned to use one eventually) but the manual used x. <lechner>dpk / i better read up on how those ellipses work <dpk>the (list? (syntax->datum #'keys)) in your original is a fender <dpk>no, it’s not an expression <dpk>never seen this before <lechner>ok, the fender is the validation or whatever other languages call it <ArneBab>lechner: could you fix the example in the manual on datum->syntax? I’ll gladly review and push it quickly. <lechner>ArneBab / I'd be happy to contribute a patch, but I'm not sure how to fix it. The manual states specifically that "we can create a syntax object as ‘(datum->syntax x 'it)’, where ‘x’ is the whole expression, as passed to the transformer procedure." As for the sample code, I'm not sure there is an identifier that corresponds to 'it'. <ArneBab>lechner: I had thought that dpk had given explanation that showed what should be correct. Could you two maybe "sit together" and figure out whether the manual needs changes to clarify something here? <dpk>> In this case we want to introduce it in the context of the whole expression, so we can create a syntax object as (datum->syntax x 'it), where x is the whole expression, as passed to the transformer procedure. <dpk>you can’t introduce an identifier in the context of a whole expression <dpk>because a ‘whole expression’ might (quite legitimately) consist of identifiers with different contexts <dpk>you want to change the examples to capture the keyword of the ‘aif’ macro use and introduce it in that context <ekaitz>hi! can i `match` on the contents of a record? <ekaitz>(($ record-name (field x)) (use x)) ;; something like that? <mwette>ekaitz: I don't think that works. I believe you can skip fields after the last one you want. <ekaitz>mwette: and can i set a variable with the field i'm trying to obtain? <mwette>I think to set you need to use the normal record syntax. Those two things cold be added. Is fields in record the only thing you are matching? <ekaitz>i want to make something like (match event (('start data) (use data...))) but instead of a list, i want to match in an event record <ekaitz>i mean, it's hard for me to explain this, specially in english <mwette>You could write your own CPS macro. Check out (system base pmatch). <ekaitz>but with current matcher... what does $ do? <mwette>it grabs the fields and assigns them to variables: (match exp (($ <foo> a b c) ...) provides a to match first field, b second, etc <mwette>where exp is a record defined by maker from (define-record-type <exp> ...) <ekaitz>i didn't understand the docs very well <mwette>the match documentation is a bit vague in areas; I've been there <ekaitz>($ <event> 'end msg) <-- i tried this <mwette>nope ($ <event> fld1 fld2 fld3) : you can't name the fields you want <ekaitz>and can I match on the contents? <ekaitz>like... i want only to match a record that has an 'end event there <mwette>Oh. I don't think so. You want certain fields to match literals and for others you want the value? <mwette>Hmm. The only issue with making a macro for this is getting a handle on the field positions at compile time. <mwette>Is <event> an srfi-9 record type? <mwette>(Reading through match.upstream.scm.) <ekaitz>($ <event> 'start msg) <-- this works if the event looks like: <ekaitz>(define-record-type <event> (make-event type data) event? (type event-type) (data event-data)) <ekaitz>so great! thanks for the help mwette <ArneBab>dpk: I think I don’t understand … @lechner: did you? <dpk>i can give a full explanation tomorrow, maybe, i’m tired now <dpk>but essentially it boils down to: ultimately, only identifiers carry hygienic context, therefore only an identifier can be used to give the hygienic context for another identifier <dpk>for implementation efficiency reasons, syntax objects can also wrap other types of datums <dpk>(also occasionally for other reasons, for example carrying source location information) <dpk>but this is an implementation detail only, and a given syntax object is not guaranteed to be wrapped, nor do all the identifiers within an expression necessarily have to have the same hygienic context <dpk>the right way to implement aif is with a syntax-case clause which matches a pattern (k test then else) and then use #'k at the first argument to datum->syntax <dpk>because k is always guaranteed to be an identifier; moreover, it will have the hygienic context for the place aif was actually lexically used