guile-user
[Top][All Lists]
Advanced

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

Re: reserved-keyword in macro


From: Vijay Marupudi
Subject: Re: reserved-keyword in macro
Date: Wed, 02 Feb 2022 19:52:37 -0500

Hi Damien,

I tried to run the code you provided. I ran

-----------------------------------------------------------------

(define-syntax <-
  (syntax-rules ($bracket-apply$)
    ((_ ($bracket-apply$ container index) expr)
     (let ((value expr)) ;; to avoid compute it twice
       (cond ((vector? container) (vector-set! container index value))
             ((hash-table? container) (hash-table-set! container index value))
             (else (array-set! container index value)));)
       value))
    ((_ ($bracket-apply$ array index1 index2 ...) expr)
     (let ((value expr))
       (if (vector? array)
           (array-n-dim-set! array value index1 index2 ...)
           (array-set! array index1 index2 ... value));)
       (newline)
       value))
    ((_ (var ...) expr)
     (begin
       (display expr) (newline)
       (let ((expr-list (call-with-values (lambda () expr) list)))
         (assign-var (var ...) expr-list)
         expr-list)))
    ((_ var expr)
     (begin
       (set! var expr)
       var))
    ((_ var var1 var2 ...)
     (<- var (<- var1 var2 ...)))))

(define T (make-vector 5))
(<- ($bracket-apply$ T 2) 1)

-----------------------------------------------------------------

After I ran that, T was

#(#<unspecified> #<unspecified> 1 #<unspecified> #<unspecified>)

Is that was you are looking for?

> "A literal matches an input expression if the input expression is an
> identifier with the same name as the literal, and both are unbound13
> <https://www.gnu.org/software/guile/manual/html_node/Syntax-Rules.html#FOOT13>.
> " as $bracket-apply$ is already bind to a definition the pattern will
> not be matched:

It's possible, as in my case, I did not have it bound, and it seems to
have worked the way you expected?

~ Vijay



reply via email to

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