From df5fa5f23909146ec9ddb15327158f248971b45a Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Sun, 30 Dec 2007 23:59:56 -0500 Subject: [PATCH 1/2] combinators.lib:construct-slots --- extra/combinators/lib/lib.factor | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extra/combinators/lib/lib.factor b/extra/combinators/lib/lib.factor index e4d66d4725..a24e7bd791 100644 --- a/extra/combinators/lib/lib.factor +++ b/extra/combinators/lib/lib.factor @@ -161,3 +161,8 @@ MACRO: map-call-with2 ( quots -- ) r> length [ narray ] curry append ; MACRO: map-exec-with ( words -- ) [ 1quotation ] map [ map-call-with ] curry ; + +MACRO: construct-slots ( assoc tuple-class -- tuple ) + [ construct-empty ] curry swap [ + [ dip ] curry swap 1quotation [ keep ] curry compose + ] { } assoc>map concat compose ; From 5a347d513c59099732be41acf681d3d1e31e3898 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 31 Dec 2007 00:44:40 -0500 Subject: [PATCH 2/2] Macros now memoize when not used as compiler transform --- extra/macros/macros.factor | 12 ++++++------ extra/memoize/memoize.factor | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/extra/macros/macros.factor b/extra/macros/macros.factor index 1c23a1c85e..9c1cb6210b 100755 --- a/extra/macros/macros.factor +++ b/extra/macros/macros.factor @@ -2,18 +2,18 @@ ! See http://factorcode.org/license.txt for BSD license. USING: parser kernel sequences words effects inference.transforms - combinators assocs definitions quotations namespaces ; +combinators assocs definitions quotations namespaces memoize ; IN: macros -: (:) +: (:) ( -- word definition effect-in ) CREATE dup reset-generic parse-definition over "declared-effect" word-prop effect-in length ; -: (MACRO:) - >r - 2dup "macro" set-word-prop - 2dup [ call ] append define-compound +: (MACRO:) ( word definition effect-in -- ) + >r 2dup "macro" set-word-prop + 2dup over "declared-effect" word-prop memoize-quot + [ call ] append define-compound r> define-transform ; : MACRO: diff --git a/extra/memoize/memoize.factor b/extra/memoize/memoize.factor index 75f8ae5ea0..97da6f0a33 100644 --- a/extra/memoize/memoize.factor +++ b/extra/memoize/memoize.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2007 Slava Pestov, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. USING: kernel hashtables sequences arrays words namespaces -parser math assocs effects definitions ; +parser math assocs effects definitions quotations ; IN: memoize : packer ( n -- quot ) @@ -46,3 +46,7 @@ PREDICATE: compound memoized "memoize" word-prop ; M: memoized definer drop \ MEMO: \ ; ; M: memoized definition "memo-quot" word-prop ; + +: memoize-quot ( quot effect -- memo-quot ) + gensym swap dupd "declared-effect" set-word-prop + dup rot define-memoized 1quotation ;