guile-user
[Top][All Lists]
Advanced

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

(un)quoting, evaluation, and environments


From: Stephen Scheck
Subject: (un)quoting, evaluation, and environments
Date: Mon, 31 Aug 2020 16:31:46 -0400

Hello,

I'm puzzled by what is going on here:

    scheme@(guile-user)> (eval-string "`(foo ,b)")
    ERROR: In procedure %resolve-variable:
    Unbound variable: b

    Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
    scheme@(guile-user) [1]> ,q
    scheme@(guile-user)> (define b 'bar)
    scheme@(guile-user)> (eval-string "`(foo ,b)")
    $1 = (foo bar)
    scheme@(guile-user)> (null-environment 5)
    $2 = #<interface (#{ g298}#) 7f4447df16e0>
    scheme@(guile-user)> (eval-string "`(foo ,b)" $2)
    $3 = (foo (unquote b))
    scheme@(guile-user)> (eval-string "`(foo ,b)" (current-module))
    $4 = (foo bar)
    scheme@(guile-user)> (module-ref (current-module) 'b)
    $5 = bar
    scheme@(guile-user)> (module-ref $2 'b)
    ERROR: In procedure scm-error:
    No variable named b in #<interface (#{ g298}#) 7f4447df16e0>

    Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
    scheme@(guile-user) [1]> ,q
    scheme@(guile-user)> (module-define! $2 'b 'bar)
    scheme@(guile-user)> (module-ref $2 'b)
    $6 = bar
    scheme@(guile-user)> (eval-string "`(foo ,b)" $2)
    $7 = (foo (unquote b))

Why does b get evaluated in the default environment (current module), but
gets unquoted for one passed as an argument to eval-string? What is
different about these environments? Is there a correct way to use a
different environment, such that the result is the same?


reply via email to

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