memoize: implement identity memoize, trim using lists so bootstrap continues to work

db4
Doug Coleman 2011-11-30 14:28:40 -08:00
parent b26ddc37e8
commit f0b6494c76
5 changed files with 20 additions and 11 deletions

View File

@ -1,6 +1,6 @@
! (c)2010 Joe Groff bsd license
USING: accessors arrays assocs hashtables hashtables.wrapped
kernel parser sequences vocabs.loader ;
USING: accessors assocs hashtables hashtables.wrapped kernel
parser vocabs.loader ;
IN: hashtables.identity
TUPLE: identity-wrapper < wrapped-key ;

View File

@ -1,9 +1,8 @@
! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: assocs continuations hashtables.wrapped kernel
namespaces prettyprint.backend prettyprint.config
prettyprint.custom ;
USING: assocs continuations hashtables.wrapped namespaces
prettyprint.config prettyprint.custom ;
IN: hashtables.wrapped.prettyprint

View File

@ -1,8 +1,8 @@
! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: accessors arrays assocs fry hashtables kernel parser
sequences vocabs.loader ;
USING: accessors arrays assocs hashtables kernel sequences
vocabs.loader ;
IN: hashtables.wrapped

View File

@ -21,6 +21,8 @@ SYNTAX: MACRO:: (::) define-macro ;
SYNTAX: MEMO:: (::) define-memoized ;
SYNTAX: IDENTITY-MEMO:: (::) define-identity-memoized ;
{
"locals.macros"
"locals.fry"

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license.
USING: kernel hashtables sequences sequences.private arrays
words namespaces make parser effects.parser math assocs effects
definitions quotations summary accessors fry ;
definitions quotations summary accessors fry hashtables.identity ;
IN: memoize
<PRIVATE
@ -44,14 +44,22 @@ IN: memoize
PRIVATE>
: define-memoized ( word quot effect -- )
[ drop "memo-quot" set-word-prop ]
[ 2drop H{ } clone "memoize" set-word-prop ]
: (define-memoized) ( word quot effect hashtable -- )
[ [ drop "memo-quot" set-word-prop ] ] dip
'[ 2drop _ "memoize" set-word-prop ]
[ [ [ dup "memoize" word-prop ] 2dip make-memoizer ] keep define-declared ]
3tri ;
: define-memoized ( word quot effect -- )
H{ } clone (define-memoized) ;
: define-identity-memoized ( word quot effect -- )
IH{ } clone (define-memoized) ;
SYNTAX: MEMO: (:) define-memoized ;
SYNTAX: IDENTITY-MEMO: (:) define-identity-memoized ;
PREDICATE: memoized < word "memoize" word-prop ;
M: memoized definer drop \ MEMO: \ ; ;