If I have a list, the first Operator and last Operator work nicely to retrieve whatever’s in first or last position…
But suppose I have a variable named position_in_list (say), what’s the simplest way to use it to retrieve the item listed in the corresponding numeric position in the list?
In other words, I want to return the fifth list item when the variable is 5, etc. In FileMaker Pro (my familiar background toolkit), there’s a Choose function which does that. Surely we have something similar?
(Related thought: it would be ideal if our documentation did things like lateral links among very similar Operators such as first and last and whatever it is that I’m seeking here.)
Although I doubt many folk would want documentation to work like this, here’s an example of how documentation can be organized in a TiddlyWiki instance: BASIC Anywhere Machine Programming Reference
These two filter operators are not always equivalent!
While nth[1] (or nth[]) and first[1] (or first[]) return the same results (the first item in the list), these filter operators return different results when the operand is greater than 1.
To illustrate, let’s suppose we have a list, A B C D E F.
As previously noted, [A B C D E F +[nth[1]] and [A B C D E F +[first[]] will both return “A”.
However…
[A B C D E F +[nth[3]] returns just “C”,
but [A B C D E F +[first[3]] returns “A B C”
To further confuse the issue, there is the zth[] operator, which works the same as the nth[] operator, but is “0 based” instead of “1 based”. Thus, zth[0] is equivalent to nth[1]. Note that both nth[0] and first[0] will return NO RESULT.
Finally, for completeness, I will also mention last[] and butlast[], as well as rest[] (and its synonyms, butfirst[] and bf[]).
{{{ [list[C Major Scale]nth[1]] [list[C Major Scale]nth[5]] [list[C Major Scale]nth[8]] +[join[ ]] }}}
Aside: isn’t a C Major chord CEG, and isn’t 1,5,8 a C5 (aka power) chord?
Regardless, put the generic version of the filter above in a $list widget, and you can get your equivalent chord in different tunings:
...
{{{ [list[D Major Scale]nth[1]] [list[D Major Scale]nth[5]] [list[D Major Scale]nth[8]] +[join[ ]] }}}
...
{{{ [list[G Major Scale]nth[1]] [list[G Major Scale]nth[5]] [list[G Major Scale]nth[8]] +[join[ ]] }}}
...
Back in my Seagull Merlin (aka “M4”) plucking days, I used to spend a lot of time transcribing guitar/ukulele tabs from whatever tuning to my Merlin’s DAdd tuning, or whatever other retuning I might have applied to my Merlin (CGcc, DGdd…).
So the ability to take any chord for one tuning and figure out the chord for some other tuning was a big deal that would have been helped by TiddlyWiki something silly.
Something pretty re widgets wrapped around something like
<!-- "ni", "nii", "niii" each being a note position in whatever major scale -->>
<<This Scale>> notes:<<ni>>, <<nii>>, <<niii>>
{{{ [list<This Scale>nth<ni>] [list<This Scale>nth<nii>] [list<This Scale>nth<niii>] +[join[ ]] }}}
<<That Scale>> notes: notes:<<ni>>, <<nii>>, <<nii>>
{{{ [list<That Scale>nth<ni>] [list<That Scale>nth<nii>] [list<That Scale>nth<niii>] +[join[ ]] }}}
I was critiqued once for using nth[1] instead of first. So I figured it must be some kind of unwritten best practice to use first instead of nth[1]. I didn’t agree (i.e. kept on using nth[1]), but I could not be bothered making the case for continuing with nth[1].
Glad I didn’t bother, because I wouldn’t have come anywhere near as good as that great explanation of nth vs first.