public inbox for
 help / color / mirror / Atom feed
From: hello <>
Subject: lisp-syntax-transformer
Date: Mon, 08 May 2000 09:51:00 -0000	[thread overview]
Message-ID: <> (raw)


(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))
       #: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)

(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

             reply	other threads:[~2000-05-08  9:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-08  9:51 hello [this message]
2000-05-08 10:04 ` lisp-syntax-transformer Keisuke Nishida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).