Re: splicing macros
Hi, Top-posting as it's been so long. You know, on second thought I'm hesitant to document this macro. I understood it at one point but it has totally left my head -- I can only remember so many things. It seem to me that the best we can do is probably pointing to Oleg's web page, and leaving it out of the manual. If we do put it in, it's not really a peer of syntax-rules, which is where you put it... dunno. I'm open to other thoughts. Sorry for the negativity! A On Fri 08 Feb 2013 21:53, Stefan Israelsson Tampe stefan.ita...@gmail.com writes: Hi, Here is a git-format-patch of some docs for the ck macro. enjoy! On Sun, Jan 27, 2013 at 11:17 AM, Andy Wingo wi...@pobox.com wrote: On Sat 26 Jan 2013 14:03, Stefan Israelsson Tampe stefan.ita...@gmail.com writes: I will assume that you are familliar with th ck macro, included in recent guile releases or else consider looking it up at http://okmij.org/ftp/Scheme/macros.html It does not seem to be documented in Guile's manual. Want to write some documentation? :) Andy -- http://wingolog.org/ From c0e4a806bda68dc3b645e17e2475929d2cb0dfad Mon Sep 17 00:00:00 2001 From: Stefan Israelsson Tampe stefan.ita...@gmail.com Date: Fri, 8 Feb 2013 21:42:38 +0100 Subject: [PATCH] * doc/ref/api-macros.texi: added documentation for the ck macro --- doc/ref/api-macros.texi | 46 ++ 1 file changed, 46 insertions(+) diff --git a/doc/ref/api-macros.texi b/doc/ref/api-macros.texi index 347d025..1f9e645 100644 --- a/doc/ref/api-macros.texi +++ b/doc/ref/api-macros.texi @@ -44,6 +44,7 @@ languages}, or EDSLs.}. * Syntax Parameters:: Syntax Parameters. * Eval When:: Affecting the expand-time environment. * Internal Macros:: Macros as first-class values. +* Ck macro::Applicative evaluation order macro facility. @end menu @node Defining Macros @@ -1160,7 +1161,52 @@ which one may ask the docstring. That's the whole reason this section is documented. Actually a part of the result of @code{macro-binding}. @end deffn +@node Ck macro +@subsection The Ck macro +@deffn {Syntax} ck state expression +The @code{ck} macro is a facility that simulate function applicative expansion +order for the scheme macro system. It does so by introducing a few conventions. +First every expression of the form @code{(quote x)} will mark x as the result +of the expansion of that argument and stop try expanding. Secondly every macro +have to use as first argument, the state and then concatenate the actual +arguments. Thirdly it have to explicitly invoke the @code{ck} macro at start +and also at every continuation when a resulting expansion have finished. To +start the expantion use @code{(ck () expr)}. + +@example +(use-modules (system base ck)) + +;;note +;; 1) The use of '... to indicate a value +;; 2) How we continue with issueing (ck s ...) at the end of expansion +;; 3) How macros applications inside of the ck macro does not have explicit +;;s (That's added later on) + +(define-syntax c-cons + (syntax-rules (quote) +((_ s 'x 'y) (ck s '(x . y) + +(define-syntax c-map + (syntax-rules (quote) +((_ s 'c-f '(x . l)) + (ck s (c-cons (c-f 'x) (c-map 'c-f 'l +((_ s _ '()) + (ck s '() + +(define-syntax c-f + (syntax-rules (quote) + ((_ s 'x) + (ck s '(* x 10) + + +;; And to show the macro in action write + +,exp (ck () (c-map 'c-f '(a b c))) + +$1 = ((* a 10) (* b 10) (* c 10)) +@end example +@end deffn @c Local Variables: @c TeX-master: guile.texi @c End: -- http://wingolog.org/
Fwd: splicing macros
I found the doc, maybe you can take a look! -- Forwarded message -- From: Stefan Israelsson Tampe stefan.ita...@gmail.com Date: Fri, Feb 8, 2013 at 9:53 PM Subject: Re: splicing macros To: Andy Wingo wi...@pobox.com Cc: guile-devel guile-devel@gnu.org Hi, Here is a git-format-patch of some docs for the ck macro. enjoy! On Sun, Jan 27, 2013 at 11:17 AM, Andy Wingo wi...@pobox.com wrote: On Sat 26 Jan 2013 14:03, Stefan Israelsson Tampe stefan.ita...@gmail.com writes: I will assume that you are familliar with th ck macro, included in recent guile releases or else consider looking it up at http://okmij.org/ftp/Scheme/macros.html It does not seem to be documented in Guile's manual. Want to write some documentation? :) Andy -- http://wingolog.org/ 0001-doc-ref-api-macros.texi-added-documentation-for-the-.patch Description: Binary data
Re: splicing macros
Yes, I can add documentation for it. /Stefan On Sun, Jan 27, 2013 at 11:17 AM, Andy Wingo wi...@pobox.com wrote: On Sat 26 Jan 2013 14:03, Stefan Israelsson Tampe stefan.ita...@gmail.com writes: I will assume that you are familliar with th ck macro, included in recent guile releases or else consider looking it up at http://okmij.org/ftp/Scheme/macros.html It does not seem to be documented in Guile's manual. Want to write some documentation? :) Andy -- http://wingolog.org/
Re: splicing macros
On Sat 26 Jan 2013 14:03, Stefan Israelsson Tampe stefan.ita...@gmail.com writes: I will assume that you are familliar with th ck macro, included in recent guile releases or else consider looking it up at http://okmij.org/ftp/Scheme/macros.html It does not seem to be documented in Guile's manual. Want to write some documentation? :) Andy -- http://wingolog.org/
splicing macros
Hi all, This is something fun to implement using ck-macros and local-syntax-value. The idea is to patch guile's quasisyntax.scm in ice-9 to implement splicing of macros. If we assume a reader macro #.code == (macro-splicing code), with the proposed hack I can now write: (define-syntax-rule (2x x) (x x)) and (define-syntax 4x (lambda (x) (syntax-case x () ((_ x) #`(#.(2x x) #.(2x x)) and (define-syntax g (lambda (x) #`(#.(4x 1) #.(4x 2 $4 = (1 1 1 1 2 2 2 2) I will assume that you are familliar with th ck macro, included in recent guile releases or else consider looking it up at http://okmij.org/ftp/Scheme/macros.html It is now quite natural to use his c-append macro to do do the transformation: (a b #.(f x) c d) -- (ck () (c-append '(a b) (c-append (ck-it '(f x)) '(c d And assuming that ck-it can dispatch the macro (f x) the appending would be obvious. The second magic is ck-it, it is defined as (use-modules (system syntax)) (define-syntax ck-it (lambda (x) (syntax-case x (quote) ((_ s (quote f)) (and (identifier? #'f) (eq? (syntax-local-binding #'f) 'macro)) (call-with-values (lambda () (syntax-local-binding #'f)) (lambda (m transformer) (list #'ck-it #'s (list #'quote (transformer #'f)) ((_ s (quote (quote x))) (list #'ck #'s #'(quote x))) ((_ s (quote (f . x))) (and (identifier? #'f) (eq? (syntax-local-binding #'f) 'macro)) (call-with-values (lambda () (syntax-local-binding #'f)) (lambda (m transformer) (list #'ck-it #'s (list #'quote (transformer #'(f . x))) ((_ s f) (list #'ck #'s #'f) It will iterativelly apply macros until a non macro sexp is appearing, To inhibit macro expeansion one need to quote it. This is a bit unclean because if the macro returns (quote x), x any sexp, it will return x in stead. A better solution might be to introduce a special inhibit macro. Also notice how splicing in already spliced syntaxes works as the example above works. Another thing to note is how we use syntax-local-binding to search find the macro transformer and use that in order to make all this work. Any thoughts? Should we add ck-it to guile's ck.scm? Should we add splicing macros? /Stefan