Login  Register

Re: I need some explaination about arguements assignment

Posted by S Krish on Aug 07, 2014; 3:25am
URL: https://forum.world.st/I-need-some-explaination-about-arguements-assignment-tp4772102p4772103.html


I am quite at loss to really understand the purpose of the code written...if you can show in some manner what are you trying to achieve some pointers can be given in the correct direction. As is I presume the code will need to rewritten completely..


On Thu, Aug 7, 2014 at 8:43 AM, aria2end <[hidden email]> wrote:
Hello, I am new to smalltalk and I would really appreciate your help so I can
better use and understand Pharo.

So here is the problem, I wanted to implement a function to get the value of
my tree struct nodes in a recursive manner and I wanted to concatenate them
to a String ( aText ) and later show them on the Transcript.


showLists
        | aText |
         aText  :=  lol level,  (String with: Character cr).
        self recursiveShowLists: lol withText: aText tabsNumber: 1.




recursiveShowLists: aLoL withText: aText tabsNumber: aNumb
        | counter index |
        aLoL lols isEmpty
                ifFalse: [
                        counter := 1.
                        [ counter <= aNumb ]
                                whileTrue: [
                                        aText := aText , (String with:
Character tab).
                                        counter := counter + 1 ].
                        index := 1.
                        aNumb := aNumb + 1.
                        LoL lols do: [ :each | aText := aText , each level ,
(String with: Character cr) ].
                        ]



Without having the last line ( LoL lols do: ... ) everything works fine but
when I include it and as soon as debugger reaches to [counter <= aNumb ] and
wants to evaluate it, my arguments start to act weird. aText will become nil
and aNumb will hold te value of aText!


I fixed this issue by adding another temporary variable ( copyText ) and
instead of direct assignment of aText I used the copyText:



recursiveShowLists: aLoL withText: aText tabsNumber: aNumb
        | counter index copyText |
        copyText := aText.
        aLoL lols isEmpty
                ifFalse: [
                        counter := 1.
                        [ counter <= aNumb ]
                                whileTrue: [
                                        copyText := copyText , (String with:
Character tab).
                                        counter := counter + 1 ].
                        index := 1.
                        aLoL lols do: [ :each | copyText := copyText , each
level , (String with: Character cr) ] ]



I really like to know the reason behind this issue,  I appreciate all the
explanations.
Thanks,
Aria




--
View this message in context: http://forum.world.st/I-need-some-explaination-about-arguements-assignment-tp4772102.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.