[Top][All Lists]

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

Re: Req for help on objects and environments

From: Marius Vollmer
Subject: Re: Req for help on objects and environments
Date: Tue, 21 Sep 2004 22:47:27 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Andy Wingo <address@hidden> writes:

> [0] This is complicated by the existence of environment SMOBs, from
> environments.c / environment-*. I have no idea whether this code is
> on the way in, or the way out. Marius, Dirk?

They are not used by Guile at the moment, but maybe they will be in
the future.  Or maybe not.  Their existence has caused a few
confusions, so maybe it is best to remove them...

> Lexical environments are a different beast. You cannot access them with
> r5rs, I don't think. However, with guile you can, although it's
> definitely not documented.

It is best not to fiddle with the implementation of lexical
environments (expect when you are writing a debugger, say).  Something
like the following might be sufficient and is cleaner.

    (define (make-environment . bindings)
      (let loop ((b bindings)
                 (env '()))
        (cond ((null? b)
               (loop (cddr b) (cons (list (car b) (cadr b)) env))))))

    (define-macro (with-env env . body)
      (let ((module (current-module)))
        `(let ((code (cons* 'let ,env ',body)))
           (eval code ',module))))

    (define env (make-environment 'a 12 'b 13))

    (pk (with-env env (+ a b)))

GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405

reply via email to

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