Arrays in revTalk are basically Maps - each 'key' points to a 'value'. So if you do:
Code: Select all
put 1 into tArray["foo"]
put "smurf" into tArray["bar"]
you'll have two items in your array, and key "foo" will point to value 1, and key "bar" will point to value "smurf".
There's no need to declare the array or initiate it to a certain size; it's all done transparently for you.
Since version 3.0, we gained the ability to nest arrays in another array. So you can do things like:
Code: Select all
put 1 into tArray[1]["foo"]
put "smurf" into tArray[1]["bar"]
put 99 into tArray[2]["foo"]
and you'll have an array where the key "1" points to another array, where the key "foo" points to value 1 and key "bar" points to value "smurf"; and in the outer array, the key "2" points to another array, where the key "foo" points to value 99.
Now you can also copy nested arrays as a whole:
and now you have an additional key "3" in your outer array, with a copy of the nested array that was in key "1" - no need to copythe individual items of the nested array.
You can also delete items from the array:
will erase the entire content of the key "2" of your outer array, and this will automatically delete the nested array. No need to 'free' the individual nested items yourself, no chance of memory leaks.
This system is extremely flexible, but takes a little getting used to.
Back to the code snippet in the User Guide.
The
repeat for each <chunktype> <chunkVariable> in <container>loop is a very powerful construct in the revTalk language, as it efficiently goes through the entire container variable, and copies the appropriate chunks into the chunkVariable, one at a time.
So what the code snippet does, is go through the text in field "sample text", and copies each word into the variable tword, running the script inside the repeat loop. As explained above, you don't need to allocate the memory, and new items are automatically added to the tWordcount array.
Also, one of the interesting aspects of how the revEngine works, is that if a variable is empty, and you add 1 to it, the assumption is that the variable was supposed to contain 0 and so you get 1 after the addition; the next time around it has 1 so adding 1 means the array item now has value 2.
Assuming we have a text like this:
Code: Select all
revTalk is fast and easy and it is simply amazing
then at the end of the repeat loop, the array tWordcount will look something like this:
- tWordcount["revTalk"] = 1
- tWordcount["is"] = 2
- tWordcount["fast"] = 1
- tWordcount["and"] = 2
- tWordcount["easy"] = 1
- tWordcount["it"] = 1
- tWordcount["simply"] = 1
- tWordcount["amazing"] = 1
The exact order of items in the array is undefined (or rather, it is defined on the basis of the hash-value of the key, but that's another story entirely), and that's why you may be a tad confused at what happens at the
combine command.
What it does, is go through eack key, and then concatenate its value, putting a comma between the key and the value of the item, and a return in between two items. So you'll end up with a single string something like:
Code: Select all
revTalk,1
is,2
fast,1
and,2
easy,1
it,1
simply,1
amazing,1
I typed it up in the order that made most sense, but it's going to be in a different order. So you may want to
sort the lines in a way that makes more sense.
For instance, if you want to sort it in reverse alphabetical order on the words, you could use:
Code: Select all
sort lines of tWordcount descending by item 1 of each
and then the variable's lines will be sorted that way.
If you want to see the lines in the order of the number of times they appeared in the container variable, you could use:
Code: Select all
sort lines of twordcount numeric descending by item 2 of each
and then the most used words bubble to the top of the text string.
HTH,
Jan Schenkel.