From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: taylanbayirli@gmail.com (Taylan Ulrich =?utf-8?Q?Bay=C4=B1rl=C4=B1?= =?utf-8?Q?=2FKammer?=) Newsgroups: gmane.lisp.guile.user Subject: Re: Transient environment with standard functions Date: Sat, 11 Jun 2016 02:08:36 +0300 Message-ID: <87porowsjv.fsf@T420.taylan> References: <30B0B35B-F6B0-4FD4-A35D-3E6542C3871F@gmail.com> <7B7BC3F7-A25D-427D-8E21-D3583C3C7DEA@gmail.com> <87twh0wxzn.fsf@T420.taylan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1465600051 7526 80.91.229.3 (10 Jun 2016 23:07:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 10 Jun 2016 23:07:31 +0000 (UTC) Cc: guile-user@gnu.org To: Matthew Keeter Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Jun 11 01:07:23 2016 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bBVWM-0007T2-Jl for guile-user@m.gmane.org; Sat, 11 Jun 2016 01:07:22 +0200 Original-Received: from localhost ([::1]:44868 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBVWL-0005dL-Lg for guile-user@m.gmane.org; Fri, 10 Jun 2016 19:07:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43720) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBVVu-0005cs-9n for guile-user@gnu.org; Fri, 10 Jun 2016 19:06:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bBVVr-0000Jk-1m for guile-user@gnu.org; Fri, 10 Jun 2016 19:06:54 -0400 Original-Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:35136) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBVVq-0000IY-Dh for guile-user@gnu.org; Fri, 10 Jun 2016 19:06:50 -0400 Original-Received: by mail-wm0-x236.google.com with SMTP id v199so9691808wmv.0 for ; Fri, 10 Jun 2016 16:06:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=tVh4oz9+rA/2yGUGkuBz+vUfRUsHw5iZa05rPWOPgRw=; b=dKWrBo9nR0p0YbfKmdK0Lf2sAUaAXGGL1rzQrUG6CKkw4XGN63aABO0c6OaNUe9SOE JmlxfmzKamkBVfG2TKT9SjplgUDSygUJPUWiCsGzswsnGOIo/pxwpCMa5+dUfFkewaZi asp6zVy6LQy+W61opbYwGO0lV86/KiEHCsulDpvIVdxXrcqYDoIeSVjPvSgkGcPASBCs KBQ8qs2Z0dx7eeS1CJ2MpiBSjbkY1FEsbH2JKhr/7Sv3/dBEBeT3PEj0uyCCGRcuUtZl Q+g7VGPHMufO0BNnBSS+busnUaUMlGymwxi0N6Z2+q6ZnOL4YOSmSvqOp0onLQoysNg1 sP2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=tVh4oz9+rA/2yGUGkuBz+vUfRUsHw5iZa05rPWOPgRw=; b=BGr0NEO0RAGlN7qnme5thPq1dx8dqk9x66W4cdPQzsO0Yfh2n5qGF6SE4cq2yyWTRa 6fcN3opt0fa/eLDC0rfi2xMc1ROvdmyf1sbz7oyn4Kt8t8n7qTg8djhbxaOQ+GJj+xTi TTBg3UB99QrEB66kxGFUd+2IMv8RDBgsGvmgTwGzI6N2wHLh+qjAiavX84h55SEyA06H xgyg61o48mMmYdEwqVVXHRTcLQ7n52BA7cq1hlWKlF3cGwT6e9rVA/ZFnK7L3s4p/awJ gpmLIJnaNRdpEGwJFgLxjad2GePj4fvZvJPWvNWPu2RpG+p1Lir4b9gobBAxAhXDnOVW /Vmw== X-Gm-Message-State: ALyK8tKLjyMvGmoLZlc2xVTvPT0GdhQF7HkH157b+Dn0ZGbi4AJWyp4lt3e5duM3pPuwkg== X-Received: by 10.28.134.199 with SMTP id i190mr1136901wmd.26.1465600009681; Fri, 10 Jun 2016 16:06:49 -0700 (PDT) Original-Received: from T420.taylan ([78.179.55.193]) by smtp.gmail.com with ESMTPSA id h14sm1299931wme.1.2016.06.10.16.06.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Jun 2016 16:06:48 -0700 (PDT) In-Reply-To: (Matthew Keeter's message of "Fri, 10 Jun 2016 18:31:14 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::236 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 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 Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:12619 Archived-At: Matthew Keeter writes: > However, if I make an empty environment with (null-environment), it > doesn=E2=80=99t have useful functions like + and *; looks like (make-modu= le) > has the same issue. Adding the (guile) module to the environment is going to provide a sane base environment. Let's implement something like R7RS's 'environment': (define (environment . modules) (let ((m (make-module))) (module-use-interfaces! m (map resolve-interface modules)) m)) Now we can: (eval '(+ 1 2) (environment '(guile))) =3D> 3 The environments returned from 'environment' are mutable, but unique: (define e1 (environment '(guile))) (eval '(define x 'x) e1) (eval 'x e1) =3D> x =20=20=20=20 (define e2 (environment '(guile))) (eval 'x e2) ;ERROR: Unbound variable: x > I'm sure that this is possible in Guile, but I got tired of reading > through the source files to hunt down undocumented function that do > what I need [1]. I sympathize. :-) Racket has a ton of personpower behind it, which other Scheme implementations often can't compete with... > [1] Another recent incident: How do you programmatically list all of > the variables in a module? You search the web, find > http://www.draketo.de/proj/guile-basics/#sec-3-2, see a a reference to > module-map, which doesn=E2=80=99t exist in the documentation, dig it up i= n the > source to see its arguments, etc=E2=80=A6 Indeed, Guile's module API in particular is badly documented. Maybe I'll work on it in the coming weeks; I'll have some spare time. In case you're still interested though, here's how I quickly found out how to use module-map in Guile's REPL: scheme@(guile-user)> module-map $7 =3D # This tells me it takes two arguments: a procedure and a module. Let's see what arguments it passes to the procedure: scheme@(guile-user)> (module-map (lambda args=20 (display args) (newline)) e1) ;; output: (x #) (Reusing the 'e1' from the previous example.) So proc is called with a symbol that's the variable's name, and a variable object. Those are documented in: (info "(guile) Variables") It's noteworthy also that imported modules' variables aren't listed; otherwise all of (guile)'s variables would have been listed too. Taylan