Hi,
I think this is an old topic I'm bringing here. But I haven't found the solution yet. Is there a way to use #!key and #!optional parameters when loading syntax-case extension? If not, how can I at least use procedures that expect these and pass the arguments, like in compile-file?
Best regards
Afficher les réponses par date
Hi,
Den 3 mars 2012 13:29 skrev Álvaro Castro-Castilla < alvaro.castro.castilla@gmail.com>:
Hi,
I think this is an old topic I'm bringing here. But I haven't found the solution yet. Is there a way to use #!key and #!optional parameters when loading syntax-case extension?
I believe I have a rough memory of some ml email that said this is not possible.
If not, how can I at least use procedures that expect these and pass the arguments, like in compile-file?
What do you say of,
1) Rewrite invocation to form (apply target-proc (list arg0 arg1 etc. (string->keyword "key-arg-1") val-1)
2) Make a wrapper that's implemented and loaded outside of the syntax-case lib - (invoke-procedure compile-file '((arg0-v arg2-v) (key-arg-1 . val-1))
Best regards _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Hi
- Rewrite invocation to form (apply target-proc (list arg0 arg1 etc.
(string->keyword "key-arg-1") val-1)
Nice, this works for procedures like compile-file.
- Make a wrapper that's implemented and loaded outside of the syntax-case
lib - (invoke-procedure compile-file '((arg0-v arg2-v) (key-arg-1 . val-1))
This works for sure, but means that you have to isolate procedures in a module and compile. This sounds like a dirty solution soon leading to issues.
I wonder why Gambit doesn't include a syntax-rules implementation that is compatible with DSSSL and cond-expand, it belongs to R5RS.
Thanks Mikael!
Den 3 mars 2012 20:49 skrev Álvaro Castro-Castilla < alvaro.castro.castilla@gmail.com>:
I wonder why Gambit doesn't include a syntax-rules implementation that is compatible with DSSSL and cond-expand, it belongs to R5RS.
The impl is taken from /a lib of/ another Scheme. (just like with the thing addressed yesterday, someone said which on the ml a year ago)
DSSSL is not in the R5RS spec, it's just a very widely implemented extension. Same w cond-expand.
Yw.
Den 3 mars 2012 20:49 skrev Álvaro Castro-Castilla < alvaro.castro.castilla@gmail.com>:
I wonder why Gambit doesn't include a syntax-rules implementation that
is compatible with DSSSL and cond-expand, it belongs to R5RS.
The impl is taken from /a lib of/ another Scheme. (just like with the thing addressed yesterday, someone said which on the ml a year ago)
DSSSL is not in the R5RS spec, it's just a very widely implemented extension. Same w cond-expand.
Just secondarily, note that different DSSSL implementations have different behaviors: does the #!rest argument include all args defined up to it, in what order can #!optional and #!key be put, etc.
Yw.
Oh, yes, I meant that syntax-rules is R5RS so it makes sense to have it in Gambit compatible to its own extensions. I understand that's a lot of work though, and not the compiler's concern at some point.
On Sun, Mar 4, 2012 at 11:34 AM, Mikael mikael.rcv@gmail.com wrote:
Den 3 mars 2012 20:49 skrev Álvaro Castro-Castilla alvaro.castro.castilla@gmail.com:
I wonder why Gambit doesn't include a syntax-rules implementation that is compatible with DSSSL and cond-expand, it belongs to R5RS.
The impl is taken from /a lib of/ another Scheme. (just like with the thing addressed yesterday, someone said which on the ml a year ago)
DSSSL is not in the R5RS spec, it's just a very widely implemented extension. Same w cond-expand.
Just secondarily, note that different DSSSL implementations have different behaviors: does the #!rest argument include all args defined up to it, in what order can #!optional and #!key be put, etc.
Yw.
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
On 2012-03-03, at 1:49 PM, Álvaro Castro-Castilla wrote:
I wonder why Gambit doesn't include a syntax-rules implementation that is compatible with DSSSL and cond-expand, it belongs to R5RS.
Gambit uses the psyntax macro expander extracted from Chez Scheme Version 7.3 . Using psyntax has the advantage that it not only provides syntax-rules, but also syntax-case which is more powerful (allows breaking hygiene).
Unfortunately, psyntax is a large complex piece of software. When it is compiled, it takes almost as much space as the whole interpreter (including runtime and primitive procedures). Psyntax basically implements a specific Scheme dialect on top of Gambit. The Gambit syntactic extensions to Scheme, such as DSSSL optional and named parameters, declarations, low-level macros, keyword objects, etc would have to be *reimplemented* in psyntax, which is quite an undertaking. The psyntax code is much too hairy for me to understand how the extensions would fit in properly. Moreover, I am not willing to put time into this, knowing that using the psyntax system permanently in Gambit will bloat the system unreasonably (doubling the size of the interpreter).
By the way, that's why syntax-rules and syntax-case are not available by default in Gambit. You must use the -:s runtime option for Gambit to conform to R5RS (or load ~~lib/syntax-case.scm explicitly at the REPL).
Marc
Marc,
I see. The only reason I miss syntax-rules is for some SRFIs and libs like Kanren, completely implemented as syntax-rules. Otherwise I'm happier with define-macro :)
Thanks for your reply
2012/3/4 Marc Feeley feeley@iro.umontreal.ca:
On 2012-03-03, at 1:49 PM, Álvaro Castro-Castilla wrote:
I wonder why Gambit doesn't include a syntax-rules implementation that is compatible with DSSSL and cond-expand, it belongs to R5RS.
Gambit uses the psyntax macro expander extracted from Chez Scheme Version 7.3 . Using psyntax has the advantage that it not only provides syntax-rules, but also syntax-case which is more powerful (allows breaking hygiene).
Unfortunately, psyntax is a large complex piece of software. When it is compiled, it takes almost as much space as the whole interpreter (including runtime and primitive procedures). Psyntax basically implements a specific Scheme dialect on top of Gambit. The Gambit syntactic extensions to Scheme, such as DSSSL optional and named parameters, declarations, low-level macros, keyword objects, etc would have to be *reimplemented* in psyntax, which is quite an undertaking. The psyntax code is much too hairy for me to understand how the extensions would fit in properly. Moreover, I am not willing to put time into this, knowing that using the psyntax system permanently in Gambit will bloat the system unreasonably (doubling the size of the interpreter).
By the way, that's why syntax-rules and syntax-case are not available by default in Gambit. You must use the -:s runtime option for Gambit to conform to R5RS (or load ~~lib/syntax-case.scm explicitly at the REPL).
Marc
On 2012-03-04, at 11:22 AM, Álvaro Castro-Castilla wrote:
Marc,
I see. The only reason I miss syntax-rules is for some SRFIs and libs like Kanren, completely implemented as syntax-rules. Otherwise I'm happier with define-macro :)
Thanks for your reply
By the way, I should have mentionned in my previous message that when using the -:s switch, you still have access to ##lambda which does support DSSSL parameter lists. The form ##lambda has the same syntax as lambda, but it is not under the control of the psyntax expander (which defines lambda as a macro).
So you can do this:
% gsi -:s Gambit v4.6.4
(define f (lambda (a b #!optional (c (+ a b)) #!rest d) (list a b c d)))
*** ERROR -- invalid parameter list in (lambda (a b #!optional (c (+ a b)) #!rest d) (list a b c d))
(define f (##lambda (a b #!optional (c (+ a b)) #!rest d) (list a b c d))) (f 0 1 2 3 4)
(0 1 2 (3 4))
(define f (##lambda (a b #!key (c (+ a b)) #!rest d) (list a b c d))) (f 11 22)
(11 22 33 ())
(f 11 22 c: 99)
*** ERROR IN (console)@6.10 -- Unbound variable: c: 1>
(f 11 22 (string->keyword "c") 99)
(11 22 99 ())
(define c: (string->keyword "c")) (f 11 22 c: 99)
(11 22 99 ())
Marc
Thanks a lot for clarifying Marc. That's very useful!!
The only thing that doesn't work using the string->keyword trick is define-type, which doesn't have a ##define-type to bypass psyntax expansion.
(define-type my-type (string->keyword "constructor") whatever a b)
(whatever 1 2) *** ERROR -- Ill-formed special form: define-type (define-type my (string->keyword "constructor") whatever a b)
I've always used Gambit with BH so I didn't stumbled upon these issues before. I've also realized that define-macro's can be referred within file B if you have the macro defined in A and you load B from A; when you use psyntax. This isn't possible when you are using plain Gambit.
alvatar@asia~ $ cat testA.scm (define-macro (push! list obj) `(set! ,list (cons ,obj ,list)))
(load "testB")
alvatar@asia~ $ cat testB.scm (define l '(b c)) (push! l 'a) (pp l)
alvatar@asia~ $ gsc -e '(load "testA")' *** ERROR IN "testB.scm"@2.2 -- Unbound variable: push!
alvatar@asia~ $ gsc -:s -e '(load "testA")' (a b c)
I don't get the origin of this behavior and how can I controll it (for example make it work in Gambit without psyntax).
Thanks again for your replies.
2012/3/4 Marc Feeley feeley@iro.umontreal.ca:
On 2012-03-04, at 11:22 AM, Álvaro Castro-Castilla wrote:
Marc,
I see. The only reason I miss syntax-rules is for some SRFIs and libs like Kanren, completely implemented as syntax-rules. Otherwise I'm happier with define-macro :)
Thanks for your reply
By the way, I should have mentionned in my previous message that when using the -:s switch, you still have access to ##lambda which does support DSSSL parameter lists. The form ##lambda has the same syntax as lambda, but it is not under the control of the psyntax expander (which defines lambda as a macro).
So you can do this:
% gsi -:s Gambit v4.6.4
(define f (lambda (a b #!optional (c (+ a b)) #!rest d) (list a b c d)))
*** ERROR -- invalid parameter list in (lambda (a b #!optional (c (+ a b)) #!rest d) (list a b c d))
(define f (##lambda (a b #!optional (c (+ a b)) #!rest d) (list a b c d))) (f 0 1 2 3 4)
(0 1 2 (3 4))
(define f (##lambda (a b #!key (c (+ a b)) #!rest d) (list a b c d))) (f 11 22)
(11 22 33 ())
(f 11 22 c: 99)
*** ERROR IN (console)@6.10 -- Unbound variable: c: 1>
(f 11 22 (string->keyword "c") 99)
(11 22 99 ())
(define c: (string->keyword "c")) (f 11 22 c: 99)
(11 22 99 ())
Marc