New compiler: variable and recursive bloc of code

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

New compiler: variable and recursive bloc of code

HilaireFernandes
Hello,

I noticed this change described bellow and I just want to have
confirmation about it:

The new Pharo 2.0 compiler need to have variable assigned with a value
before it used in a recursive bloc of code. Of course it is a bit
inelegant. Or is it something else and does it need to be reported?

Thanks to let me know

Hilaire

For example this Dr. Geo code break in Pharo 2.0:

| triangle c |
triangle := [:s1 :s2 :s3 :n |
     c segment: s1 to: s2;
         segment: s2 to: s3;
         segment: s3 to: s1.
     n > 0 ifTrue:
         [triangle
             value: s1
             value: (c middleOf: s1 and: s2) hide
             value: (c middleOf: s1 and: s3) hide
             value: n-1].
     [...]
].

It must be changed to:

| triangle c |
triangle := []. <= CHANGE HERE
triangle := [:s1 :s2 :s3 :n |
     c segment: s1 to: s2;
         segment: s2 to: s3;
         segment: s3 to: s1.
     n > 0 ifTrue:
         [triangle
             value: s1
             value: (c middleOf: s1 and: s2) hide
             value: (c middleOf: s1 and: s3) hide
             value: n-1].
     [...]
].



--
Dr. Geo - http://drgeo.eu
iStoa - http://istao.drgeo.eu


Reply | Threaded
Open this post in threaded view
|

Re: New compiler: variable and recursive bloc of code

Clément Béra
Hello,

The additional assignment is not needed. 

You get a warning because the warning detection is approximate and sometimes raises warning whereas it should not, but if you proceed, it compiles fine.

2014-09-10 8:54 GMT+02:00 Hilaire <[hidden email]>:
Hello,

I noticed this change described bellow and I just want to have confirmation about it:

The new Pharo 2.0 compiler need to have variable assigned with a value before it used in a recursive bloc of code. Of course it is a bit inelegant. Or is it something else and does it need to be reported?

Thanks to let me know

Hilaire

For example this Dr. Geo code break in Pharo 2.0:

| triangle c |
triangle := [:s1 :s2 :s3 :n |
    c segment: s1 to: s2;
        segment: s2 to: s3;
        segment: s3 to: s1.
    n > 0 ifTrue:
        [triangle
            value: s1
            value: (c middleOf: s1 and: s2) hide
            value: (c middleOf: s1 and: s3) hide
            value: n-1].
    [...]
].

It must be changed to:

| triangle c |
triangle := []. <= CHANGE HERE
triangle := [:s1 :s2 :s3 :n |
    c segment: s1 to: s2;
        segment: s2 to: s3;
        segment: s3 to: s1.
    n > 0 ifTrue:
        [triangle
            value: s1
            value: (c middleOf: s1 and: s2) hide
            value: (c middleOf: s1 and: s3) hide
            value: n-1].
    [...]
].



--
Dr. Geo - http://drgeo.eu
iStoa - http://istao.drgeo.eu



Reply | Threaded
Open this post in threaded view
|

Re: New compiler: variable and recursive bloc of code

HilaireFernandes
Ok, thanks

Le 10/09/2014 10:35, Clément Bera a écrit :
>
> The additional assignment is not needed.
>
> You get a warning because the warning detection is approximate and
> sometimes raises warning whereas it should not, but if you proceed, it
> compiles fine.


--
Dr. Geo - http://drgeo.eu
iStoa - http://istao.drgeo.eu