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: define anywhere Date: Sat, 12 Jun 2021 01:43:29 +0200 Message-ID: References: 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="3474"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= , Jean-Paul Roy Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Jun 12 02:08:34 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 1lrrCT-0000km-QS for guile-user@m.gmane-mx.org; Sat, 12 Jun 2021 02:08:33 +0200 Original-Received: from localhost ([::1]:37498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrrCS-0001yY-OE for guile-user@m.gmane-mx.org; Fri, 11 Jun 2021 20:08:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrqoV-0006gW-Jo for guile-user@gnu.org; Fri, 11 Jun 2021 19:43:47 -0400 Original-Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]:42686) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrqoQ-0003cT-MT for guile-user@gnu.org; Fri, 11 Jun 2021 19:43:47 -0400 Original-Received: by mail-io1-xd31.google.com with SMTP id s26so3798845ioe.9 for ; Fri, 11 Jun 2021 16:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rqhQAoNkQVkr2S26U6nORVCJOzhW66MDYa1NP+hZ+x4=; b=k4xr+tyTjOEghG9sAzXgali8r7NWqQ8RsCAvsGFjZygCtSr/fUzuYgjt1qXMGHzYF+ qS03kyGuDpyAJ8KKjZffpiB70rm4nD9MMMJxwpDCfovIdxIymHgUQBzMVR4EOs53ebD0 s0K1M6H4ftifyA3ipkUxQ0p9V/mlgyQP91ytdfIVQi6cqzUtBrqUEJ7n3Ke+Vcxr0jWq LcMTO/s8GP0XnyC6HCK0fjFEO4we4zom3Y6hFUWNsPNaeTguGzY19+Surwc+OSsdP5nv 91WT0e14gpwLnnJpqTjkuANfPnNMmJyCRXgGMS4/SrJH7mz4wRwY+/8yJbKr7eKQIY9h VfQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rqhQAoNkQVkr2S26U6nORVCJOzhW66MDYa1NP+hZ+x4=; b=XDA6fJLmcy+LsuMsG7VisW4ljeqeOtgQTpy24y2YSNBBFY4OpkqSTmRCmyXOx4aOm6 xaQMqXJo5iSmxEDq25+p06eJbbCYhm/D+aHLmjbYNIsJehwiXtJQOmDpSC6q4H4dYQzt ODjDpMrX0lmpBSzRdxj3p7SXV0Aaed86mz1LzZEtqtY6GpkOsqTBuDB2kIJ8HjzyCRtA EjVBnIi6VUIm3UFg3PXdf34ZHKy4suU/8qsIJUn2NRijjhSWtscpbmE6nr8arllct6Hk NQ6cyD0XwHv7ef7ic5Fm2jiHlZ9yeo57t2MJf0ip9vWZf92WNrV1W1z9i00sz09zV/Z4 ++nw== X-Gm-Message-State: AOAM530rxnu3HNhsk4SeN9BfIM6FMPj2jw7axtwbJvcq90i3F0Lf9Kjg 8W7a3ABum9/ItVg3yI03OND027YGKMtAbYC/piA= X-Google-Smtp-Source: ABdhPJwPXnUZ/T1FpM8Xfm7OAKAU2UMqpnSQirrrFVGy5H55f+aUMWNeKi9WidcVR48vCZMx82UVPndlysz8BGVQGpE= X-Received: by 2002:a02:2a0b:: with SMTP id w11mr6313444jaw.22.1623455021186; Fri, 11 Jun 2021 16:43:41 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::d31; envelope-from=damien.mattei@gmail.com; helo=mail-io1-xd31.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_FONT_LOW_CONTRAST=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:17595 Archived-At: hello Linus, finally i tested your code with my program and it works. define worked in if in ssigma-sol-approx ( in *Preview:* ;; (load "SssRec.scm") ;;(use-modules (syntax define));;(use-modules (guile/define))(use-modules (guile define)) (include "first-and-rest.scm")(include "list.scm")(include "postfix.scm")(include "let.scm")(include "definition.scm")(include "guile/array.scm")(include "block.scm") ;; if data are disordered the algo works also ;; scheme@(guile-user)> (define L-init '(1 3 4 16 17 64 256 275 723 889 1040 1041 1093 1111 1284 1344 1520 2027 2734 3000 4285 5027));; scheme@(guile-user)> (start-ssigma-sol-approx-linus L-init 19836);; $1 =3D (1 3 4 16 17 256 275 723 1040 1041 1284 1344 1520 3000 4285 5027)(define (start-ssigma-sol-approx-linus L t) ;; Sub Set Sum problem (find solution or approximation) ;; { } are for infix notation as defined in SRFI 105 ;; <+ and :=3D are equivalent to (define var value) { best-sol <+ (lambda (L1 L2) =09 {s1 <+ (apply + L1)} {s2 <+ (apply + L2)} =09 (if {(abs {t - s1}) <=3D (abs {t - s2})} L1 L2)) } ;; :=3D is the same macro as <+ { best-sol3 :=3D (lambda (L1 L2 L3) =09 {L22 <+ (best-sol L2 L3)} (best-sol L1 L22)) } { ssigma-sol-approx <+ (lambda (L) ;; def is a macro for declared but unasigned variable, it is same as (define var '()) ;;(def c) ;;(def R) =09 (if (null? L) L ($ (define c (first L)) ;; $ =3D begin (if {c =3D t} (list c) ;; c is the solution ($ (define R (rest L)) (if {c > t} (best-sol (list c) (ssigma-sol-approx R)) ;; c is to big to be a solution but could be an approximation ;; c < t at this point, 3 possibilities : ;; c is the best solution ;; c is part of the solution or his approximation ;; or c is not part of solution or his approximation (best-sol3 (list c) ;; c is the best solution ;; c part of solution or is approximation (cons c (start-ssigma-sol-approx-linus R {t - c})) ;; we have to find a solution or an approximation for t-c now ;; c is not part of solution or his approximation (ssigma-sol-approx R)))))))) } =09 =09 ;; start the function (ssigma-sol-approx L)) without you module, my solution was: https://github.com/damien-mattei/library-FunctProg/blob/master/SssRec.scm *Preview:* ;; scheme@(guile-user)> (define L-init '(1 3 4 16 17 64 256 275 723 889 1040 1041 1093 1111 1284 1344 1520 2027 2734 3000 4285 5027));; scheme@(guile-user)> (start-ssigma-sol-approx-basic L-init 19836);; $1 =3D (1 3 4 16 17 256 275 723 1040 1041 1284 1344 1520 3000 4285 5027);; scheme@(guile-user)> (apply + $1);; $2 =3D 19836(define (start-ssigma-sol-approx-basic L t) ;; Sub Set Sum problem (find solution or approximation) ;; { } are for infix notation as defined in SRFI 105 ;; <+ and :=3D are equivalent to (define var value) { best-sol <+ (lambda (L1 L2) =09 {s1 <+ (apply + L1)} {s2 <+ (apply + L2)} =09 (if {(abs {t - s1}) <=3D (abs {t - s2})} L1 L2)) } ;; :=3D is the same macro as <+ { best-sol3 :=3D (lambda (L1 L2 L3) =09 {L22 <+ (best-sol L2 L3)} (best-sol L1 L22)) } { ssigma-sol-approx <+ (lambda (L) ;; def is a macro for declared but unasigned variable, it is same as (define var '()) (def c) (def R) =09 (if (null? L) L ($ {c <- (first L)} ;; $ =3D begin (if {c =3D t} (list c) ;; c is the solution ($ {R <- (rest L)} (if {c > t} (best-sol (list c) (ssigma-sol-approx R)) ;; c is to big to be a solution but could be an approximation ;; c < t at this point, 3 possibilities : ;; c is the best solution ;; c is part of the solution or his approximation ;; or c is not part of solution or his approximation (best-sol3 (list c) ;; c is the best solution ;; c part of solution or is approximation (cons c (start-ssigma-sol-approx-basic R {t - c})) ;; we have to find a solution or an approximation for t-c now ;; c is not part of solution or his approximation (ssigma-sol-approx R)))))))) } =09 =09 ;; start the function (ssigma-sol-approx L)) just had a few problem making Guile 3.0 find the module from an other sub directory, but not the falt of you module, my config i think? Damien On Sat, Jun 5, 2021 at 5:24 PM Linus Bj=C3=B6rnstam wrote: > I implemented this hack before guile 3 got defines in function bodies: > https://hg.sr.ht/~bjoli/guile-define > > Even I guile 3 it allows a more liberal placement of define, but it won't > work for things like bodies of imported macros (like match) > -- > Linus Bj=C3=B6rnstam > > On Sat, 5 Jun 2021, at 00:27, Damien Mattei wrote: > > hello, > > i'm was considering that i want to be able to define a variable > > anywhere in > > code, the way Python do. Few scheme can do that (Bigloo i know) > > ( the list here is not exact: > > > https://www.reddit.com/r/scheme/comments/b73fdz/placement_of_define_insid= e_lambda_bodies_in/ > > ) > > is it possible in guile to do it? i do not know, so could it be added > > to > > the language specification for future release? > > > > regards, > > Damien > > >