[gambit-list] syntax-case and procedures with keyword parameters

Álvaro Castro-Castilla alvaro.castro.castilla at gmail.com
Sun Mar 4 13:49:15 EST 2012


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 at asia~ $ cat testA.scm
(define-macro (push! list obj)
              `(set! ,list (cons ,obj ,list)))

(load "testB")

alvatar at asia~ $ cat testB.scm
(define l '(b c))
(push! l 'a)
(pp l)

alvatar at asia~ $ gsc -e '(load "testA")'
*** ERROR IN "testB.scm"@2.2 -- Unbound variable: push!

alvatar at 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 at 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
>



More information about the Gambit-list mailing list