block in recursion, Any cure for that kind of situation?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

block in recursion, Any cure for that kind of situation?

Hilaire Fernandes-4
I got an error "Attempt to evaluate a block that is already being
evaluated", when I call in recursion a block like

carre := [:s1 :s2 :s3 :s4 :n |
        n >0 ifTrue:
                [carre valueWithArguments:  {(segment value: s1 value: s2).
                         (segment value: s2 value: s3).
                         (segment value: s3 value: s4).
                         (segment value: s1 value: s4).
                         n-1}]]

Hilaire

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Marcin Tustin
You could add an extra parameter that is another block. Use that parameter as the value of carre in the block. something like:

f := [:a :ff | a ifTrue: [ff (a not) ff] ]
ff: = [:a :ff | a ifTrue: [ff (a not) ff] ]

On Jan 22, 2008 9:10 PM, Hilaire Fernandes <[hidden email]> wrote:
I got an error "Attempt to evaluate a block that is already being
evaluated", when I call in recursion a block like

carre := [:s1 :s2 :s3 :s4 :n |
       n >0 ifTrue:
               [carre valueWithArguments:  {(segment value: s1 value: s2).
                        (segment value: s2 value: s3).
                        (segment value: s3 value: s4).
                        (segment value: s1 value: s4).
                        n-1}]]

Hilaire

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Marcin Tustin
For the avoidance of confusion, here is a version with non-guessed syntax:

f := [:a :ff | a ifTrue: [{a . (ff value: (a not) value: ff)}] ifFalse: a].
g := [:a :ff | a ifTrue: [{a . (ff value: (a not) value: ff)}] ifFalse: a].
f value: true value: g.

On Jan 22, 2008 9:35 PM, Marcin Tustin <[hidden email]> wrote:
You could add an extra parameter that is another block. Use that parameter as the value of carre in the block. something like:

f := [:a :ff | a ifTrue: [ff (a not) ff] ]
ff: = [:a :ff | a ifTrue: [ff (a not) ff] ]


On Jan 22, 2008 9:10 PM, Hilaire Fernandes <[hidden email]> wrote:
I got an error "Attempt to evaluate a block that is already being
evaluated", when I call in recursion a block like

carre := [:s1 :s2 :s3 :s4 :n |
       n >0 ifTrue:
               [carre valueWithArguments:  {(segment value: s1 value: s2).
                        (segment value: s2 value: s3).
                        (segment value: s3 value: s4).
                        (segment value: s1 value: s4).
                        n-1}]]

Hilaire

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Marcin Tustin
I'm an idiot. That doesn't work either. Why not?

On Jan 22, 2008 10:12 PM, Marcin Tustin <[hidden email]> wrote:
For the avoidance of confusion, here is a version with non-guessed syntax:

f := [:a :ff | a ifTrue: [{a . (ff value: (a not) value: ff)}] ifFalse: a].
g := [:a :ff | a ifTrue: [{a . (ff value: (a not) value: ff)}] ifFalse: a].
f value: true value: g.


On Jan 22, 2008 9:35 PM, Marcin Tustin <[hidden email]> wrote:
You could add an extra parameter that is another block. Use that parameter as the value of carre in the block. something like:

f := [:a :ff | a ifTrue: [ff (a not) ff] ]
ff: = [:a :ff | a ifTrue: [ff (a not) ff] ]


On Jan 22, 2008 9:10 PM, Hilaire Fernandes <[hidden email]> wrote:
I got an error "Attempt to evaluate a block that is already being
evaluated", when I call in recursion a block like

carre := [:s1 :s2 :s3 :s4 :n |
       n >0 ifTrue:
               [carre valueWithArguments:  {(segment value: s1 value: s2).
                        (segment value: s2 value: s3).
                        (segment value: s3 value: s4).
                        (segment value: s1 value: s4).
                        n-1}]]

Hilaire

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Randal L. Schwartz
In reply to this post by Hilaire Fernandes-4
>>>>> "Hilaire" == Hilaire Fernandes <[hidden email]> writes:

Hilaire> I got an error "Attempt to evaluate a block that is already being evaluated",
Hilaire> when I call in recursion a block like

Hilaire> carre := [:s1 :s2 :s3 :s4 :n |
Hilaire> n >0 ifTrue:
Hilaire> [carre valueWithArguments:  {(segment value: s1 value: s2).
Hilaire> (segment value: s2 value: s3).
Hilaire> (segment value: s3 value: s4).
Hilaire> (segment value: s1 value: s4).
Hilaire> n-1}]]

