* Quasisyntax broken? @ 2009-07-03 0:04 Andreas Rottmann 2009-07-23 21:31 ` Andy Wingo 0 siblings, 1 reply; 10+ messages in thread From: Andreas Rottmann @ 2009-07-03 0:04 UTC (permalink / raw) To: Guile Developers Hi! Playing around with Guile's now-in-core syntax-case support (using Git HEAD as of today), I found that quasisyntax seems quite broken: (define-syntax test (lambda (stx) (syntax-case stx () ((_ id body ...) #`(let ((id #,(symbol->string (syntax->datum #'id)))) body ...))))) [...] ERROR: In procedure sc-expand: ERROR: reference to pattern variable outside syntax form in id scheme@(guile-user)> Feeding that macro into Ikarus, Ypsilon or plt-r6rs suceeds, and produces the expected results: > (define-syntax test (lambda (stx) (syntax-case stx () ((_ id body ...) #`(let ((id #,(symbol->string (syntax->datum #'id)))) body ...))))) > (test foo foo) "foo" ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Quasisyntax broken? 2009-07-03 0:04 Quasisyntax broken? Andreas Rottmann @ 2009-07-23 21:31 ` Andy Wingo 2009-07-23 22:35 ` Andreas Rottmann 0 siblings, 1 reply; 10+ messages in thread From: Andy Wingo @ 2009-07-23 21:31 UTC (permalink / raw) To: Andreas Rottmann; +Cc: Guile Developers On Fri 03 Jul 2009 02:04, Andreas Rottmann <a.rottmann@gmx.at> writes: > Playing around with Guile's now-in-core syntax-case support (using Git > HEAD as of today), I found that quasisyntax seems quite broken: We've spoken over IRC since then, but for those that do not frequent there, it's simply not implemented. You can implement it in terms of with-syntax, though. Did you have a patch for that, Andreas? Andy -- http://wingolog.org/ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Quasisyntax broken? 2009-07-23 21:31 ` Andy Wingo @ 2009-07-23 22:35 ` Andreas Rottmann 2009-07-23 22:48 ` Andy Wingo 0 siblings, 1 reply; 10+ messages in thread From: Andreas Rottmann @ 2009-07-23 22:35 UTC (permalink / raw) To: Andy Wingo; +Cc: Guile Developers [-- Attachment #1: Type: text/plain, Size: 492 bytes --] Andy Wingo <wingo@pobox.com> writes: > On Fri 03 Jul 2009 02:04, Andreas Rottmann <a.rottmann@gmx.at> writes: > >> Playing around with Guile's now-in-core syntax-case support (using Git >> HEAD as of today), I found that quasisyntax seems quite broken: > > We've spoken over IRC since then, but for those that do not frequent > there, it's simply not implemented. You can implement it in terms of > with-syntax, though. Did you have a patch for that, Andreas? > Yep, the patch is attached: [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: Quasisyntax --] [-- Type: text/x-diff, Size: 3603 bytes --] From: Andreas Rottmann <a.rottmann@gmx.at> Subject: [PATCH] Add support for `quasisyntax' --- module/ice-9/boot-9.scm | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 75 insertions(+), 0 deletions(-) diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index 36a463a..26d73a7 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -308,6 +308,81 @@ (syntax-rules () ((_ exp) (make-promise (lambda () exp))))) +;; Add quasisyntax support. This is a slight variation of the code +;; posted in http://srfi.schemers.org/srfi-93/mail-archive/msg00063.html +(define-syntax quasisyntax + (lambda (e) + + (define (expand-quasisyntax x) + + ;; Expand returns a syntax object of the form + ;; (template[t/e, ...] (replacement ...)) + ;; Here template[t/e ...] denotes the original template + ;; with unquoted expressions e replaced by fresh + ;; variables t, followed by the appropriate ellipses + ;; if e is also spliced. + ;; The second part of the return value is the list of + ;; replacements, each of the form (t e) if e is just + ;; unquoted, or ((t ...) e) if e is also spliced. + ;; This will be the list of bindings of the resulting + ;; with-syntax expression. + + (define (expand x level) + (syntax-case x (quasisyntax unsyntax unsyntax-splicing) + ((quasisyntax e) + (with-syntax (((k _) x) ; Original must be copied + ((rest bs) (expand (syntax e) (+ level 1)))) + (syntax + ((k rest) bs)))) + ((unsyntax e) + (= level 0) + (with-syntax (((t) (generate-temporaries '(t)))) + (syntax (t ((t e)))))) + (((unsyntax e ...) . r) + (= level 0) + (with-syntax (((rest (b ...)) (expand (syntax r) 0)) + ((t ...) (generate-temporaries (syntax (e ...))))) + + (syntax + ((t ... . rest) + ((t e) ... b ...))))) + (((unsyntax-splicing e ...) . r) + (= level 0) + (with-syntax (((rest (b ...)) (expand (syntax r) 0)) + ((t ...) (generate-temporaries (syntax (e ...))))) + (with-syntax ((((t ...) ...) (syntax ((t (... ...)) ...)))) + (syntax + ((t ... ... . rest) + (((t ...) e) ... b ...)))))) + ((k . r) + (and (> level 0) + (identifier? (syntax k)) + (or (free-identifier=? (syntax k) (syntax unsyntax)) + (free-identifier=? (syntax k) (syntax unsyntax-splicing)))) + (with-syntax (((rest bs) (expand (syntax r) (- level 1)))) + (syntax + ((k . rest) bs)))) + ((h . t) + (with-syntax (((head (b1 ...)) (expand (syntax h) level)) + ((tail (b2 ...)) (expand (syntax t) level))) + (syntax + ((head . tail) + (b1 ... b2 ...))))) + (#(e ...) + (with-syntax ((((e* ...) bs) + (expand (vector->list (syntax #(e ...))) level))) + (syntax + (#(e* ...) bs)))) + (other + (syntax (other ()))))) + + (with-syntax (((template bindings) (expand x 0))) + (syntax + (with-syntax bindings (syntax template))))) + + (syntax-case e () + ((k template) + (expand-quasisyntax (syntax template)))))) \f ;;; {Defmacros} -- tg: (3b0b6bc..) t/quasisyntax (depends on: master) [-- Attachment #3: Type: text/plain, Size: 113 bytes --] From my few experiments, it seems to work nicely. Cheers, Rotty -- Andreas Rottmann -- <http://rotty.yi.org/> ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: Quasisyntax broken? 2009-07-23 22:35 ` Andreas Rottmann @ 2009-07-23 22:48 ` Andy Wingo 2009-07-25 21:30 ` Andreas Rottmann 0 siblings, 1 reply; 10+ messages in thread From: Andy Wingo @ 2009-07-23 22:48 UTC (permalink / raw) To: Andreas Rottmann; +Cc: Guile Developers Hi, On Fri 24 Jul 2009 00:35, Andreas Rottmann <a.rottmann@gmx.at> writes: > Andy Wingo <wingo@pobox.com> writes: > >> On Fri 03 Jul 2009 02:04, Andreas Rottmann <a.rottmann@gmx.at> writes: >> >>> Playing around with Guile's now-in-core syntax-case support (using Git >>> HEAD as of today), I found that quasisyntax seems quite broken: >> >> We've spoken over IRC since then, but for those that do not frequent >> there, it's simply not implemented. You can implement it in terms of >> with-syntax, though. Did you have a patch for that, Andreas? >> > Yep, the patch is attached: What is the license of this code? (Do you have copyright assignment on file? I assume the original author does not.) Andy -- http://wingolog.org/ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Quasisyntax broken? 2009-07-23 22:48 ` Andy Wingo @ 2009-07-25 21:30 ` Andreas Rottmann 2009-07-26 13:15 ` Ludovic Courtès ` (2 more replies) 0 siblings, 3 replies; 10+ messages in thread From: Andreas Rottmann @ 2009-07-25 21:30 UTC (permalink / raw) To: Andy Wingo; +Cc: Guile Developers [-- Attachment #1: Type: text/plain, Size: 1443 bytes --] Andy Wingo <wingo@pobox.com> writes: > Hi, > > On Fri 24 Jul 2009 00:35, Andreas Rottmann <a.rottmann@gmx.at> writes: > >> Andy Wingo <wingo@pobox.com> writes: >> >>> On Fri 03 Jul 2009 02:04, Andreas Rottmann <a.rottmann@gmx.at> writes: >>> >>>> Playing around with Guile's now-in-core syntax-case support (using Git >>>> HEAD as of today), I found that quasisyntax seems quite broken: >>> >>> We've spoken over IRC since then, but for those that do not frequent >>> there, it's simply not implemented. You can implement it in terms of >>> with-syntax, though. Did you have a patch for that, Andreas? >>> >> Yep, the patch is attached: > > What is the license of this code? > It's under the (unmodified) MIT license, see <http://srfi.schemers.org/srfi-process.html>. I've attached an updated patch, which takes the quasisyntax implementation straight from Andre van Tonder's portable R6RS libraries implementation[0], without any modification. [0] http://www.het.brown.edu/people/andre/macros/index.html > (Do you have copyright assignment on file? I assume the original > author does not.) > I think I filed one for Guile several years ago, and think you assume rightly; I guess that might be a problem; OTOH it would be (IMHO) kinda dumb to have to ignore/rewrite all the perfectly (L)GPL-compatible BSD- and MIT-licensed code that's out there, as you cannot expect the respective authors to all sign copyright assignments for Guile... [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: t_quasisyntax.diff --] [-- Type: text/x-diff, Size: 5093 bytes --] From: Andreas Rottmann <a.rottmann@gmx.at> Subject: [PATCH] Add support for `quasisyntax' --- module/ice-9/boot-9.scm | 117 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 117 insertions(+), 0 deletions(-) diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index 36a463a..31ebfe0 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -308,6 +308,123 @@ (syntax-rules () ((_ exp) (make-promise (lambda () exp))))) +;; Quasisyntax in terms of syntax-case. +;; +;; Code taken from +;; <http://www.het.brown.edu/people/andre/macros/index.html>; +;; Copyright (c) 2006 Andre van Tonder +;; Copyright statement at http://srfi.schemers.org/srfi-process.html +;; +;;========================================================= +;; +;; To make nested unquote-splicing behave in a useful way, +;; the R5RS-compatible extension of quasiquote in appendix B +;; of the following paper is here ported to quasisyntax: +;; +;; Alan Bawden - Quasiquotation in Lisp +;; http://citeseer.ist.psu.edu/bawden99quasiquotation.html +;; +;; The algorithm converts a quasisyntax expression to an +;; equivalent with-syntax expression. +;; For example: +;; +;; (quasisyntax (set! #,a #,b)) +;; ==> (with-syntax ((t0 a) +;; (t1 b)) +;; (syntax (set! t0 t1))) +;; +;; (quasisyntax (list #,@args)) +;; ==> (with-syntax (((t ...) args)) +;; (syntax (list t ...))) +;; +;; Note that quasisyntax is expanded first, before any +;; ellipses act. For example: +;; +;; (quasisyntax (f ((b #,a) ...)) +;; ==> (with-syntax ((t a)) +;; (syntax (f ((b t) ...)))) +;; +;; so that +;; +;; (let-syntax ((test-ellipses-over-unsyntax +;; (lambda (e) +;; (let ((a (syntax a))) +;; (with-syntax (((b ...) (syntax (1 2 3)))) +;; (quasisyntax +;; (quote ((b #,a) ...)))))))) +;; (test-ellipses-over-unsyntax)) +;; +;; ==> ((1 a) (2 a) (3 a)) +(define-syntax quasisyntax + (lambda (e) + + ;; Expand returns a list of the form + ;; [template[t/e, ...] (replacement ...)] + ;; Here template[t/e ...] denotes the original template + ;; with unquoted expressions e replaced by fresh + ;; variables t, followed by the appropriate ellipses + ;; if e is also spliced. + ;; The second part of the return value is the list of + ;; replacements, each of the form (t e) if e is just + ;; unquoted, or ((t ...) e) if e is also spliced. + ;; This will be the list of bindings of the resulting + ;; with-syntax expression. + + (define (expand x level) + (syntax-case x (quasisyntax unsyntax unsyntax-splicing) + ((quasisyntax e) + (with-syntax (((k _) x) ;; original identifier must be copied + ((e* reps) (expand (syntax e) (+ level 1)))) + (syntax ((k e*) reps)))) + ((unsyntax e) + (= level 0) + (with-syntax (((t) (generate-temporaries '(t)))) + (syntax (t ((t e)))))) + (((unsyntax e ...) . r) + (= level 0) + (with-syntax (((r* (rep ...)) (expand (syntax r) 0)) + ((t ...) (generate-temporaries (syntax (e ...))))) + (syntax ((t ... . r*) + ((t e) ... rep ...))))) + (((unsyntax-splicing e ...) . r) + (= level 0) + (with-syntax (((r* (rep ...)) (expand (syntax r) 0)) + ((t ...) (generate-temporaries (syntax (e ...))))) + (with-syntax ((((t ...) ...) (syntax ((t (... ...)) ...)))) + (syntax ((t ... ... . r*) + (((t ...) e) ... rep ...)))))) + ((k . r) + (and (> level 0) + (identifier? (syntax k)) + (or (free-identifier=? (syntax k) (syntax unsyntax)) + (free-identifier=? (syntax k) (syntax unsyntax-splicing)))) + (with-syntax (((r* reps) (expand (syntax r) (- level 1)))) + (syntax ((k . r*) reps)))) + ((h . t) + (with-syntax (((h* (rep1 ...)) (expand (syntax h) level)) + ((t* (rep2 ...)) (expand (syntax t) level))) + (syntax ((h* . t*) + (rep1 ... rep2 ...))))) + (#(e ...) + (with-syntax ((((e* ...) reps) + (expand (vector->list (syntax #(e ...))) level))) + (syntax (#(e* ...) reps)))) + (other + (syntax (other ()))))) + + (syntax-case e () + ((_ template) + (with-syntax (((template* replacements) (expand (syntax template) 0))) + (syntax + (with-syntax replacements (syntax template*)))))))) + +(define-syntax unsyntax + (lambda (e) + (syntax-violation 'unsyntax "Invalid expression" e))) + +(define-syntax unsyntax-splicing + (lambda (e) + (syntax-violation 'unsyntax "Invalid expression" e))) \f ;;; {Defmacros} -- tg: (74deff3..) t/quasisyntax (depends on: master) [-- Attachment #3: Type: text/plain, Size: 54 bytes --] Rotty -- Andreas Rottmann -- <http://rotty.yi.org/> ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: Quasisyntax broken? 2009-07-25 21:30 ` Andreas Rottmann @ 2009-07-26 13:15 ` Ludovic Courtès 2009-07-26 16:30 ` Andy Wingo 2009-08-20 21:19 ` Ludovic Courtès 2 siblings, 0 replies; 10+ messages in thread From: Ludovic Courtès @ 2009-07-26 13:15 UTC (permalink / raw) To: guile-devel Hi Andreas, Andreas Rottmann <a.rottmann@gmx.at> writes: > I think I filed one for Guile several years ago, and think you assume > rightly; Yes, you're on file. > I guess that might be a problem; OTOH it would be (IMHO) kinda dumb to > have to ignore/rewrite all the perfectly (L)GPL-compatible BSD- and > MIT-licensed code that's out there, as you cannot expect the > respective authors to all sign copyright assignments for Guile... Yes, of course. We already have code not copyright FSF such as `psyntax' and `match'. Thanks, Ludo'. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Quasisyntax broken? 2009-07-25 21:30 ` Andreas Rottmann 2009-07-26 13:15 ` Ludovic Courtès @ 2009-07-26 16:30 ` Andy Wingo 2009-07-26 22:06 ` Ludovic Courtès 2009-08-20 21:19 ` Ludovic Courtès 2 siblings, 1 reply; 10+ messages in thread From: Andy Wingo @ 2009-07-26 16:30 UTC (permalink / raw) To: Andreas Rottmann; +Cc: Guile Developers Hi, On Sat 25 Jul 2009 23:30, Andreas Rottmann <a.rottmann@gmx.at> writes: > Andy Wingo <wingo@pobox.com> writes: > >> On Fri 24 Jul 2009 00:35, Andreas Rottmann <a.rottmann@gmx.at> writes: >> >>> Andy Wingo <wingo@pobox.com> writes: >>> >>>> On Fri 03 Jul 2009 02:04, Andreas Rottmann <a.rottmann@gmx.at> writes: >>>> >>>>> Playing around with Guile's now-in-core syntax-case support (using Git >>>>> HEAD as of today), I found that quasisyntax seems quite broken: >>>> >>>> We've spoken over IRC since then, but for those that do not frequent >>>> there, it's simply not implemented. You can implement it in terms of >>>> with-syntax, though. Did you have a patch for that, Andreas? >>>> >>> Yep, the patch is attached: >> >> What is the license of this code? >> > It's under the (unmodified) MIT license, see > <http://srfi.schemers.org/srfi-process.html> Hm. I have no idea what this means for Guile. It seems we need either a disclaimer or an assignment. Now, it seems that something happened in the past with psyntax which would seem to go against this, though: commit 9d1a28471c4e69ee151a85d44f8888a69bf102ec Author: Jim Blandy <jimb@red-bean.com> Date: Mon Oct 19 13:43:50 1998 +0000 We can't include Kent Dybvig's syntax-case macro expander in the core Guile distribution, because we don't have copyright assignments for this code. We can certainly distribute them as a separate package, but Guile should be FSF code. * syncase.scm, psyntax.pp, psyntax.ss: Removed. * Makefile.am (ice9_sources): Removed syncase.scm, psyntax.pp, and psyntax.ss. * Makefile.in: Regenerated. * Makefile.am (ice9_sources): Add getopt-gnu-style.scm. * Makefile.in: Regenerated. But then: commit a63812a2fef2f81b8c4eca04c858e42b62e455f9 Author: Jim Blandy <jimb@red-bean.com> Date: Mon Oct 19 15:38:05 1998 +0000 Talked to Stallman. Actually, the syntax-case copyright is no problem. Duh. * Makefile.am (ice9_sources): Revert last change. * syncase.scm, psyntax.pp, psyntax.ss: Added again. * Makefile.in: Regeneretade. So I don't know what the deal is. I'll defer to Neil and Ludovic. > it would be (IMHO) kinda dumb to have to ignore/rewrite all the > perfectly (L)GPL-compatible BSD- and MIT-licensed code that's out > there, as you cannot expect the respective authors to all sign > copyright assignments for Guile... Yes, I agree. Cheers, Andy -- http://wingolog.org/ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Quasisyntax broken? 2009-07-26 16:30 ` Andy Wingo @ 2009-07-26 22:06 ` Ludovic Courtès 2009-07-27 22:51 ` Neil Jerram 0 siblings, 1 reply; 10+ messages in thread From: Ludovic Courtès @ 2009-07-26 22:06 UTC (permalink / raw) To: guile-devel Hi, Andy Wingo <wingo@pobox.com> writes: > Hm. I have no idea what this means for Guile. It seems we need either a > disclaimer or an assignment. My understanding is that it's OK if we have bits of code not copyright FSF, if there's a good reason to do so (and there is one, here). After some reading, I see this (info "(maintain) Copying from Other Packages"): When you are copying code for which we do not already have papers, you need to get papers for it. It may be difficult to get the papers if the code was not written as a contribution to your package, but that doesn't mean it is ok to do without them. If you cannot get papers for the code, you can only use it as an external library (*note External Libraries::). But later on (info "(maintain) External Libraries") basically says that it's easy to incorporate free third-party code like this. At any rate we already have precedents for this (`psyntax' and `match') so I'm not worried. Maybe we can ask Karl Berry and RMS just to make sure. (Note that the so-called "GNU" Bazaar doesn't have a single line copyright FSF.) Thanks, Ludo'. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Quasisyntax broken? 2009-07-26 22:06 ` Ludovic Courtès @ 2009-07-27 22:51 ` Neil Jerram 0 siblings, 0 replies; 10+ messages in thread From: Neil Jerram @ 2009-07-27 22:51 UTC (permalink / raw) To: Ludovic Courtès; +Cc: guile-devel ludo@gnu.org (Ludovic Courtès) writes: > Hi, > > Andy Wingo <wingo@pobox.com> writes: > >> Hm. I have no idea what this means for Guile. It seems we need either a >> disclaimer or an assignment. > > My understanding is that it's OK if we have bits of code not copyright > FSF, if there's a good reason to do so (and there is one, here). I agree. > After some reading, I see this (info "(maintain) Copying from Other > Packages"): > > When you are copying code for which we do not already have papers, > you need to get papers for it. It may be difficult to get the papers > if the code was not written as a contribution to your package, but > that doesn't mean it is ok to do without them. If you cannot get > papers for the code, you can only use it as an external library (*note > External Libraries::). > > But later on (info "(maintain) External Libraries") basically says that > it's easy to incorporate free third-party code like this. > > At any rate we already have precedents for this (`psyntax' and `match') > so I'm not worried. Maybe we can ask Karl Berry and RMS just to make > sure. Good idea. > (Note that the so-called "GNU" Bazaar doesn't have a single line > copyright FSF.) I think that just means that the FSF has no power to pursue any infringing uses. Which is fine, so long as - in the case of Bazaar they are happy with someone else (Canonical?) having that power, or with no one having that power - they don't forget and then waste resources on investigating an alleged infringement. For Guile I think the second point is the important one. If we allowed Guile to become substantially non-FSF-owned, it might become difficult to prove whether some future GPL-infringing use of Guile relied on FSF-owned code, and hence whether the FSF had standing to pursue the infringement. Adding quasisyntax doesn't take us any nearer this hypothetical grey area, IMO, so I don't think it's a cause for concern. Neil ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Quasisyntax broken? 2009-07-25 21:30 ` Andreas Rottmann 2009-07-26 13:15 ` Ludovic Courtès 2009-07-26 16:30 ` Andy Wingo @ 2009-08-20 21:19 ` Ludovic Courtès 2 siblings, 0 replies; 10+ messages in thread From: Ludovic Courtès @ 2009-08-20 21:19 UTC (permalink / raw) To: guile-devel Hey! The outcome of a discussion with RMS and Karl Berry is that we can include this code under its current license in Guile. It would be preferable to store it in a separate file, though, with the full license text in the header. Could you prepare an updated patch based on this? Thanks, Ludo'. ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2009-08-20 21:19 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-07-03 0:04 Quasisyntax broken? Andreas Rottmann 2009-07-23 21:31 ` Andy Wingo 2009-07-23 22:35 ` Andreas Rottmann 2009-07-23 22:48 ` Andy Wingo 2009-07-25 21:30 ` Andreas Rottmann 2009-07-26 13:15 ` Ludovic Courtès 2009-07-26 16:30 ` Andy Wingo 2009-07-26 22:06 ` Ludovic Courtès 2009-07-27 22:51 ` Neil Jerram 2009-08-20 21:19 ` Ludovic Courtès
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).