This is the mail archive of the
guile-emacs@sourceware.cygnus.com
mailing list for the Guile project.
lisp-syntax-transformer
- To: guile-emacs at sourceware dot cygnus dot com
- Subject: lisp-syntax-transformer
- From: hello <kxn30 at po dot cwru dot edu>
- Date: 08 May 2000 12:51:26 -0400
Hello,
(define-class <lisp-variable> ()
(sym #:accessor sym #:init-keyword #:symbol)
(var #:allocation #:virtual
#:slot-ref (lambda (i) (%lisp-eval (sym i)))
#:slot-set! (lambda (i v)
(%lisp-eval `(setq ,(sym i) ',v))
*unspecified*)
#:accessor lisp-value))
(define-method (write (obj <lisp-variable>) port)
(display "#<lisp-variable " port)
(display (sym obj) port)
(display ">" port))
(define user-full-name (make <lisp-variable> #:symbol 'user-full-name))
user-full-name => #<lisp-variable user-full-name>
(lisp-value user-full-name) => #<foreign-object <emacs-string> 4047e070>
(define (transformer x)
(let ((lisp-symbol? (lambda (o) (eq? (string-ref o 0) #\$)))
(lisp-value (lambda (o) (list 'lisp-value
(string->symbol (substring o 1))))))
(if (and (symbol? x) (lisp-symbol? x))
(lisp-value x)
(letrec ((trans! (lambda (x)
(cond ((pair? x)
(if (symbol? (car x))
(if (lisp-symbol? (car x))
(set-car! x (lisp-value (car x))))
(trans! (car x)))
(trans! (cdr x)))))))
(trans! x)
x))))
(transformer '$foo) => (lisp-value foo)
(transformer '(set! $foo #t)) => (set! (lisp-value foo) #t)
(use-syntax transformer)
(set! $user-full-name "hello")
$user-full-name => #<foreign-object <emacs-string> 4042a298>
(%lisp->scheme $user-full-name) => "hello"
Any comment?
-- Kei