From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mortimer Cladwell Newsgroups: gmane.lisp.guile.user Subject: Re: intern a top level variable Date: Thu, 17 Aug 2023 02:07:41 -0400 Message-ID: References: <5306923bbfa46630b22c6dc978e89b60d0565ad9.camel@abou-samra.fr> <8fa88dc6-48ca-900f-6ee8-51b9c0229362@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18702"; mail-complaints-to="usenet@ciao.gmane.io" To: Taylan Kammer , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Aug 17 08:08:34 2023 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qWWBO-0004iL-2P for guile-user@m.gmane-mx.org; Thu, 17 Aug 2023 08:08:34 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWWB2-0001Pd-OE; Thu, 17 Aug 2023 02:08:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWWAn-0001Mj-Vz for guile-user@gnu.org; Thu, 17 Aug 2023 02:07:58 -0400 Original-Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWWAk-0004v5-G2 for guile-user@gnu.org; Thu, 17 Aug 2023 02:07:57 -0400 Original-Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-54290603887so4582290a12.1 for ; Wed, 16 Aug 2023 23:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692252473; x=1692857273; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=YaAXooLINqgnuXIXJRfaVyq9Uv+uujCzCnVK1jhs0jM=; b=rnyrDVci4NF34UvWhZnuR9E1N2lVXs1Xv8nmSorIIk5ySXvBOebiOzKMzx0MoO5JTZ auXyQ+XQBLb5H6OJaq05nKzd97aIcsfn2eR4XnjDWZvGyneAEfOPX/hwnUMu8gxDkxDr W9mU56RezaabH25hbRDHD4zMFioyRdi0SaI2uuIQUtUbYNm1PeykbLDcz0R4ykagOk26 Vx6Dwmj77r7jj2e/0itOYQUPqY3r6/Dv4zF1TPSMFeYzwxV8552Da1e2w/LUqE/l18Zm QVK5bW2GqOame8N7C4dx3ufpPFTjDXfMjt+zN1cOXS2GmXlPXouhX8Zo5OMZOXPFlIhs AAIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692252473; x=1692857273; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YaAXooLINqgnuXIXJRfaVyq9Uv+uujCzCnVK1jhs0jM=; b=AMj7wzB3dl3B/oCVGCkxVAY7Y2wSaAjmi/VWf7JgD3fqgWDf8oPcH11kIc7iQh98Cd Q+WNDjwNE32q5Cs/u71GWIjRxcwGgG5VvrKuHzLyUvtiveTWTgOYWyvXMhOQVZWNMyy2 F8LCF20Wf604oCfVvXNnVvi/2TF6clpxHKiQe5ckCIkBXdyaEt2ul39lknyz4gu8tIzY lbem650yFxwYb2yllTDJuDKc5kluktc6ITgMS9a5gdEV2BGqRjk64m6sMfXApM3S6pH4 8n3ZnbrPFLg3H1fGRSRbI0lsbrGQAAePq8rrQ47eIEZFSjZFukUE8yNjMHFglQUiaT7D NAyQ== X-Gm-Message-State: AOJu0YxzpYyNtkj5yQCetBTzAMxzpb7yqbT2jgkx6GeuQcZXu0+48sX5 ngh4x+I43bzqqtUvnXzk5eKHnrDLaoyjAqccz3Y= X-Google-Smtp-Source: AGHT+IHBDFJn4e2jJLzEOmUPYgsbYPeVmRWPYdU6beCwypQVBbytn6gHUaL+rw5HumJ05Ux0DYsjEiO83GHD8V5ifOE= X-Received: by 2002:a05:6a20:13cf:b0:13f:9dbc:e530 with SMTP id ho15-20020a056a2013cf00b0013f9dbce530mr4026802pzc.8.1692252472729; Wed, 16 Aug 2023 23:07:52 -0700 (PDT) In-Reply-To: <8fa88dc6-48ca-900f-6ee8-51b9c0229362@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=mbcladwell@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19171 Archived-At: > is the name of the variable only going to be known when the program has already begun running yes the values of name and data will be substringed from an argument passed to the method at runtime Thanks Mortimer On Wed, Aug 16, 2023 at 4:35=E2=80=AFPM Taylan Kammer wrote: > On 16.08.2023 21:17, Mortimer Cladwell wrote: > > 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)) > > ) > > > > The "normal" way to do something like this would be with a macro that > takes the > name of the variable to be bound, like so: > > (define-syntax defvar-example > (syntax-rules () > ((_ ) > (define "def")))) > > (defvar-example abc) > > ;; variable abc has now been set to "def" > > Is there any particular reason the name has to come from a string in your > case? > > For example, is the name of the variable only going to be known when the > program > has already begun running, and doesn't appear in the initial source code? > That > would be one case where you really have to use 'module-define!' to do it. > > > (Note: I use pattern variables like out of personal preference; > there's no > special meaning to the <> around the name.) > > -- > Taylan > >