First time here? Check out the FAQ!
x

Whats the difference between <@ and of: #()

0 votes
545 views
I was pondering the usage of

anArrayEventVariable @< anEventExpression

what would be the difference between looking up an EventVariable using of:

anEventExpression of: #( {anEventVariable} {anEventVariable} {anEventVariable}..... )
asked Aug 6, 2018 in Capytalk & Smalltalk by cristian-vogel (Master) (8,410 points)
Cristian, I'm having difficulty understanding this. Is there a missing 'or' or perhaps an omitted comparison after the word 'between'?
Well, the way I have always looked up hotValues in an array is using the

` of: `  CapyTalk.

So,

!Index of: #( !sw01 !sw02 !sw03 !sw04 )

When !Index is set to 0, the expression evaluates to be the hotValue !sw01
When !Index is set to 1, the expression evaluates to be the hotValue !sw02

I'm reading in the CapyTalk help about <@

Carla writes:

``` Access an entry in an array EventVariable.

Read the nth entry in an array variable with anArray @< !n. Set the nth to !aValue using (anArray @< !n) <+ !aValue. Use 0-based indexing (the first entry in the array is at location 0, not at location 1).
```

I am trying to get my head around the different ways of working with CapyTalk arrays
I can see how my topic question doesn't make sense in plain English!
Hi Alan. It seems the advantage is to be able to swap elements out of an EventVariableArray which you can't do with a normal array of hotValues.
ahh, yes of course. The whole EventVariable Array is assignable at runtime. Cool. I've learnt heaps this morning.

2 Answers

0 votes
 
Best answer

Hi Alan & Cristian, yes you're right about the difference between the two constructs:

of: is for accessing an element of a Smalltalk Array with an EventValue index

<@ is for accessing an element of a Capytalk Array with an EventValue index

The Smalltalk Array can contain any EventExpressions, for example:

!Index of: #(2 6 2 9)

!Index of: #(!Interval7 !Interval6 {!Interval5 + !Interval3} !Interval4)

In most situations, you can use Smalltalk to construct the Array (during the compile step) and of: to random access an element of the Array while the Sound is running.

It's rare that you would need to use Capytalk arrays. The only time you would need a Capytalk Array and the <@ accessor is, as Alan pointed out, when you need to programmatically write the contents of the Array while the Sound is running.

To summarize:

of: returns the value of a Smalltalk array using the receiver's value as the index into the (0-based) array

<@ returns a reference that you can use to either read or write to a Capytalk (0-based) array where the index is the argument and the receiver is the Capytalk array.

 

 

 

answered Aug 6, 2018 by ssc (Savant) (126,300 points)
selected Aug 7, 2018 by cristian-vogel
So for example;

There's a rather clever hardware sequencer out there called the Cirklon which has loads of cool features that I'd like to try and emulate.

One of them is that user can 'skip' any number number elements from a row, effectively shortening the Array that is being iterated. Is this something I could try and do with the <@ ?
Hmmm...

You could set the item in the array to a "zero" value then have different behaviour on that step, like spend no time on that step in a sequence. Then you don't have to resize the array.

But if you wanted to literally resize the array, you could have one array of VCS controls to enable and disable steps. If any of those change that could trigger rebuilding the sequencer steps array. Go through the steps and for each enabled step add that to an OrderedCollection. Then iterate over the OrderedCollection to rebuild the final steps array at the new size...?

The Doepfer DarkTime also has skip switches for each of its steps in a sequence. Being an analog hardware sequencer it takes the first approach. It's always got a row of 8 knobs so it can't shorten the array, it just spends no time on a skipped step.
0 votes

I don't know if this helps....

I just had a play with this. Here's a bit script using  "@<"

| eventVariableArray |

eventVariableArray := EventVariable new size: 8.
eventVariableArray @< 1.

this evaluates fine and returns something like:

 (Var30560 @< 1 )

 

But trying the following doesn't work:

| eventVariableArray |

eventVariableArray := EventVariable new size: 8.
1 of: eventVariableArray.

gives an error:

"Error: The Value 2 was used to index Var59487, an instance of class EventVariable. This index was out of bounds for this object."

What that suggest to me is that you use "of:" to index into a "normal" array. But that when you create an EventVariable "Array", it's not a normal array, it's some other kind of special object, which uses the @< operator to index into it. 

Ok maybe that much was obvious. So I suppose the question is what's the advantage using one of these special EventVariable "Array" data structures as opposed to a normal array of EventVariables?

EventVariables are CapyTalk variables so evaluate at run time and are a good way of saving state of !HotValues. I suppose you could use an EventVariable "Array" to store a time series of previous values of an EventExpression (!HotValue etc.).

(I think an array of EventVariables would let you do the same thing, because each individual EventVariable in the array would be able to save state, but constructing an array of EventVariables would be more tedious.)

 

 

 

answered Aug 6, 2018 by alan-jackson (Virtuoso) (15,840 points)
edited Aug 6, 2018 by alan-jackson
Why don't !EventVariables in an !EventVariable array show up on the VCS?
...