IRC channel logs
2016-12-30.log
back to list of logs
<djcb>i'd like to write some macro that transforms something like <djcb>(defspecialfunc foo #:optional #:key (bar 123) (body)) <djcb> into (define* (special-foo #:optional #:key (bar 123) (body))) <djcb>i went through the docs, but so far it's a bit unclear how to do this <djcb>any tips / examples you can recommend? <ft>djcb: So the structure is exactly the same, but for one set of parens and turning foo into special-foo? That would mean that the only problem is changing the name then? <ft>djcb: That could be done with datum->syntax in a syntax-case macro. <djcb>ft: oh, thanks. it's a bit unclear how to create a symbol special-<id> for (defspecialfunc id ...) <djcb>struggling a little bit with the various magisteria of scheme and macros, and what is evaluated where/when <djcb>my translator pattern starts with something like #'(define id <ft>(define-syntax foo (lambda (x) (syntax-case x () ((kw id rest ...) #`(define* (#,(datum->syntax #'kw (symbol-append 'special (syntax->datum #'id))) rest ...))))) <ft>[✗] untested, typed into an IRC buffer code. :) <djcb>ft: thanks a lot! i'll play with that <ft>djcb: Meh, you might need the splicing version of unsyntax. It's probably easier to use with-syntax. <ft>(define-syntax foo (lambda (x) (syntax-case x () ((kw id rest ...) (with-syntax ((name (datum->syntax #'kw (symbol-append 'special (syntax->datum #'id))))) #`(define (name) rest ...)))))) <ft>djcb: (define-syntax foo (lambda (x) (syntax-case x () ((kw id rest ... body) (with-syntax ((name (datum->syntax #'kw (symbol-append 'special (syntax->datum #'id))))) #`(define* (name rest ...) body)))))) <ft>djcb: ,exp (foo id #:key (foo 123) (+ foo 1)) => (define* (specialid #:key (foo 123 #:foo)) (+ foo 1)) <ft>djcb: (specialid) => 124 and (specialid #:foo 2) => 3 <djcb>ft: brilliant! thanks again! <daviid>I wonder if this is intentional, it is undefined in 2.0.13 <davexunit>I wonder if we can implement the same thing for guile's hash tables <amz3>is there dynamic context in guile fiber? <amz3>my event loop was using write and read, if I implement it on top of fibers it won't work <amz3>anyway, I don't need that code anymore <amz3>anyway i am not sure how I could put to good use fibers right now