]> gitweb.factorcode.org Git - factor.git/commitdiff
inverse: Add `under`
authorGiftpflanze <gifti@tools.wmflabs.org>
Sat, 27 Apr 2024 19:51:42 +0000 (21:51 +0200)
committerGiftpflanze <gifti@tools.wmflabs.org>
Sat, 27 Apr 2024 19:51:42 +0000 (21:51 +0200)
basis/inverse/inverse-docs.factor
basis/inverse/inverse-tests.factor
basis/inverse/inverse.factor

index adda3838cc03234966968c9b1cc791c5ad46824e..47b5e1184d38dba864d12e933eb58527dd004eab 100644 (file)
@@ -48,6 +48,18 @@ HELP: switch
 "    } switch ;" }
 { $see-also undo } ;
 
+HELP: under
+{ $values { "invertible-quot" "" } { "quot" "" } }
+{ $description "Applies " { $snippet "invertible-quot" } ", then " { $snippet "quot" } " and finally the inverse of " { $snippet "invertible-quot" } "." }
+{ $examples
+    "Round a decimal number to two decimals:"
+    { $example
+        "USING: inverse math math.functions prettyprint ;"
+        "123.456 [ 100 * ] [ round ] under ."
+        "123.46"
+    }
+} ;
+
 ARTICLE: { "inverse" "intro" } "Invertible quotations"
 "The inverse vocab defines a way to 'undo' quotations, and builds a pattern matching framework on that basis. A quotation can be inverted by reversing it and inverting each word. To define the inverse for particular word, use"
 { $subsections
index 04db91310840b134ae5052d09dc6bfc32c639974..c619156b8a0c950e4afffb29edb7bfa9270f82df 100644 (file)
@@ -97,3 +97,5 @@ TUPLE: funny-tuple ;
 
 { 0 } [ { 1 2 } [ [ 1 + 2 ] { } output>sequence ] undo ] unit-test
 { { 0 1 } } [ 1 2 [ [ [ 1 + ] bi@ ] input<sequence ] undo ] unit-test
+
+{ 123.46 } [ 123.456 [ 100 * ] [ round ] under ] unit-test
index 3a442db48e512bae153aae5e4fc00e64df7fc870..33954c7634701a74a0ae6b8a0686f9fe815e1316 100644 (file)
@@ -291,3 +291,6 @@ MACRO: switch ( quot-alist -- quot ) [switch] ;
 SYNTAX: INVERSE: scan-word parse-definition define-inverse ;
 
 SYNTAX: DUAL: scan-word scan-word define-dual ;
+
+MACRO: under ( reversible-quot quot -- quot )
+    over [undo] '[ @ @ @ ] ;