Anonymous user
Search a list: Difference between revisions
→{{header|J}}: correction
m (Added to text proc cat) |
(→{{header|J}}: correction) |
||
Line 87:
J has a general and optimized lookup function, <tt>i.</tt>. For example:
H =: ;:'Zig Zag Ronald. Bush Krusty Wally Charlie Bush Bozo' NB. Haystack
N =: ;:'Washington Bush' NB. Needles
H i. N
Note that the arguments to <tt>i.</tt> can be '''anything''' (ie either or both may be scalars, lists, multidimensional arrays, etc).
To
H ;:^:_1@(]
Washington is not in haystack
3 Bush
To elaborate a bit: Array-oriented languages (like J) consume the input and produce the output ''in toto''.
Line 107:
And while it is both possible and simple to treat the input item by item, this is significantly slower and loses the great advantage of array processing.
Therefore these languages generally produce a special, but conforming, output for "bad" inputs (in this case,
In this case, there is only one function which formats and prints the results, and its treatment of "good" and "bad" outputs is identical (it cannot distinguish the two). It is simply that the outputs of previous functions have been arranged such that the results are conformable.
|