Hi list, playing with literals, I think we need to clarify the documentation and maybe change the code.
------------------------- 1) The following commit changed the $ word: commit ddce0e0a107ffdb295b02363c553d562641b72b9 Author: Joe Groff <[email protected]> Date: Wed Feb 18 16:57:20 2009 -0600 change literals so that $ works with constants in same compilation unit As far as I understand, this makes any word previously defined in the same compilation unit work with $. But the docs were not updated to reflect this change. Now $, ${ and flags{ amm use "def>> call" to work with previous words in the same compilation unit. But the docs still say that all these words can't be used this way. Can someone confirm this so we can change the docs ? ------------------------- 2) "${" only works with words that have 0 inputs (they can have any number of outputs) and this is not explained in the docs. "flags{" has the same restriction, but the documentation is a bit better, although not very explicit. The following change makes ${ and flags{ work with any word. I don't know wheter we want to update the docs, or change the behavior of "${" and "flags{". diff --git a/basis/literals/literals.factor b/basis/literals/literals.factor index 42a7ab9..ede0fba 100644 --- a/basis/literals/literals.factor +++ b/basis/literals/literals.factor @@ -17,7 +17,7 @@ IN: literals ] with-datastack ; : expand-literals ( seq -- seq' ) - [ [ { } ] dip expand-literal ] map concat ; + { } [ expand-literal ] reduce ; PRIVATE> ------------------------- Finally, I find the litterals has the following limitation: $[ doesn't use "def>> call", so it does not work with previously defined words. This makes defining constants based on previous constants in the same file impossible. The following change seem to make it work. It calls with-datastack n times instead of just 1, but I don't think this would make a big difference in compilation times.. Bootstrap time is not increased. diff --git a/basis/literals/literals.factor b/basis/literals/literals.factor index ede0fba..302c34b 100644 --- a/basis/literals/literals.factor +++ b/basis/literals/literals.factor @@ -22,7 +22,7 @@ IN: literals PRIVATE> SYNTAX: $ scan-word expand-literal >vector ; -SYNTAX: $[ parse-quotation with-datastack >vector ; +SYNTAX: $[ parse-quotation swap [ expand-literal ] reduce >vector ; SYNTAX: ${ \ } [ expand-literals ] parse-literal ; SYNTAX: flags{ \ } [ What do you think ? Jon ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Factor-talk mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/factor-talk
