3 ms·
Somewhat related, but I wish that more languages provided a reserved convenience variable for accessing the result of the previous function call: https://stack
by zackmorris 7y ago
Somewhat related, but I wish that more languages provided a reserved convenience variable for accessing the result of the previous function call:
https://stackoverflow.com/questions/3326826/language-history-origin-of-variable-it-in-read-eval-print-loop/3342195 https://stackoverflow.com/questions/3326826/language-history...
Python and Ruby: _
Shell: $?
HyperTalk: it (my first exposure to the concept, even though it was more of a convention)
Some Lisps: *, **, ***, ...
If we had that, then we could write:
func1();
func2(_);
func3(_);
...
Which reminds me of PostScript, which lets you examine and manipulate the program's stack directly (the top of the stack is the previous result):
http://www.ugrad.math.ubc.ca/Flat/intro.html http://www.ugrad.math.ubc.ca/Flat/intro.html
http://www.ugrad.math.ubc.ca/Flat/stack.html http://www.ugrad.math.ubc.ca/Flat/stack.html
If I were implementing it, I would make the previous result and stack contents read-only so that it's conceptually the same as the pipeline operator except that it allows inspecting the intermediate value.
- vmchale 7y agoGets confusing in a multithreaded context. Or if you return pointers.
- smabie 7y agoI really like k/q’s right to left parsing. something like: f(g(h(x))) Becomes f g h x Which I find very natural and better than x h g f Like in a stack language.
- vthriller 7y ago> f(g(h(x))) Haskell has $ operator (simple application operator but with low precedence—think open bracket that closes implicitly at the end of expression). While it makes your example a bit more verbose: > f $ g $ h x it also allows one to pass multiple arguments in an intermediate function call, e.g. > f $ g x $ h y is the same in Haskell as > f (g x (h y)) which in most languages would be > f(g(x, h(y))
- dunefox 7y agoHaskell also allows point free style: (f . g . h) x
- dragonwriter 7y agoThe Stackoverflow thing you cite is wrong: Ruby doesn't _ that way (IRB, the bundled Ruby REPL, does)—Ruby actually does have special handling for _ as a variable, but that's to suppress duplicate definitions n warnings to allow it to be used as a don't-care argument. I think Python is similar, where it is special-cased in the REPL, not a general language feature.