Hello,
One of the onions in Factor world (to me anyway) has been the dilemma of
finding the "one true effect". Even when you find the supposed "one true
effect", there are still exceptional cases which require an accompanying
shuffle word.
Another dilemma has been finding a "grand unified theory of stack effects"; a
sort of philosophy behind the effects which would inform the design of future
words.
I'm going a different route, embracing the diversity of effects instead of
rejecting it. The way down this route is to give names to each variant.
The following generic words work on sequences and tables (assocs):
----------------------------------------------------------------------
GENERIC: at ( col key -- val )
GENERIC: of ( key col -- val )
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
GENERIC: grab ( col key -- col val )
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
GENERIC: is ( col key val -- col )
GENERIC: as ( col val key -- col ) ! "Store value as key"
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
GENERIC: is-of ( key val col -- col ) ! "Key is value of this collection"
GENERIC: as-of ( val key col -- col ) ! "Store val as key of this collection"
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
GENERIC: mutate-at ( col key val -- ) ! Mutate collection at key
GENERIC: mutate-as ( col val key -- ) ! Mutate collection. Store val as key.
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
GENERIC: at-mutate ( key val col -- )
GENERIC: as-mutate ( val key col -- )
----------------------------------------------------------------------
Those are available in 'extra/newfx'.
I also have code to make those work on tuples:
TUPLE: planet name radius solar-radius ;
<planet> :name "Mars" is
<planet> 100 :radius as
2000 :solar-radius <planet> is-of
I haven't checked that in as it's even more experimental.
There's a very common pattern; that of "dup foo>>", i.e. a dup followed by a
tuple reader. This is captured by the word 'grab' above. I would really like
to call this 'pick' but...
Ed
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
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