First time here? Check out the FAQ!
x

How can I turn an EventVariable into an array?

0 votes
373 views

For example:

{| YValues |
     YValues := EventVariable new size: 256.
     
     (!PenDown 
          true: ((YValues @< ((!PenX * 256) rounded)) <+ !y)
          false: (nil)).
     YValues asArray}

Gives me "error furing literal iteration".

From my understanding this is because the output is 256 iterations of the very same EventVariable. Allthough the EventVariable is in fact an array it seems I can't access it that way. Of course I could use something like

     YValuesArray := ((0 to: 256) collect: [ :i | (YValues @< i)]).
     
     YValuesArray asArray}

but I guess there must be a better way to do that?

Thanks! 

asked May 8, 2015 in Capytalk & Smalltalk by kymaguy (Virtuoso) (10,580 points)

1 Answer

0 votes

In the example PEN: Draw waveform w/Finger on Tablet, the YValues field accomplishes this by using a Smalltalk array of SampleAndHold expressions:

{| col |
    col := ((0 to: 30) collect: [ :i | (((!PenX - (i / 30)) abs lt: (1/30)) * !PenDown sampleAndHold: !y) * !PreScale]) asOrderedCollection.
    col addLast: col first.
    col asArray}

answered May 9, 2015 by ssc (Savant) (128,080 points)
Yes, I know but I wanted to rewrite that one to use an EventVariable. But I guess it's not possible to output the EventVariable as array?
Thanks for bringing that interesting code example to our attention SSC. I am not at Kyma now to do some experiments, but I am wondering if the OrderedCollection remains ordered even though the hotValues are changing?
...