Skip to content

Instantly share code, notes, and snippets.

@codemac
Last active July 26, 2016 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codemac/53201db0ac36b585e81745be8553504b to your computer and use it in GitHub Desktop.
Save codemac/53201db0ac36b585e81745be8553504b to your computer and use it in GitHub Desktop.
Some scheme
(define-syntax define-maker
(lambda (stx)
(syntax-case stx ()
((_ name)
#`(define
#,(datum->syntax
#'name
(string->symbol
(string-append
"make-"
(symbol->string
(syntax->datum #'name)))))
(lambda () (display "hello!")))))))
(define-maker bob)
(make-bob)
@codemac
Copy link
Author

codemac commented Jul 26, 2016

Ok, the problem was #' instead of

#`

@codemac
Copy link
Author

codemac commented Jul 26, 2016

Current bug:

; guile --no-auto-compile struct.scm
ice-9/psyntax.scm:1388:26: In procedure rebuild-macro-output:
ice-9/psyntax.scm:1388:26: Syntax error:
unknown location: encountered raw symbol in macro output in subform make-bob of (define-maker bob)

@codemac
Copy link
Author

codemac commented Jul 26, 2016

15:25 <ijp> codemac: basically, rather than deal with symbols,
            macros deal with syntax objects which carry around some
            extra information (source location, lexical
            environment, etc.)
15:25 <ijp> syntax->datum strips it, datum->syntax adds it
15:26 <ijp> the first argument to datum->syntax is an identifier
            whose information to use for the datum
15:26 <ijp> so (datum->syntax #'name (string->symbol ...)) here
15:26 *** phant0mas QUIT Ping timeout: 258 seconds
15:27 <ijp> we should add an identifier-append, or an
            identifier-format or something
15:27 <codemac> that would be neat!
15:28 <ijp> everyone has probably written their own

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment