Quotations now a first-class type; conses removed
Thursday, May 18, 2006
I finished pushing a large set of patches to the main repository which implement the changeover I’ve been talking about for a while now.
What follows is a rundown of what has changed.
First of all, literals like [ 1 2 3 ]
are now instances of a
quotation
type. They implement the sequence protocol and behave much
like arrays. Any sequence can be converted to a quotation via
>quotation
. The difference between a quotation and an array is that
like the list-based “quotations” of old, these objects can be passed to
the call
and if
primitives which are the basic building blocks of
all higher order functions in Factor.
It used to be that f
and [ ]
both parsed to the same object; this is
now no longer the case. The object [ ]
is a length-zero quotation.
Parsing words will need to be changed. To begin a new nested parse
level, push f
not [ ]
. To add to the parse tree, use parsed
instead of swons
. The end result is a vector, not a list in reverse
order. Replace reverse
calls with >quotation
or similar. If this
terse description made no sense, it will be more detailed in the
documentation.
A lot of code did not use the list-specific words, but it used list
literals to hold data. Using [ ]
literals for non-code data is still
okay. I’d prefer if people used arrays { }
for that purpose, it just
makes the code a tiny bit more clear.