« Sequences! | Main | renaissance period »
November 28, 2004
[inp]ossible things in sequences
I've discovered that it is impossible to have control over the contents of a sequence from outside the sequence without using variable names. One may want something similar to inp, but for sequences. The design of CX doesn't allow this.
I cannot think of a time when a user would have to do it, but if you have a sequence without any lists, and want to use that sequence in an applicative way, you can only use a plain variable (not inp). To understand this fact, one must understand how and when inp is used.
inp is a special word that is only to be used in lists. CX has applicative lists, and inp is the symbol for placement of the argument. Lists are made with square brackets, and if the word inp is found inside the brackets, the evaluation of the next word is moved into the place of the inp. Here are some examples of ways to use inp:
[ inp inp ] 3 => [ 3 3 ]
[inp inp] [inp] 3 => [ [3] [3] [3] ]
+[2 inp] 5 => 7
Outside of lists, inp cannot be used. If a sequence does not use a list, no inp is allowed in the sequence either, because using the word that points to a sequence is just like typing out the sequence itself. Therefore we cannot have applicative sequences. At most, we can have a sequence of words where the next word after the sequence itself will be used:
set["twice" unquote {*[2 inp]}] (standard 'twice' function)
set["twiceAlias" unquote {twice}]
twiceAlias 3 => 6
Of all of the programming I've done in CX, I've never come across this, but I did notice it in an irc conversation , where I accidentally used inp at the top level, inside a sequence. This gives sequences the feeling of word definitions in concatenative langauges. A person might be writing functions too big if this problem is hit. Consider factoring. At the same time, just becuase I haven't found a case where one would have to do such a thing doesn't mean I shouldn't think of a more efficient way to deal with it than variables.
Please comment. Btw, the title of this article evaluates to
[ ossible ] things in sequences
Remember: inp must be in a list.
Posted by Rex at November 28, 2004 01:13 AM
Comments
I just noticed one option: one may use a quote instead of a sequence, if this set of code wants to use inp. I could then make eval take a 2-node list, one node being the quote , second being the input to the quote:
set["x" { twice inp }]
eval[x 3] => 6
Muwhahaha. If no one finds a better way, I'm resorting to this, but either eval will accept both lists and quotes or there will be an evalInp for the applicative calling of quotes. The goal is not to have inconsistancy in the syntax.
Posted by: Rex at November 28, 2004 02:06 AM