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: letrec semantics Date: Mon, 28 Nov 2022 15:07:39 +0100 Message-ID: <8f5d8b22-f073-272f-004b-d18a14f7f166@gmail.com> References: <87sfi379eb.fsf@soeven.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1150"; 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.5.0 To: Alexander Asteroth , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Mon Nov 28 15:08:31 2022 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 1ozeoB-00005w-Df for guile-user@m.gmane-mx.org; Mon, 28 Nov 2022 15:08:31 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozenl-000596-44; Mon, 28 Nov 2022 09:08:05 -0500 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 1ozenS-000529-Hl for guile-user@gnu.org; Mon, 28 Nov 2022 09:07:46 -0500 Original-Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ozenQ-0003bb-Jn for guile-user@gnu.org; Mon, 28 Nov 2022 09:07:46 -0500 Original-Received: by mail-ej1-x62a.google.com with SMTP id n20so26153657ejh.0 for ; Mon, 28 Nov 2022 06:07:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=hWF46oG4ZC42vdfpE+hY6Jk1yOcPOHtVYRn1tipADBY=; b=p2P2ouqU0TLn+ep6CaJYSErU7cYnIgMQl+RUnjOuh4TjUBxlKH5dFK6pnBhQW+oTBK 7ll5IQ9WfA58nBVFAt5C6DIG3wILL17yof0R7ZMjD3SwNwrh5NNClQOSiIrnjhJCuRU8 HR8vAeUsn2yrf3WHszEsDlJUOfcxOHnyGwQ3PU2kzSYQZh0xUsuoNuZUQbrVpYhYaFVN S3unaV1aPC1ikPHXpqaHpuzifRDtQTGRTLh7Xme50SGj3fIyZLOOXXY3uJ4ejS/sRRe3 QxTaIv+LC7UVkl8wpXHHuIGcflPAlPudWKi9pVZw992yRtQW4mNwgEQno5HFTNxJIwHP NqTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hWF46oG4ZC42vdfpE+hY6Jk1yOcPOHtVYRn1tipADBY=; b=Yusp3R7zzXAAzKFOu+EwSdTKP2O3Y4eCVVl94afFB3VxyKzJ/5T/gy7CXotzb7z3G6 KGw3gxMqGsyQFNUd66WoN/mKZBbP1ZQ5M8T64+AaBYKuMAJ+sScHq/vh8Av63+EVfHbH 00A1DwxNRkCLIb7hTmEv/b0+tJHK77N4Od1ue30W+1nKxyMtAcTpoC58/U5hBrxcnc8h eBj1ZrhoX8EcMKZTROQt99t/gLqaZSYxt8cfEgFDPBrb4s6yW3gKXIz/RXeEvdq2DjsX AEabTJZrmi2+KfxFQ3uR0dm0TVTl9Uy/5RNRsyzzO7NvezdvV+tkdfqbAeUF7ebr1AKF BNqw== X-Gm-Message-State: ANoB5pm9sQoin7QN43L7QClLQ5S+ufQjKIvhz+PNPnNHxx4ocz26OGxG aDPkrLmq6AV63PwgLTtWZAZQ3meO6gs= X-Google-Smtp-Source: AA0mqf6Z/dauK0lXEZ3LtVQptJUHwp8RVAt+auXsv8N+rUtHGduX+o/IwBwcuB3Pok7tLgX78t1Brg== X-Received: by 2002:a17:906:a156:b0:78d:9b8b:93cc with SMTP id bu22-20020a170906a15600b0078d9b8b93ccmr44243296ejb.529.1669644462493; Mon, 28 Nov 2022 06:07:42 -0800 (PST) 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 fe9-20020a1709072a4900b007ae0fde7a9asm5007815ejc.201.2022.11.28.06.07.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Nov 2022 06:07:42 -0800 (PST) Content-Language: en-US In-Reply-To: <87sfi379eb.fsf@soeven.de> Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=taylan.kammer@gmail.com; helo=mail-ej1-x62a.google.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 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=-0.257, 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:18754 Archived-At: On 28.11.2022 09:33, Alexander Asteroth wrote: > >> scheme@(guile-user)> (letrec ((b a)(a 7)) b) >> $1 = 7 > > should be equivalent (of course in a new scope) to: > >> scheme@(guile-user)> (define b #nil) >> scheme@(guile-user)> (define a #nil) >> scheme@(guile-user)> (set! b a) >> scheme@(guile-user)> (set! a 7) >> scheme@(guile-user)> b >> $2 = #nil > Hi Alex, The only reason the first example returns 7 is because Guile *happens* to bind a to 7 before it binds b to the value of a. The code could have as well returned another value (IIRC Guile uses #) had Guile decided to evaluate the arms of the letrec in a different order. As per the part of the standard you quoted: > the 〈init〉s are evaluated [...] (in some unspecified order) That's what the "unspecified order" in the parentheses is referring to. On the other hand, in your second code example, there's a strict order in which the various expressions will be evaluated. In the moment you type in (set! b a), the value of a has not yet been changed to 7. If you want to use letrec but with a specific order of evaluation of the arms, then you can use the letrec* variant: > (letrec* ((a 7) (b a)) b) > $1 = 7 This will definitely work, without relying on chance or an implementation detail of Guile. -- Taylan