memoize: change unpacker to embed array type.
parent
668de36940
commit
001baa2cc4
|
@ -1,8 +1,8 @@
|
||||||
! Copyright (C) 2007, 2010 Slava Pestov, Daniel Ehrenberg.
|
! Copyright (C) 2007, 2010 Slava Pestov, Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel hashtables sequences sequences.private arrays
|
USING: accessors arrays assocs definitions effects
|
||||||
words namespaces make parser effects.parser math assocs effects
|
effects.parser fry hashtables.identity kernel kernel.private
|
||||||
definitions quotations summary accessors fry hashtables.identity ;
|
math sequences sequences.private words ;
|
||||||
IN: memoize
|
IN: memoize
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -28,9 +28,10 @@ IN: memoize
|
||||||
[ { } [nsequence] ] if ;
|
[ { } [nsequence] ] if ;
|
||||||
|
|
||||||
: unpacker ( seq -- quot )
|
: unpacker ( seq -- quot )
|
||||||
length dup 4 <=
|
length dup dup 4 <=
|
||||||
[ { [ drop ] [ ] [ first2-unsafe ] [ first3-unsafe ] [ first4-unsafe ] } nth ]
|
[ { [ drop ] [ ] [ first2-unsafe ] [ first3-unsafe ] [ first4-unsafe ] } nth ]
|
||||||
[ [firstn] ] if ;
|
[ [firstn] ] if swap 1 >
|
||||||
|
[ [ { array } declare ] prepose ] when ;
|
||||||
|
|
||||||
: pack/unpack ( quot effect -- newquot )
|
: pack/unpack ( quot effect -- newquot )
|
||||||
[ in>> packer ] [ out>> unpacker ] bi surround ;
|
[ in>> packer ] [ out>> unpacker ] bi surround ;
|
||||||
|
|
Loading…
Reference in New Issue