|A variable 'that, 'prev, 'last, or whatever, that holds the value of the last expression. For example:|
Would be equivalent to:
3 (+ 2 that)
I'm not saying that's how it has to be implemented, but that it would be semantically equivalent to that.
(= that 3)
(= that (+ 2 that))
Generally, I think this would simplify expressions by allowing them to be written in a one-two punch style. For example, in places where you have one complex expression with another complex expression inside it; or where you need to use an expression, simple or complex, in multiple places. From the news.arc code:
This would become:
(let i (load-item id)
(push i (items i!type)))
Using this as a replacement for 'let in multi-form blocks would require 'do:
(push that (items that!type))
This would be:
(let a 'hi
At first it seemed to me that requiring 'do with this method was missing the point, but I think it is actually simpler because the variable 'a is gone. 'that is a lot more implicit.
(do (pr that)
In similar fashion to how values are returned from functions:
We could use likewise in this way:
; some stuff that manipulates x
It occured to me that even with 'do, it wouldn't work because (pr that) would assign a new value to 'that. Funnily, a value which would have made this example seem to work. Questions of scoping handoff also pop up here. Perhaps 'those could be a hash, where those.0 would be 'that in the current scope, those.1 would be 'that in the outer scope, and so on:
(do (pr that)
Not to pull at straws, but to provide heuristics.
(do (pr those.1)
Also, I'm not saying we should get rid of let, just that this mechanism would be nice. I was surprised when searching through the news.arc code that the vast majority of lets only had one inner code block. There were maybe a handful that were multi-form.
It seems to me that let was mostly used to simplify code, rather than to declare local variables. Noob programmers might not be inclined to doing that, but some encouragement wouldn't be bad.
I was thinking something like a variable 'prev that held the value of the last iteration:
-- In Iterations --
Which would be equivalent to:
[map (fn (x) (+ x prev) ) _]
But it seems clunky to me. However, 'that would be nil/undefined at the beginning of the function, so to give it some usefulness in the first line it could be given the value of the last iteration at that point. Or it could be given the value of 'that in the calling scope, or perhaps the continuation of the calling point or something.
[reduce (fn (prev x) (+ x prev)) _]
I don't really know how this would be implemented, other than it would probably need to be deep in the core for efficiency.
-- Implementation --