This is a maintenance nightmare waiting to happen.  Use a proper method call,
perhaps creating a "manager" class to manage the workflow, and so you don't
have to keep passing segment around.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Michael Davies-2
In reply to this post by Hilaire Fernandes-4
On Jan 22, 2008 9:10 PM, Hilaire Fernandes <[hidden email]> wrote:
> I got an error "Attempt to evaluate a block that is already being
> evaluated", when I call in recursion a block...
<snip>

This is a know limitation of Squeak, eg see discussion around
http://lists.squeakfoundation.org/pipermail/squeak-dev/2007-December/123421.html

Cheers,
Michael

(re-sent as my original seems to have wandered off course)
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Ben Goetter
In reply to this post by Randal L. Schwartz
>This is a maintenance nightmare waiting to happen.  Use a proper method call,

Squeak Smalltalk blocks are just similar enough to Scheme lambdas that I still fall into this trap, too.

(letrec ((carre (lambda (s1 s2 s3 s4 n)
                 (if (> n 0)
                  (carre (segment s1 s2)
                         (segment s2 s3)
                         (segment s3 s4)
                         (segment s1 s4)
                         (- n 1))))))
 'oops-must-remember-this-is-Squeak-not-Scheme)

Ben
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Marcin Tustin
So am I right in thinking that if I get newCompiler, blocks will work as I would expect them to (like lambdas)?

If so, how do I get the most recent version? I remember there being something that has superceded squeakmap, but I can't seem to find it.

On Jan 22, 2008 11:42 PM, Ben Goetter <[hidden email]> wrote:
>This is a maintenance nightmare waiting to happen.  Use a proper method call,

Squeak Smalltalk blocks are just similar enough to Scheme lambdas that I still fall into this trap, too.

(letrec ((carre (lambda (s1 s2 s3 s4 n)
                (if (> n 0)
                 (carre (segment s1 s2)
                        (segment s2 s3)
                        (segment s3 s4)
                        (segment s1 s4)
                        (- n 1))))))
 'oops-must-remember-this-is-Squeak-not-Scheme)

Ben
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Marcin Tustin
I figured it out - I meant monticello + squeaksource.

Having loaded newcompiler, ast, blockchecker, and newcompilerloader, it doesn't seem to have made a difference.

On Jan 23, 2008 12:00 AM, Marcin Tustin < [hidden email]> wrote:
So am I right in thinking that if I get newCompiler, blocks will work as I would expect them to (like lambdas)?

If so, how do I get the most recent version? I remember there being something that has superceded squeakmap, but I can't seem to find it.


On Jan 22, 2008 11:42 PM, Ben Goetter <[hidden email]> wrote:
>This is a maintenance nightmare waiting to happen.  Use a proper method call,

Squeak Smalltalk blocks are just similar enough to Scheme lambdas that I still fall into this trap, too.

(letrec ((carre (lambda (s1 s2 s3 s4 n)
                (if (> n 0)
                 (carre (segment s1 s2)
                        (segment s2 s3)
                        (segment s3 s4)
                        (segment s1 s4)
                        (- n 1))))))
 'oops-must-remember-this-is-Squeak-not-Scheme)

Ben
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Mathieu SUEN
In reply to this post by Marcin Tustin
On Jan 23, 2008, at 1:00 AM, Marcin Tustin wrote:

> So am I right in thinking that if I get newCompiler, blocks will  
> work as I would expect them to (like lambdas)?
>
> If so, how do I get the most recent version? I remember there being  
> something that has superceded squeakmap, but I can't seem to find it.

You can find it on squeaksource.
http://www.squeaksource.com/NewCompiler.html

You first need to load AST NewParser RefactoringEgine and SmaccRuntime.
In other to load them all you could use the NewCompilerLoader  
availible one the NewCompiler squeaksource repository.
Simply invoke:
NewCompilerLoader new loadPackage.

This will recompile the complete image using the NewCompiler.

To avoid the recompilation you can look at the loadPackage method.
You could also load the NewCompiler throw the Universe browser.

After loading the compiler you have 2 way to compile code.

1. Use the NewCompiler but don't make full block closure. (Preference  
browser section compile #compileUseNewCompiler)
       
        In this mode the block still remain the same and temp are share
  among the home context. That the reason why you could not invoke
        recursively a block.

2. Enable the block closure. (Preference browser section compile  
#compileBlocksAsClosures)

        With this preference the block while be transform in full block  
closure. You could then recursively
        invoke a block. Block while then create a environment  to store temps  
whenever is needed.


HTH
Cheers,


>
>
> On Jan 22, 2008 11:42 PM, Ben Goetter <[hidden email]> wrote:
> >This is a maintenance nightmare waiting to happen.  Use a proper  
> method call,
>
> Squeak Smalltalk blocks are just similar enough to Scheme lambdas  
> that I still fall into this trap, too.
>
> (letrec ((carre (lambda (s1 s2 s3 s4 n)
>                 (if (> n 0)
>                  (carre (segment s1 s2)
>                         (segment s2 s3)
>                         (segment s3 s4)
>                         (segment s1 s4)
>                         (- n 1))))))
>  'oops-must-remember-this-is-Squeak-not-Scheme)
>
> Ben
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

        Mth



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Hilaire Fernandes-4
In reply to this post by Marcin Tustin

Le mardi 22 janvier 2008 à 22:16 +0000, Marcin Tustin a écrit :
> I'm an idiot. That doesn't work either. Why not?

Because still nested, I guess.
Anyway I want to use that for teacher to design programmaticaly
interactige geometry figure for Drgeo. So it have to keep simple and be
usable in a Workspace.
The only alternative I see is to define a class with methods, but it is
a bit more complex for the target audiance.

Hilaire


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Hilaire Fernandes-4
In reply to this post by Ben Goetter
Indeed, and I am adapting from DrGeo1.1 which embede the Guile Scheme
interpretor, see
http://documentation.ofset.org/drgeo/fr/drgenius_93.html

Hilaire

Le mardi 22 janvier 2008 à 15:42 -0800, Ben Goetter a écrit :

> >This is a maintenance nightmare waiting to happen.  Use a proper method call,
>
> Squeak Smalltalk blocks are just similar enough to Scheme lambdas that I still fall into this trap, too.
>
> (letrec ((carre (lambda (s1 s2 s3 s4 n)
>                  (if (> n 0)
>                   (carre (segment s1 s2)
>                          (segment s2 s3)
>                          (segment s3 s4)
>                          (segment s1 s4)
>                          (- n 1))))))
>  'oops-must-remember-this-is-Squeak-not-Scheme)
>
> Ben

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Klaus D. Witzel
In reply to this post by Hilaire Fernandes-4
Hi Hilaire,

on Wed, 23 Jan 2008 09:49:07 +0100, you wrote:

>
> Le mardi 22 janvier 2008 à 22:16 +0000, Marcin Tustin a écrit :
>> I'm an idiot. That doesn't work either. Why not?
>
> Because still nested, I guess.
> Anyway I want to use that for teacher to design programmaticaly
> interactige geometry figure for Drgeo. So it have to keep simple and be
> usable in a Workspace.
>
> The only alternative I see is to define a class with methods, but it is
> a bit more complex for the target audiance.

You don't have to. I use recursive blocks in Smalltalk workspace all the  
time. The "trick" is from the Self language, which always clones  
activation record before using them. Example:

  recursiveBlock := [:argV |
    argV < 1
     ifFalse: [argV + (recursiveBlock clone value: argV - 1)]
     ifTrue: [argV]].

  recursiveBlock clone value: 17

You could send #copy instead of #clone but I prefer the latter in honor of  
Self.

Enjoy!

/Klaus

P.S. beware of the #fixTemps symptom in Squeak's implementation of blocks,  
was discussed several times over in squeak-dev.

> Hilaire
>


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Hilaire Fernandes-4
Hi Klaus,

Thanks for the tip, I also need the fixTemps. It is not very elegant but
it works. See the vidéo: http://squeak.ofset.org/drgeo/spiral.ogg



Klaus D. Witzel a écrit :
> Hi Hilaire,
>

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: block in recursion, Any cure for that kind of situation?

Klaus D. Witzel
On Wed, 23 Jan 2008 18:52:51 +0100, Hilaire Fernandes wrote:

> Hi Klaus,
>
> Thanks for the tip, I also need the fixTemps. It is not very elegant but  
> it works. See the vidéo: http://squeak.ofset.org/drgeo/spiral.ogg
>

Hey, what a nice return for a double clone :-)

>
> Klaus D. Witzel a écrit :
>> Hi Hilaire,
>>


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners