Paste: hash to slots

Author: randy7
Mode: factor
Date: Sun, 20 Dec 2009 21:53:45
Plain Text |
! takes values from a hashtable and matches them against tuple's slots names, replacing the slots' values with the corresponding ones (unless the value is f).

: slot-names ( mirror -- seq )        
    >alist [ first ] map ;
        
: slot-values-from-hash ( hash seq -- slot-value-pairs )
    [ [ swap at ] keep swap 2array ] with map
    [ second ] filter ;
        
: set-mirror-slots ( mirror value-pairs -- mirror' ) 
    over '[ first2 swap _ set-at ] each ;
        
: values-to-slots ( hash mirror -- mirror' )
    tuck slot-names slot-values-from-hash set-mirror-slots ;
    
: hash>slots ( hash tuple -- tuple' )
    <mirror> values-to-slots object>> ;

Annotation: blah

Author: bla
Mode: text
Date: Thu, 7 Jan 2010 16:01:33
Plain Text |
a sensation of mysterious horror
a feeling of bravery + adventure

Aslan the Highest of All High Kings
The Majesty of Aslan
The Deceit of The White Witch

The Chronicles of Narnia
The Voyage of the Dawn Treader

New Annotation

Summary:
Author:
Mode:
Body: