[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [patch] variable datums with syncase transformer

From: Ludovic Courtès
Subject: Re: [patch] variable datums with syncase transformer
Date: Wed, 05 Mar 2008 17:34:26 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Stephen Compall <address@hidden> writes:

> address@hidden (Ludovic Courtès) writes:
>> OTOH, you can (should?) use `use-modules':
>> <snip>
>> I don't even understand what the difference is between using
>> `use-modules' and `use-syntax' for `(ice-9 syncase)'.
> guile> (use-modules (ice-9 syncase))
> guile> (define-syntax x-of-y
>          (lambda (stx)
>            (syntax-case stx ()
>              (_ (syntax (hashq-ref y 'x))))))
> guile> x-of-y
> #<macro! sc-macro>
> ;;restart
> guile> ;;same as above, using use-syntax instead
> guile> x-of-y
> Backtrace:
> In unknown file:
>    ?: 0* [hashq-ref ...

Oh, forgive my ignorance, I didn't know `syntax-case' allowed non-list
patterns.  It makes me like syntax transformers a bit more.  ;-)

Getting back to your initial problem...

> guile> (use-syntax (ice-9 syncase))
> guile> (@ (guile) car)
> ERROR: invalid syntax #<variable b7c50a40 value: #<primitive-procedure car>>

Note that `@' and `@@' rely on an interesting property of the evaluator:
you type `(@ (guile) car)', `@' returns a *variable*, but what you get
is a *procedure*, because in the meantime, the evaluator automagically
performed a `variable-ref'.  This is not very elegant in my opinion.

With that in mind, I propose instead the following patch, which also
fixes your problem AFAICS:

--- /home/ludo/src/guile/1.8/guile-core/ice-9/boot-9.scm.~1.356.2.10.~  
2007-09-01 19:11:00.000000000 +0200
+++ /home/ludo/src/guile/1.8/guile-core/ice-9/boot-9.scm        2008-03-05 
17:25:15.000000000 +0100
@@ -2988,7 +2988,7 @@
   (let ((var (module-variable (resolve-interface mod-name) var-name)))
     (if (not var)
        (error "no such public variable" (list '@ mod-name var-name)))
-    var))
+    (variable-ref var)))
 ;; The '@@' macro is like '@' but it can also access bindings that
 ;; have not been explicitely exported.
@@ -2997,7 +2997,7 @@
   (let ((var (module-variable (resolve-module mod-name) var-name)))
     (if (not var)
        (error "no such variable" (list '@@ mod-name var-name)))
-    var))
+    (variable-ref var)))
Would it be OK for you?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]