@ and related operators (functions?) are only dimly understood by me. The explanation in the lfnoise/README page is terse, they don’t show up by `(function) help, and looking at the source code is, for me, not much help, either. There seems to be @@ @@@ … and @1 @2 … and functions that have @ buried in them, like each2. Can anybody help?
still learning sapf myself but @ seems like a way to pull a value out of the stack.
Thank you for your tries.
Besides the @ operator there are further derivatives @@, @@@… and @1, @2… which are tersely documented in the README files and sapf-prelude files. For example: Is @@ equivalent to @ @? What is the function of a number included: If you have @1 and @2 in an expression, what is the meaning? Where is the @ sign in the source code, anyhow? It seems like it gets consumed and affects the way the parser works in a not particularly transparent way, at least for me, who is a rank amateur at reading language parsers written in C++.
this is from the readme
Blockquote
THE “EACH” OPERATOR
Sometimes an operator needs to be applied at a deeper level than the top
level. The @ sign, known as the "each" operator, tags the top value on the
stack so that the next function that consumes it will operate over each of
its values instead of the list as a whole.
For example say we have the following nested list:
[[1 2 3] [4 5 6]]
If we reverse it we get the outer list reversed:
[[1 2 3] [4 5 6]] reverse --> [[4 5 6] [1 2 3]]
What if we want to reverse each of the inner lists? We use the each
operator:
[[1 2 3] [4 5 6]] @ reverse --> [[3 2 1] [6 5 4]]
Yes, the use of the single ‘@’ operator is well enough explained by the README file. I can infer even the use of the ‘@@, @@@…’ from this, though I don’t really know how much there are (perhaps infinity along this series). What @1, @2… do, is not really clear to me. What is the function of the number?
sapf-prelude.txt
has some hints. basically @1
…@n
let you apply a function of n
arguments to a cartesian product of n
lists.
first, a function to demonstrate @1
/@2
— it prints its two arguments and returns their product:
\a b [a pr " " pr b pr cr a b *] = test2
then we get:
sapf> [1 2] @1 [3 4 5] @2 test2
1 3
1 4
1 5
2 3
2 4
2 5
[[3 4 5] [6 8 10]]
sapf> clear
sapf> [1 2] @2 [3 4 5] @1 test2
1 3
2 3
1 4
2 4
1 5
2 5
[[3 6] [4 8] [5 10]]
it looks like the number arguments define the order in which the lists are iterated.