From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Taylan Kammer Newsgroups: gmane.lisp.guile.user Subject: Re: intern a top level variable Date: Wed, 16 Aug 2023 22:35:39 +0200 Message-ID: <8fa88dc6-48ca-900f-6ee8-51b9c0229362@gmail.com> References: <5306923bbfa46630b22c6dc978e89b60d0565ad9.camel@abou-samra.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19760"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Cc: guile-user@gnu.org, tomas@tuxteam.de To: Mortimer Cladwell , Jean Abou Samra Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Aug 16 22:36:22 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 1qWNFe-0004wl-DU for guile-user@m.gmane-mx.org; Wed, 16 Aug 2023 22:36:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWNF6-0006OR-MX; Wed, 16 Aug 2023 16:35:48 -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 1qWNF4-0006O2-44 for guile-user@gnu.org; Wed, 16 Aug 2023 16:35:46 -0400 Original-Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWNF1-0007MI-Fv for guile-user@gnu.org; Wed, 16 Aug 2023 16:35:45 -0400 Original-Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-99bf3f59905so922708166b.3 for ; Wed, 16 Aug 2023 13:35:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692218141; x=1692822941; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ArT3KGBd0cEe1dv+nHB+NBt9Xr1onjImPysamhhyzWs=; b=QksXe9qvfjisVPfAGcgHfwogif4oPF6KQLv1nIH2C+zVxmwS1oHJukz54Er7+tbGqm 2AaSHL9lzmOs30wY5refPWW7anvhNqL0iAfjtbDr3Xr74SKy/YeJREtWloM+TIialL3f GlaiqZ+3N+COHEkmy47zFOEQzigfMboZECbJzMsKR6qpbRhM4IaUNl7xTPYdaoP95IYm J5PYolX4mVsGEX5DQY90VYdjNuXs2bvs/Rj8iPKwpxIf8aOsaWQtQauV4gDP1jw6m3kp UUEWI83XWHHVX43N/0PYzp/NJG9lns6GqO98rFSQQd6y/XlOxuAlcY2q8hXpCVzSMjiZ 2w1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692218141; x=1692822941; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ArT3KGBd0cEe1dv+nHB+NBt9Xr1onjImPysamhhyzWs=; b=Rqz9pI/yGVomnDka/PSjeVkNA8Cm97H7bC8KUVPKr6ZYnBg5imA75FxWA7tF2qaLCb YkW1CluqFlShU9SvwI4aE3cvV1daL4zKWcjqQGjjmIkCrP7N5iGmLtlFLwKzr+JFZyqw jMCUl3nqMQN5mea6e1XX5Gr9QVLknu2oG7q9Jiarayr7mgWPjdNQeeCqzR12w2K6SxHo ekdw9qFzeSJoUb45SvgHTBnXt9JzO2RkHAxEXZmvs3AaeSkY8SAm7qBYRDYoFKhmqayl RJNgKTaQTuO2GOBpd+xUMHSX6F5gMLhDAXUkekLuWU1RnioLSrFymh9E29pZLVFXCNjl Rw2Q== X-Gm-Message-State: AOJu0Ywzgeo24ZYQYrwDReriu0Z8/JKt/ZDZ4IgfnMPMlNCXRuw30rMe Bt0sGYUx6sheiEzsgm0NBXU= X-Google-Smtp-Source: AGHT+IGQnqMxfSqAaqcfwuB6vh+WoNeUT0oI7M7DnqU9pk4LMicubNMpRg8IucFfuQeT42bUg8wWvw== X-Received: by 2002:a17:906:dfdc:b0:99d:9a55:1f5c with SMTP id jt28-20020a170906dfdc00b0099d9a551f5cmr2764977ejc.51.1692218141274; Wed, 16 Aug 2023 13:35:41 -0700 (PDT) Original-Received: from [192.168.178.20] (ip-109-090-125-150.um36.pools.vodafone-ip.de. [109.90.125.150]) by smtp.gmail.com with ESMTPSA id f8-20020a17090624c800b009894b476310sm8889673ejb.163.2023.08.16.13.35.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Aug 2023 13:35:40 -0700 (PDT) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=taylan.kammer@gmail.com; helo=mail-ej1-x62c.google.com X-Spam_score_int: -52 X-Spam_score: -5.3 X-Spam_bar: ----- X-Spam_report: (-5.3 / 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, NICE_REPLY_A=-3.165, 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-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:19170 Archived-At: 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