unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@gmail.com>
To: Olivier Dion <olivier.dion@polymtl.ca>,
	Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: escaping from a recursive call
Date: Thu, 10 Nov 2022 06:25:55 +0100	[thread overview]
Message-ID: <CADEOadddn8DzbFENCA4nWDd91HjWrcqC4GKSNddABJqys3BqzA@mail.gmail.com> (raw)
In-Reply-To: <87v8nnoba8.fsf@laura>

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 <olivier.dion@polymtl.ca>
wrote:

> On Wed, 09 Nov 2022, Damien Mattei <damien.mattei@gmail.com> 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 <https://www.gnu.org/software/guile/manual/html_node/Prompts.html
> >.
>
> --
> Olivier Dion
> oldiob.dev
>


  parent reply	other threads:[~2022-11-10  5:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09 15:56 escaping from a recursive call Damien Mattei
2022-11-09 16:51 ` Olivier Dion via General Guile related discussions
2022-11-09 17:18   ` Damien Mattei
2022-11-09 17:55     ` Olivier Dion via General Guile related discussions
2022-11-09 18:49       ` Damien Mattei
2022-11-10  1:20         ` Olivier Dion via General Guile related discussions
2022-11-10  4:56           ` tomas
2022-11-10  6:01             ` Damien Mattei
2022-11-10  5:25           ` Damien Mattei [this message]
2022-11-10 17:03             ` Olivier Dion via General Guile related discussions
2022-11-10 12:32       ` Chris Vine
2022-11-10 13:48         ` Damien Mattei
2022-11-09 18:56     ` Zelphir Kaltstahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADEOadddn8DzbFENCA4nWDd91HjWrcqC4GKSNddABJqys3BqzA@mail.gmail.com \
    --to=damien.mattei@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=olivier.dion@polymtl.ca \
    --cc=zelphirkaltstahl@posteo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).