From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.user Subject: Re: Fwd: new function Date: Wed, 22 Sep 2021 09:52:48 +0200 Message-ID: References: <1f773384-058a-f2e3-69cf-b0e23033ec2d@gmail.com> <52130eefb713942a36aa5717ef4c916173567ce3.camel@telenet.be> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17691"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user , Matt Wette To: Maxime Devos Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Sep 22 09:59:49 2021 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 1mSxAS-0004I8-TB for guile-user@m.gmane-mx.org; Wed, 22 Sep 2021 09:59:48 +0200 Original-Received: from localhost ([::1]:48760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSxAP-0007iU-Iy for guile-user@m.gmane-mx.org; Wed, 22 Sep 2021 03:59:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSx3v-0007BM-DI for guile-user@gnu.org; Wed, 22 Sep 2021 03:53:07 -0400 Original-Received: from mail-il1-x131.google.com ([2607:f8b0:4864:20::131]:40779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSx3t-0000qI-EI for guile-user@gnu.org; Wed, 22 Sep 2021 03:53:03 -0400 Original-Received: by mail-il1-x131.google.com with SMTP id a20so1785614ilq.7 for ; Wed, 22 Sep 2021 00:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7uxNjKMC6bgVzmYBO8jTE3QhJu//MBjfQuxFTf7LhZw=; b=Syj7mC9BhMGW5dncVRa3yPAQOGZzHMEBmkpRjP4wmwPLxEOZupY8xQgMhad1+DY/lr gndj/YWFnyB6tpMnaDHvbnF1ZEQHurQYvkpF/xsujeYyv5Ct50g5vUKliM+xUeBEO2EL W8reZlf1Fh5YGz19CVcri6gRscoFGTRCQ/3l0X8NKSe9nVP0ciC31qDEEgB/S3nfalr3 x8aryEOqNKPqArwCD7Oa6gyyRTkZjz0itvVOBkK6M0tfK8sMZgaJdidMVxLyqWNA9VoR 3a9rPUoat7rhzE6U7hblgvch9vPyFF/pRR7ITtyZS26OizpUvaq+nq+HlAOLuYbPiZKg PlFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7uxNjKMC6bgVzmYBO8jTE3QhJu//MBjfQuxFTf7LhZw=; b=REKsZ3fBlnUGYR7eUpXW241ExaAKs5K+oZvAMtDpPa783tvEsiJIBkkA7FdjSOW74L HM7w1Pl6mXlfF23vNrmSYza3NMkUOpEXbs+y/ctzX7wWS6dBFGOJTRgrGi6mjk4s7Iyc WXpM1imJFEzAjWVTxlZ2as9dWVNxilMzItYC2fGDZSAbhMqGZBv8VJGVcPm7RZXXAivI OqbuEQbwvZ9S4aUcD2RMlB9ML+GAm63yRfvcdkJHQQHdd78MHQQWVcwVsxbTRvjEbC07 1F1PK993jo8NsrOrk9Reo2+vEgEYsqb072TtAjCFBWOte2+UTI6T9LMyFcMaPTSGH9Ek cQQA== X-Gm-Message-State: AOAM533QHnBjRu35e1+3z0zuEPS823pzLM1lleeDlY6wNRh+VHF0gHz5 uYXOJ4J5JgBLTD+/SRLK4NKuPeBmCseV5ZzLsWA= X-Google-Smtp-Source: ABdhPJwJZ888NBYvHlSjkd9GB2cW32wmMRynV93ULRtruQmd3tuLlrNOYv65rfVvsXWjIipvGKb3Sv4c9kB3c8uWcQI= X-Received: by 2002:a05:6e02:48d:: with SMTP id b13mr24542740ils.171.1632297180171; Wed, 22 Sep 2021 00:53:00 -0700 (PDT) In-Reply-To: <52130eefb713942a36aa5717ef4c916173567ce3.camel@telenet.be> Received-SPF: pass client-ip=2607:f8b0:4864:20::131; envelope-from=damien.mattei@gmail.com; helo=mail-il1-x131.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.23 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.lisp.guile.user:17775 Archived-At: i do not understand well what you want to mean with those example. For me define-once does not seems to be a solution, it act as define too much ,does not set! variable if already exist and can not use to set it again because, as define it is forbidden twice in the same block for the same variable: scheme@(guile-user)> (define (foo3) (define-once x 1) (if #t (let () (define-once x 2) ;;(set! x 2) (display "x=") (display x) (newline) (define-once x 3) ;;(set! x 2) (display "x=") (display x) (newline) ) 'never) (display x) (newline)) While compiling expression: Syntax error: unknown file:51:6: invalid or duplicate identifier in definition in form (let () (define-once x 2) (display "x=") (display x) (newline) (define-once x 3) (display "x=") (display x) (newline)) i will try (use-modules (system syntax)) that yesterday seems to give better results On Tue, Sep 21, 2021 at 9:03 PM Maxime Devos wrote: > Damien Mattei schreef op di 21-09-2021 om 15:04 [+0200]: > > i have tested define-once > > http://www.gnu.org/software/guile/docs/master/guile.html/Top-Level.html > > (the defvar of Lisp)and idea are: > > -unfortunately it is considered by scheme as a define,so there is some > > context where it is not allowed in my code > > -seems to work fine at toplevel (as mentioned in doc) but strange > behavior > > in a function, i did not understand really what happened but i got some > > #unspecified value. > > > > here are my test code: > > cheme@(guile-user)> (define (foo2) > > (define-once x 1) > > (if #t > > (let () > > (define-once x 2) > > ;;(set! x 2) > > (display "x=") > > (display x) > > (newline)) > > 'never) > > (display x) > > (newline)) > > Possibly you want (added a set? argument for demonstration): > > (define (foo2 set?) > (define x) ; define an (undefined or unbound, not sure about > terminology) variable > (if set? > (let () > (set! x 2) ; change the value of x > (display "x=") > (display x) > (newline)) > 'never) > (display x) > (newline)) > > That should be portable and avoids global state. > > scheme@(guile-user)> x > ;;; :20:0: warning: possibly unbound variable `x' > ice-9/boot-9.scm:1685:16: In procedure raise-exception: > Unbound variable: x > scheme@(guile-user) [1]> ,q > > scheme@(guile-user) [1]> (foo2 #f) > # ; I expected an error as would result from ... > > ;; ... this ... > scheme@(guile-user)> (variable-ref (make-undefined-variable)) > ice-9/boot-9.scm:1685:16: In procedure raise-exception: > In procedure variable-ref: Unbound variable: # value: #> > > Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. > scheme@(guile-user) [2]> > > ;; instead of # but whatever ... > > scheme@(guile-user) [1]> (foo2 #t) > x=2 > 2 > scheme@(guile-user) [1]> (foo2 #t) > x=2 > 2 > > > scheme@(guile-user) [1]> (define x 3) > scheme@(guile-user) [1]> (foo2 #t) > x=2 ; foo2 doesn't use the global variable 'x' > 2 > > scheme@(guile-user) [1]> x > $1 = 3 > > Does this seem reasonable to you? >