unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: tomas@tuxteam.de
To: Jean Abou Samra <jean@abou-samra.fr>
Cc: Mortimer Cladwell <mbcladwell@gmail.com>, guile-user@gnu.org
Subject: Re: Re: intern a top level variable
Date: Wed, 16 Aug 2023 19:58:54 +0200	[thread overview]
Message-ID: <ZN0OXrKVrJ8gm2FH@tuxteam.de> (raw)
In-Reply-To: <5306923bbfa46630b22c6dc978e89b60d0565ad9.camel@abou-samra.fr>

[-- Attachment #1: Type: text/plain, Size: 2086 bytes --]

On Wed, Aug 16, 2023 at 06:13:05PM +0200, Jean Abou Samra wrote:
> Le mercredi 16 août 2023 à 10:55 -0400, Mortimer Cladwell a écrit :
> > I would like to intern and assign a value within a method:
> > 
> > (define (test-intern)
> > (let* ((name "abc")
> >        (data "def")
> >        (name-symbol (gensym name))
> >        )
> >   (pretty-print (string-append "symbol: " (symbol->string name-symbol)))
> >   (set! name-symbol data)))
> > 
> > scheme@(guile-user)> (test-intern)
> > "symbol: abc3301"
> > scheme@(guile-user)> abc3301
> > ;;; <unknown-location>: warning: possibly unbound variable `abc3301'
> > ERROR: In procedure module-lookup: Unbound variable: abc3301
> 
> 
> Sorry, but it's not clear to me what you mean by "intern and assign a value",
> and I don't think it will be clear to someone else.
> 
> Can you be more precise please?

I think what the OP wants is to make a binding for
an existing symbol. Something, perhaps like

  scheme@(guile-user)> (define foovar (gensym "foo"))
  scheme@(guile-user)> foovar
  $1 = foo170
  scheme@(guile-user)> (module-add! (current-module) foovar (make-variable 42))
  scheme@(guile-user)> foo170
  $2 = 42

(note that the "top level" is Just Another Module).

Mortimer: is that what you were looking for? Note that
"you usually don't do this" (whatever that means), so
it'd make sense to take a step back and think about what
you are trying to achieve :-)

> I don't understand why you expect "abc3301" to be bound after running (test-
> intern). That (test-intern) call just creates a symbol, which is interned as a
> symbol, meaning that creating another (interned) symbol with the same name will
> reuse the same symbol value. But there is no reason why it shoud be bound to a
> variable. Symbol interning just applies to symbols as values, it has nothing to
> do with variables.

In any case it would make sense to revisit the concepts
of "symbol", "variable" and "binding". It's subtle, but
in Lispy lands it is indispensable.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2023-08-16 17:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-16 14:55 Re: intern a top level variable Mortimer Cladwell
2023-08-16 16:13 ` Jean Abou Samra
2023-08-16 17:58   ` tomas [this message]
2023-08-16 19:17   ` Mortimer Cladwell
2023-08-16 20:35     ` Taylan Kammer
2023-08-17  6:07       ` Mortimer Cladwell
2023-08-20 13:56     ` Jean Abou Samra

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=ZN0OXrKVrJ8gm2FH@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=guile-user@gnu.org \
    --cc=jean@abou-samra.fr \
    --cc=mbcladwell@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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).