guile-user
[Top][All Lists]
Advanced

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

Re: References/locations


From: Stephen Compall
Subject: Re: References/locations
Date: Sun, 10 Aug 2008 02:51:39 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

"Maciek Godek" <address@hidden> writes:
> I've tried to do it using a "procedure with
> setter", but the problem is that set! doesn't
> evaluate its first argument (as long as it's a
> symbol), so I'd have to wrap everything
> up in macros to obtain:
> (set! (vector-location v 1) 10)

Actually, if you (use-syntax (ice-9 syncase)), you should be able to
define lexical symbol-macros that expand a single symbol, even in a
set! place, something like:

(define v #(1 2 3))
(define-syntax v1
  (lambda (stx)
    (syntax-case stx ()
      (_ v))))

Obviously aliasing will serve:

(define-syntax alias-syntax
  (syntax-rules ()
    ((_ form)
     (lambda (stx)
       (syntax-case stx ()
         (_ (syntax form)))))))

(define-syntax defalias
  (syntax-rules stx ()
    ((_ new form)
     (define-syntax new (alias-syntax form)))))

(define-syntax let-alias
  (syntax-rules ()
    ((_ ((new form) ...) body ...)
     (let-syntax ((new (alias-syntax form)) ...) body ...))))

(defalias v1 (vector-ref v 1))

(set! v1 42)
(vector-ref v 1) ; => 42

-- 
a Mr. Fleming wishes to study bugs in smelly cheese; a Polish woman
wishes to sift through tons of Central African ore to find minute
quantities of a substance she says will glow in the dark; a Mr. Kepler
wants to hear the songs the planets sing.
        --Carl Sagan, "The Demon-Haunted World"




reply via email to

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