]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/descriptive/descriptive.factor
factor: trim using lists
[factor.git] / extra / descriptive / descriptive.factor
old mode 100755 (executable)
new mode 100644 (file)
index ba3438e..bb3b3dd
@@ -1,13 +1,19 @@
-USING: words kernel sequences locals locals.parser
-locals.definitions accessors parser namespaces continuations
-summary definitions generalizations arrays ;
+! Copyright (c) 2008 Daniel Ehrenberg.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors arrays continuations debugger definitions
+effects effects.parser generalizations io kernel
+locals.definitions locals.parser prettyprint sequences
+sequences.generalizations tools.annotations words ;
 IN: descriptive
 
 ERROR: descriptive-error args underlying word ;
 
-M: descriptive-error summary
-    word>> "The " swap name>> " word encountered an error."
-    3append ;
+M: descriptive-error error.
+    "The word " write dup word>> pprint " encountered an error." print
+    "Arguments:" print
+    dup args>> stack.
+    "Error:" print
+    underlying>> error. ;
 
 <PRIVATE
 
@@ -20,6 +26,10 @@ M: descriptive-error summary
 
 PRIVATE>
 
+: make-descriptive ( word -- )
+    dup [ ] [ def>> ] [ stack-effect ] tri [descriptive]
+    '[ drop _ ] annotate ;
+
 : define-descriptive ( word def effect -- )
     [ drop "descriptive-definition" set-word-prop ]
     [ [ [ dup ] 2dip [descriptive] ] keep define-declared ]
@@ -28,18 +38,25 @@ PRIVATE>
 SYNTAX: DESCRIPTIVE: (:) define-descriptive ;
 
 PREDICATE: descriptive < word
-    "descriptive-definition" word-prop ;
+    "descriptive-definition" word-prop >boolean ;
 
 M: descriptive definer drop \ DESCRIPTIVE: \ ; ;
 
 M: descriptive definition
     "descriptive-definition" word-prop ;
 
+M: descriptive reset-word
+    [ call-next-method ]
+    [ "descriptive-definition" remove-word-prop ] bi ;
+
 SYNTAX: DESCRIPTIVE:: (::) define-descriptive ;
 
-INTERSECTION: descriptive-lambda descriptive lambda-word ;
+PREDICATE: descriptive-lambda < descriptive lambda-word? ;
 
 M: descriptive-lambda definer drop \ DESCRIPTIVE:: \ ; ;
 
 M: descriptive-lambda definition
     "lambda" word-prop body>> ;
+
+M: descriptive-lambda reset-word
+    [ call-next-method ] [ "lambda" remove-word-prop ] bi ;