From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrew Tropin Newsgroups: gmane.lisp.guile.devel Subject: Re: Define works different when Compile and Eval Date: Fri, 21 Jun 2024 16:33:42 +0400 Message-ID: <87r0cq8ogp.fsf@trop.in> References: <875xu5i9qr.fsf@trop.in> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30704"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-devel@gnu.org To: Attila Lendvai Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Jun 21 14:34:16 2024 Return-path: Envelope-to: guile-devel@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 1sKdT4-0007dT-AP for guile-devel@m.gmane-mx.org; Fri, 21 Jun 2024 14:34:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKdSp-0006Jx-TN; Fri, 21 Jun 2024 08:33:59 -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 1sKdSm-0006JO-5A for guile-devel@gnu.org; Fri, 21 Jun 2024 08:33:56 -0400 Original-Received: from out-185.mta0.migadu.com ([91.218.175.185]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sKdSj-000366-OI for guile-devel@gnu.org; Fri, 21 Jun 2024 08:33:55 -0400 X-Envelope-To: attila@lendvai.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=key1; t=1718973227; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BRLN6Qm2qkIg/RlsTfKU0Jxq19/cXrV7sEamj8bc60E=; b=OaMbMzcL909Lh+ccIaobrvGvWudgJfeKdlPddnr/kT7cbQPzJS2IzK9yDjyvGmZdHxnunq ECXodSGom85o20xoxYJDRJ1OMXE6m8IS5OudUwrlGlQCu4Qb5zxaSul/FkkOlvliH/9gHL flBlFU+bVTv50VlHk4cBp1IN+mwzmAI/GXec1wpKFUU/cRcSOVX1+QQ7itj/m+6OZfCI6F EQnucMygG8Tt95UW55caqzreaDQyZ3W+XLXjoWwP8blWuDByTjwbUjjt16P7OK2dDDcTlX eaMbGB4MZxhvLIyCDeVyC2TCZ2eYCZDG7aT1oUCRT23FoRFAd2BdSde8gvlYKw== X-Envelope-To: guile-devel@gnu.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-Reply-To: X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=91.218.175.185; envelope-from=andrew@trop.in; helo=out-185.mta0.migadu.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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22458 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2024-06-19 09:53, Attila Lendvai wrote: >> (define (test-eval teval) >> (teval '(define a 1)) > > if you want this^ to be actually defined while compilation is > happening (i.e. in the compilation stage; see staged computing), then > you need to use an (eval-when (expand) ...) wrapper around it. Thank you for the reply! Not sure what you mean. The following code defines `a`: =2D-8<---------------cut here---------------start------------->8--- (define (test-eval teval) (teval '(define a 1)) (format #t "a value with ~a is ~a\n" teval (teval 'a))) (test-eval peval) (test-eval primitive-eval) (exit 0) ;; a value with # is 1 ;; a value with # is 1 =2D-8<---------------cut here---------------end--------------->8--- The problem and the difference is in how `(define a a)` is evaluated by compile. > > https://www.gnu.org/software/guile/manual/guile.html#Eval-When > > compile does not evaluate (aka load) the definitions, it only compiles th= em. compile returns value by default, which is probably means that everything is loaded as well. > alternatively, you yourself can explicitly call the lambda returned by co= mpile. =2D-8<---------------cut here---------------start------------->8--- (use-modules (system base compile) (system vm loader)) (define (peval e) ((load-thunk-from-memory (compile e #:to 'bytecode #:env (resolve-module '(2024-06-18-define-bug)))))) =2D-8<---------------cut here---------------end--------------->8--- It works the same way as the original code :( > > -- > =E2=80=A2 attila lendvai > =E2=80=A2 PGP: 963F 5D5F 45C7 DFCD 0A39 > -- > =E2=80=9CA politician is someone asking you to trust them more with power= than they trust you with freedom...=E2=80=9D > =E2=80=94 Kelly Diamond > > > =2D-=20 Best regards, Andrew Tropin --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmZ1cyYACgkQIgjSCVjB 3rCFyg/5AfOQAINYxU2FgEG3rusHaZ6EkGchIvgso6mqD/4e0me6PJ6yMBvzN1Kd l+8NzLr87B1GqR+jAF4ZjSTyYYIy4Ps8vSKiEEYxcEBmBYWDWWD7AJeQwvGsiav6 uD+HXWm+p4ayPVmGP0USxf997zgfNLPygYB0T0NbfilE8ngklAUCD0HGfNa51xYl ipZTccSRDyfCiUO7CcKrdz35uBRL2IYQ9NnUBIIM+pkh2SieaOtq6zondSv83HZj MwLWcpZ7xMr0bNXTvtpU+o21iUx/NjeQ3hoUNonEMNgb2x3pzjzY/v2qhRQ7/Krt ZK/5Y+QOZOlNTAeh+F892zL8H5kNJBm2Wy6pIbHafpO+CtI5PqizGSZJwMYbc248 q1J5wLzh1TCqGrWbxnQLjAOoUbNbdcYjkZ1CBEV7PwWxeSRI7Nt0yNdVpThoML21 aNVtSxUv09vRf+4ZPtpxskA5v8NSU6P/obusbv3xhQEd8Jxhz7n7c0Grb5C2e3h4 8ZLsv7h8/Vr/fwhrCVZ8I71fI6sltObaGgeoMhDsRnpN07jrrqlOb8/nVIXfrbsS 6VGrhZq9o6tzyYASwlNhrUU4sgKLURv265qhsAckoWiv4da6mJhgnQdWkayD6QYH wBmdbnsEqiD9xEbopQ+UUOCAd+E+fxlmjsEcXVJzd3c2a8/SOgc= =DRz2 -----END PGP SIGNATURE----- --=-=-=--