I have mixed feelings about extra/locals library. It is good to have
local named storage, but current design of extra/locals looks very
"lispish" (FP-style immutable variables). I think, there is a way to
make it closer to Factor stack-shuffling paradigm. So I have a
suggestion. What if we can use not local variables, but local
additional retain stacks, just like ">r" and "r>"? Let me show you
this concept on example from recent Slava's blog-post:
:: julian-day-number>date ( n -- year month day )
#! Inverse of julian-day-number
[let* | a [ n 32044 + ]
b [ 4 a * 3 + 146097 /i ]
c [ a 146097 b * 4 /i - ]
d [ 4 c * 3 + 1461 /i ]
e [ c 1461 d * 4 /i - ]
m [ 5 e * 2 + 153 /i ] |
100 b * d + 4800 -
m 10 /i + m 3 +
12 m 10 /i * -
e 153 m * 2 + 5 /i - 1+
] ;
This is how it looks with lisp-style locals. And here is my suggestion:
: julian-day-number>date ( n -- year month day )
#! Inverse of julian-day-number
[rest n a b c d e f | >n
n 32044 + >a
4 a * 3 + 146097 /i >b
a 146097 b * 4 /i - >c
4 c * 3 + 1461 /i >d
c 1461 d * 4 /i - >e
5 e * 2 + 153 /i >m
100 b * d + 4800 -
m 10 /i + m 3 +
12 m 10 /i * -
e 153 m * 2 + 5 /i - 1+
] ;
"[rest" - is fo REtain STacks. It creates additional local stacks with
accessors to them. Each stack ("x" for example) have three accessors.
Traditional ">x" and "x>" with semantics of ">r" and "r>". And
abbreviation "x" with semantics of "x> dup >x". At the end of "[rest
... ]" block remaining values on additional stacks are simply
dismissed. Looks good for me.
This raises major question. Is it possible to compile efficient code
with more than one retain stack?
Maxim Savchenko.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Register now and save $200. Hurry, offer ends at 11:59 p.m.,
Monday, April 7! Use priority code J8TLD2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk