This problem is related to the problem I mentioned earlier in regard to
upgrading list.factor. I am now upgrading symtab.factor
(www.rosycrew.org/symtab.factor) and it won't compile. All of the functions
involved in finding a key in the tree fail, and all for the same reason
("unbalanced branches"). These are a couple of the functions that are
failing::
:: <find-key> ( root target -- node new-root | 0 )
... ;
: find-key ( key root -- node new-root | 0 )
dup 0 = [ nip ] [ swap <find-key> ] if ;
The vertical bar in the stack-frame means "OR." The idea is that the word
either returns two values (node and new-root) OR it returns one value (0).
This is pretty typical in Forth, and Factor is derived from Forth, so I
would hope for it to work here also.
In C the work-around is to return a pointer to a struct that contains the
two values (node and new-root), or to return a 0 (null pointer) in the event
that the key isn't found. This has to be done because C doesn't support
returning multiple values. Also, C is a strongly-typed language, so you
can't return a struct or a 0, because they are different types --- you can
only return a pointer to a struct or a 0, because the 0 is considered to be
a null pointer to any type. All of this is very kludgy though. I would
really want to avoid messing around with structs (or tuples) at all, and
just return the values on the stack, the way that I would do in Forth.
The problem in Factor seems to be related to returning a variable number of
values (two or one), rather than returning multiple values, which Factor
seems to be okay with.
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk