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: cond clause does not allow definitions Date: Thu, 23 May 2024 16:25:27 +0200 Message-ID: References: <5d1be852da93dd324fdbcaa24ed1b444@aleph0.info> <9ff8d2d644823f62e416047582433d2b@aleph0.info> 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="32536"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Pierpaolo Bernardi , guile-user To: Jeronimo Pellegrini Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu May 23 16:26:26 2024 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 1sA9Ok-0008CC-Bc for guile-user@m.gmane-mx.org; Thu, 23 May 2024 16:26:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9O4-0003LV-Gw; Thu, 23 May 2024 10:25:44 -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 1sA9O2-0003Jk-6k for guile-user@gnu.org; Thu, 23 May 2024 10:25:42 -0400 Original-Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sA9O0-0005qu-1B for guile-user@gnu.org; Thu, 23 May 2024 10:25:41 -0400 Original-Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-792e4c2a002so185064685a.0 for ; Thu, 23 May 2024 07:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716474339; x=1717079139; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=otxqLe+r8wgMMu+Y1eALsBorf1wngg37jOai3JrjHb4=; b=niz99bE1sJ++Z4wHQfkrgeXZYUVbaBU6piELzSDkXF1nXhnbs2e3gl0x+ubeaveQVb PHyk7wjU66VJruyhQQFwfxDVyInEdLFgEHOmPb5XQofK47iLAYcQprNWKdWJzF1OT2wH 4+UuSTBh3mIOJXogWVOKbxaWYpNPiryDOOWHSaC1sPFmDJS0nlfaRacKcYUJi8ZyfMIp +SQACo6K0Frmx5So95rLGN8oT1LeNSd459cl1RgFoc1my/ArtWfkQ/zcJofgrq6fhRNj adyywBcEJYMoMjMna2P0gJr7szCBepSv/B5PrwKCU0Vlf+dqfGjTzoiTYBUsI08xPQ0w K3aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716474339; x=1717079139; h=cc: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=otxqLe+r8wgMMu+Y1eALsBorf1wngg37jOai3JrjHb4=; b=KJrIKAtRsyOKCWopIi/7uAlDPFS+C3jIWUlSd6ELuLahNeNeZjhd41hjslrv31fTVt KGO52tPJyJbHKDN1MsbHa3hZ0nrLvLOsfb7FNKgkzGxTMP/lNduzkz4qiKk9KO4mUDvC rIjdTdyR0uyVEtQO3hQnkRaxQy/K5Q4AI5gtZHeTww4qjsX5RIGZ/mWIK1cZXhyz1PH8 4ZzIZhL6SO+H5G6K8EwjAwAjq274Eotqfi5LwGL00kFxEavoKYiIdikYdkWazHawbhe2 ZBmM7o9BdXvhsramFyvdmhyerx13Tg/IV9Gv07amLMpVhQq//5cbnM24FjHEs6m3aWgk 6O7Q== X-Forwarded-Encrypted: i=1; AJvYcCXi8veyOU9qRLKTcylWWKIEz0xOidfe6vrWvHjV3/A+tYmkjnGgGgzzGbEg62G52lM1Ts5QM2PL0duJ6sfloRQjC3M= X-Gm-Message-State: AOJu0YwdAF3QO+bn90A3ceQoIaJ1mWESoZu/7KCD+DbJpZAJSj3r7MyF AobfwtBlUDO3MIYRJtEaw/OKb8tEa2iGnIa5mZMFgmFuIMtLn6ueT/4PZOpa/TyPqIpOROdyUlO bAytbBR/fKpSxVigdOWAiEvs1SuM= X-Google-Smtp-Source: AGHT+IGENTPbO5bwqmA9p9daR0eRamtJ8iv75L702ANUo3VB6V/EiTMnY0uaoAeAWe7P47A/2Ih18qlZULzjErunxoU= X-Received: by 2002:a05:620a:98a:b0:794:9c80:7299 with SMTP id af79cd13be357-7949c8076camr447308085a.3.1716474338680; Thu, 23 May 2024 07:25:38 -0700 (PDT) In-Reply-To: <9ff8d2d644823f62e416047582433d2b@aleph0.info> Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=damien.mattei@gmail.com; helo=mail-qk1-x735.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:19686 Archived-At: On Thu, May 23, 2024 at 12:37=E2=80=AFAM Jeronimo Pellegrini wrote: > On 2024-05-22 18:07, Pierpaolo Bernardi wrote: > > In chez: > > > >> (cond (else (define x 7) x)) > > 7 > >> x > > 7 > > > > which looks like a bug to me. yes ,unless they wanted Chez scheme to behave as Python :-) : if True: x=3D7 x 7 You may check if x is defined outside of > > the cond expression in the other implementations which do not raise an > > error too? > > Sure! And the result varies a lot! > yes i spent many hours debugging to understand why (cond (else (define y 7) y)) worked and not (cond (#t (define x 7) x)) just for info in Racket there is 'identifier-binding' to know if an identifier is already bind, this is only useful in a macro syntax context but it works great. I'm able to remove all 'define' (and i think 'let') of the code, the code testing itself if a variable is already binded and define it when necessary= . In summary this works with this macro: #lang racket (define-syntax (if-defined stx) (syntax-case stx () [(_ id iftrue iffalse) (let ([exist-id (identifier-binding #'id)]) (if exist-id #'iftrue #'iffalse))])) (define-syntax :=3D (lambda (stx) (syntax-case stx () ((_ var expr) #'(if-defined var (set! var expr) (define var expr)))))) it works in any situation, and the checking of the binding of the identifier seems to be done before the run-time (!) when in a program. example at REPL but works in all my programs: Welcome to DrRacket, version 8.13 [cs]. Language: racket, with debugging; memory limit: 8192 MB. > (:=3D x 7) > x 7 Welcome to DrRacket, version 8.13 [cs]. Language: racket, with debugging; memory limit: 8192 MB. > (define x 7) > (:=3D x 8) > x 8 original code from: https://stackoverflow.com/questions/20076868/how-to-know-whether-a-racket-v= ariable-is-defined-or-not > J. >