[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: escaping from a recursive call

From: Damien Mattei
Subject: Re: escaping from a recursive call
Date: Thu, 10 Nov 2022 06:25:55 +0100

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)
 (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))

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...


On Thu, Nov 10, 2022 at 2:20 AM Olivier Dion <>

> 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:
> >
> >
> In the Guile manual:
> Top > API Reference > Control Mechanisms > Prompts
> or here <
> >.
> --
> Olivier Dion

reply via email to

[Prev in Thread] Current Thread [Next in Thread]