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: escaping from a recursive call Date: Thu, 10 Nov 2022 06:25:55 +0100 Message-ID: References: <8735asoytw.fsf@laura> <87y1sknhb5.fsf@laura> <87v8nnoba8.fsf@laura> 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="38436"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: Olivier Dion , Zelphir Kaltstahl Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Nov 10 06:27:05 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 1ot05h-0009oC-3c for guile-user@m.gmane-mx.org; Thu, 10 Nov 2022 06:27:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ot04q-0000h4-7u; Thu, 10 Nov 2022 00:26:12 -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 1ot04p-0000gj-Dr for guile-user@gnu.org; Thu, 10 Nov 2022 00:26:11 -0500 Original-Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ot04m-00055p-VB for guile-user@gnu.org; Thu, 10 Nov 2022 00:26:11 -0500 Original-Received: by mail-ej1-x62c.google.com with SMTP id m22so2188471eji.10 for ; Wed, 09 Nov 2022 21:26:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=BkXoKosbp3dgr//awoIHJCKHcw1apMZsZeAK6mO7Rns=; b=d4Bp4hVZgbCJ/Azan90Avmz4u8sXuon0vKz6W24etQf59IL/wCj9zBOwlUF+QruqGh y/fhy1Jz7Ynnzg7r9HV+2Pji5qJXCBaas2gwUawbyE/x01twVVmd03VWodWyGmu4CKgt qTKRHx2BAynb6d1Bx/mUADWr2NueMqnSfa/a8hCnvqFV36NtKm6cQM63Zijs3Tv2zmwH VUaCkJKmDK+8PF1b/ldy0Z68DEVYzyHBWuT0Yhxouxq+GP754mZcHp3o5OXdq3lDPNkq XjHFBvWKT0JorukqJVBwerLFPFqCKwwzK6W0LMmd8LhgfUtkQflT0SolZXO48erO6w1X TSrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=BkXoKosbp3dgr//awoIHJCKHcw1apMZsZeAK6mO7Rns=; b=lBSRFl6s00s/LELYKeZKlva72YCf99vNzLQYG94rHK6D3Xf9bgyeGTvw+okBN/dJPt 1DrB9/pZfPFtCwhvaWxEpd/OQ1CbmIrcCMf+xiZ+gGl9sBwb6Xp7EaetkOc70zWUaq+x feX6K6jZzOlj24HD1Z/IO5GdSqTo+KS6klb+RnmXxXL4urMpKDxFryEhQC3bIZK6f95m Hs6+p+ZACpcRce1wTF87BvmQfFhaqC5ixZyIZTTihniLNhXRfhV8enl4o0UoRipzXLG7 +9WNuJmppDAyjYq9GqVfx7zWcLWOHo48Cf9HDPfbmBdEEQ/4nofM/L0FjaBaqSRcoN11 xuxA== X-Gm-Message-State: ACrzQf0OSLGjlxOwmqZmZOEa7pKNe0kmFB4YXHUQtJo4Kt6oSahwyyCh QBY7gncRPSKIkzED2h2Lxn6m47Pc0ELam3HKmic= X-Google-Smtp-Source: AMsMyM7W8GcEWkDz0ni+fLGG6e7HdVQ9PegehYtey5pkP9SSlVxrp8cCIk+YZJeROnKBL5SVXw43EuQEl+v+pZ0vXWI= X-Received: by 2002:a17:906:af6b:b0:7a9:ecc1:2bd2 with SMTP id os11-20020a170906af6b00b007a9ecc12bd2mr2259764ejb.545.1668057966525; Wed, 09 Nov 2022 21:26:06 -0800 (PST) In-Reply-To: <87v8nnoba8.fsf@laura> Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=damien.mattei@gmail.com; helo=mail-ej1-x62c.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:18709 Archived-At: yes Olivier, i had found the Guile doc and i was asking myself, but the doc is quite "succint" without a lot of explanation and i'm asking if it exists more documentation and if it is or will be standardised in any R?RS... and i'm asking too how can it be integrated in my macro 'def to be used in any procedure definition... it is like the solution of Zephir, i do not want to explicitly pass the continuation to the function , i wanted a schema that allow to capture the continuation exactly before the initial function call (not at function definition, not at the current level of recursion,my previous 'def macro already do that ...) and that was not so easy, i'm glad of this solution (that provide 'return for the current level of recursion and 'return-rec to escape all the recursive calls), but i admit i find it more by intuition than logic and i'm asking if it will work in any situation i will encounter? see the example below that motivate my research... will it work well in // code with future or thread ,i'm having already problem with // code that,compute well but show no speed up, is it because of continuation? not being compatible with //,does macro generates functions that causes unknown problem to // code, i try to get rid of macros and continuation in // code but i always fall back using them... i was in need of a way to escape the recursive call in a function that unify two minterms. Minterms (example: 0100101) are represented by lists : (0 1 0 0 1 0 1) ,they have weight , the weight is the # cardinal of ones in the minterm ,for example the minterm 0100101 has a weight of 3. We must only unify minterms of a weight difference of one. The result of unify 2 minterms of different weight is to replace the (if only one) differents bits by 'x , example: (0 1 0 1) and (0 0 0 1) are unified with result of : (0 x 0 1) if there is more than 2 differents bits ,giving more than 1 'x in the result it is false,also if minterms have different lengths. Recursively we can unify the results , example (0 x 0 1) and (0 x 1 1) are unified with result of (0 x x 1) ,etc... my initial function to do that was: (define (unify-two-minterms mt1 mt2) (function-map-with-escaping-by-kontinuation2 (macro-function-compare-2-bits-with-continuation) mt1 mt2)) but since i have problem with // speed up i try other procedure: below you see the need of having to sort of escape ,'return from the current level in case of end of lists,and 'return-rec from the full stack of recursions in cas of #f result. (define (unify-two-minterms-rec mt1 mt2) {err <+ #f} (def (unify-two-lists-tolerant-one-mismatch mt1 mt2) (if {(null? mt1) and (null? mt2)} (return '())) (if {{(null? mt1) and (not (null? mt2))} or {(not (null? mt1)) and (null? mt2)}} (return-rec #f)) {fst-mt1 <+ (first mt1)} {fst-mt2 <+ (first mt2)} (if (equal? fst-mt1 fst-mt2) (return (cons fst-mt1 (unify-two-lists-tolerant-one-mismatch (rest mt1) (rest mt2))))) (if err (return-rec #f)) {err <- #t} (cons 'x (unify-two-lists-tolerant-one-mismatch (rest mt1) (rest mt2)))) (unify-two-lists-tolerant-one-mismatch mt1 mt2)) https://github.com/damien-mattei/library-FunctProg/blob/master/guile/logiki%2B.scm#L2805 scheme@(guile-user)> (unify-two-minterms-rec '(1 0 1 0 0 1 0 1 0 1) '(1 1 1 0 1 0 0 1 0 1)) $1 = #f scheme@(guile-user)> (unify-two-minterms-rec '(1 0 1 0 0 1 0 1 0 1) '(1 0 1 0 1 1 0 1 0 1)) $2 = (1 0 1 0 x 1 0 1 0 1) i have tested but still no speed up with 'futures, i have test it with Guile but the same problem is with Racket. Seems 'furure makes no speed up , it is hard to share the benchmarks now that i have updated the 'def of Scheme+ but i then i have to release a new version and update all the github and documentation online.Soon i hope... Damien On Thu, Nov 10, 2022 at 2:20 AM Olivier Dion wrote: > On Wed, 09 Nov 2022, Damien Mattei wrote: > > good... thank, it works, i do not know a lot about 'prompts , a good > > explanation is here: > > > > > https://stackoverflow.com/questions/29838344/what-exactly-is-a-continuation-prompt > > In the Guile manual: > > Top > API Reference > Control Mechanisms > Prompts > > or here >. > > -- > Olivier Dion > oldiob.dev >