! Copyright (c) 2009 - Sascha Matzke ! See http://factorcode.org/license.txt for BSD license USING: sequences strings io.encodings.string io.encodings.utf8 splitting memoize fry kernel assocs math ; IN: assoc-path [ drop f ] unless ] [ at ] if ; inline : [build-path-accessor] ( pathseq -- quot: ( assoc -- value/f ) ) '[ [ _ extract-key ] dip at@ dup [ [ swap [ [build-path-accessor] call ] when* ] [ drop f ] if* ] [ 2drop f ] if ] ; inline recursive MEMO: [path-accessor] ( path -- quot: ( assoc -- value/f ) ) split-path [build-path-accessor] ; PRIVATE> ! retrieves value from nested assocs... ! "a.b.c" H{ { "a" H{ { "b" { H{ { "c" 23 } } H{ { "c" 42 } } } } } } } at-path ! => { 23 42 } : at-path ( pathstr assoc -- value/f ) swap [path-accessor] call ; inline