I would like to define a variable within a method but make it available to
the entire module - globally.
Take a string "abc" convert to a variable (symbol??) abc and set to the
string value "def".
The values of name and data are unknown - they are variable.
In this example the variable (symbol??) abc should evaluate to "def".

Thanks tomas you set me on the correct path. The following works:

(define (test-intern)
(let* ((name "abc")
       (data "def")
       )
   (module-define! (current-module)  (string->symbol name) data))
  )

scheme@(guile-user)> (test-intern)
scheme@(guile-user)> abc
$14 = "def"

So yes I will need to read more about interning.
Thanks
Mortimer



On Wed, Aug 16, 2023 at 12:13 PM Jean Abou Samra <j...@abou-samra.fr> 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 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.
>
>
>

Reply via email to