From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.user Subject: Re: Req for help on objects and environments Date: Fri, 03 Sep 2004 19:46:49 +0100 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: <1094237209.3785.48.camel@lark> References: <1094027329.4057.78.camel@kuzgun> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1094299527 5082 80.91.224.253 (4 Sep 2004 12:05:27 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 4 Sep 2004 12:05:27 +0000 (UTC) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Sep 04 14:05:17 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1C3ZIC-0006cO-00 for ; Sat, 04 Sep 2004 14:05:17 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C3ZNH-0007tv-6o for guile-user@m.gmane.org; Sat, 04 Sep 2004 08:10:31 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C3ZND-0007sY-Dl for guile-user@gnu.org; Sat, 04 Sep 2004 08:10:27 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C3ZNA-0007ow-KV for guile-user@gnu.org; Sat, 04 Sep 2004 08:10:27 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C3ZNA-0007on-Ha for guile-user@gnu.org; Sat, 04 Sep 2004 08:10:24 -0400 Original-Received: from [216.166.232.203] (helo=johnson-resources.com) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1C3ZHz-0002wJ-Aa for guile-user@gnu.org; Sat, 04 Sep 2004 08:05:04 -0400 Original-Received: from localhost (mantis.schoolnet.na [::ffff:196.44.140.238]) (AUTH: LOGIN wingo) by johnson-resources.com with esmtp; Sat, 04 Sep 2004 08:04:22 -0400 id 001201CC.4139AF4D.00002589 Original-Received: from wingo by lark with local (Exim 3.36 #1 (Debian)) id 1C3J5Q-0001g5-00 for ; Fri, 03 Sep 2004 19:47:00 +0100 Original-To: Guile Users In-Reply-To: <1094027329.4057.78.camel@kuzgun> X-Mailer: Evolution 1.5.93 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.user:3429 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:3429 Hi Alp, I know you've got a lot of answers already, but I think the environment question is still not covered. On Wed, 2004-09-01 at 11:28 +0300, Alp =D6ztarhan wrote: > First, I want to play with the properties on objects. > I want to be able to serialize an object along with its properties. > I *can* make and retrieve properties of objects by use of > (make-object-property). But how do I get a list of the properties of a > given object? In case you didn't figure it out, you can't, except from C with scm_properties_whash. > Second, I want to manipulate the environment in eval. > I could not even do what the documentation tells. > I could not get a handle on (null-environment) etc. (undefined symbol > :-( > Besides, I want to manipulate it, giving extra symbols etc. > Could anybody give me any hint on these? Sure. Scheme actually has two kinds of environments: toplevel and lexical. The first is a simple association of names and values. The concept is very similar to that of "modules", so in guile, toplevel environments *are* modules[0]: (module? (null-environment 5)) =3D> #t By default, guile is not r5rs-compliant when it loads up. I think this is because (ice-9 syncase) is very slow to load up. Anyway, using (ice-9 r5rs) will give you everything in the report, including null-environment. Modules are what can be passed as the second argument to `eval'. They should be accessed only with documented functions for maximum portability between guile versions, and to other schemes. Unfortunately, modules expose their guts too much because everyone sees boot-9.scm. So, to opaquely add a:=3D5 to a module, you can say: (define env (null-environment 5)) (eval '(define a 5) env) (eval 'a env) =3D> 5 If you feel more dangerous, you can use module-define, module-defined?, module-ref, module-variable, etc. See boot-9.scm for more. Dunno what Marius thinks about this, but I like first-class modules :) [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? 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. I tried to be less hacky with the following macro, but define-macro's memoizing behaviour caused guile 1.6 to segfault, so I had to use low-level macros: (define make-environment (procedure->syntax (lambda (exp env) (local-eval `(let* ,(let lp ((in (cdr exp)) (out '())) (if (null? in) (reverse out) (lp (cddr in) (cons (list (car in) (cadr in))=20 out)))) (the-environment)) env)))) ;; e.g. (make-environment a 5 b 6 c a) =3D> 5 (define (bind sym val env) (if (defined? sym env) (begin (local-eval `(set! ,sym ',val) env) env) (local-eval `(let ((,sym ,val)) (the-environment)) env))) There's more in (soundscrape environments), in my arch repository. I wrote this when I just started with guile; the pattern of lexical environments applied to a problem I had. Now I worry about the low-level access. A problem for later, I guess... Hope that helped, --=20 Andy Wingo http://ambient.2y.net/wingo/ _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user