Login  Register

Re: I need some explaination about arguements assignment

Posted by HilaireFernandes on Aug 07, 2014; 4:17am
URL: https://forum.world.st/I-need-some-explaination-about-arguements-assignment-tp4772102p4772107.html

You should first take time to improve the readability of your code, do
not forget it is your own food.

What about starting something like (no idea what you want to do however):

recursiveShowLists: aLoL withText: aText tabsNumber: aNumb
| counter index copyText |
copyText := aText.
aLoL lols ifEmpty: [^self].

aNumb timesRepeat: [copyText := copyText, (String with: Character tab)].
index := 1.
aLoL lols do: [ :each |
    copyText := copyText, each level, (String with: Character cr) ] ]

Hilaire

Le 07/08/2014 11:13, aria2end a écrit :

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


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