]> gitweb.factorcode.org Git - factor.git/commitdiff
infix: added meta information and fixed up docs somewhat
authorPhilipp Brüschweiler <blei42@gmail.com>
Wed, 11 Feb 2009 19:56:09 +0000 (20:56 +0100)
committerPhilipp Brüschweiler <blei42@gmail.com>
Wed, 11 Feb 2009 19:56:09 +0000 (20:56 +0100)
extra/infix/ast/ast.factor
extra/infix/authors.txt [new file with mode: 0644]
extra/infix/infix-docs.factor
extra/infix/infix-tests.factor
extra/infix/infix.factor
extra/infix/parser/parser-tests.factor
extra/infix/parser/parser.factor
extra/infix/summary.txt [new file with mode: 0644]
extra/infix/tags.txt [new file with mode: 0644]
extra/infix/tokenizer/tokenizer-tests.factor
extra/infix/tokenizer/tokenizer.factor

index 0bc22feeb762341f4c31bcf76dca9e3f475b06dc..1908b3d39bc54af20633d9b22b08e8dc9ab22dcd 100644 (file)
@@ -1,3 +1,5 @@
+! Copyright (C) 2009 Philipp Brüschweiler
+! See http://factorcode.org/license.txt for BSD license.
 IN: infix.ast
 
 TUPLE: ast-number value ;
diff --git a/extra/infix/authors.txt b/extra/infix/authors.txt
new file mode 100644 (file)
index 0000000..156a81a
--- /dev/null
@@ -0,0 +1 @@
+Philipp Brüschweiler
index 7a4febb514b7383021d0c4220a30602cfb29dc80..4a2ec963eecad92a21d7ba752ccb1df5c197d76c 100644 (file)
@@ -1,4 +1,6 @@
-USING: help.syntax help.markup prettyprint locals ;
+! Copyright (C) 2009 Philipp Brüschweiler
+! See http://factorcode.org/license.txt for BSD license.
+USING: help.syntax help.markup math prettyprint locals sequences ;
 IN: infix
 
 HELP: [infix
@@ -36,3 +38,54 @@ HELP: [infix|
 } ;
 
 { POSTPONE: [infix POSTPONE: [infix| } related-words
+
+ARTICLE: "infix" "Infix notation"
+"The " { $vocab-link "infix" } " vocabulary implements support for infix notation in Factor source code."
+{ $subsection POSTPONE: [infix }
+{ $subsection POSTPONE: [infix| }
+$nl
+"The usual infix math operators are supported:"
+{ $list
+    { $link + }
+    { $link - }
+    { $link * }
+    { $link / }
+    { { $snippet "%" } ", which is the infix operator for " { $link mod } "." }
+}
+"The standard precedence rules apply: Grouping with parentheses before " { $snippet "*" } ", " { $snippet "/" } "and " { $snippet "%" } " before " { $snippet "+" } " and " { $snippet "-" } "."
+{ $example
+    "USING: infix prettyprint ;"
+    "[infix 5-40/10*2 infix] ."
+    "-3"
+}
+$nl
+"You can call Factor words in infix expressions just as you would in C. There are some restrictions on which words are legal to use though:"
+{ $list
+    "The word must return exactly one value."
+    "The word name must consist of the letters a-z, A-Z, _ or 0-9, and the first character can't be a number."
+}
+{ $example
+    "USING: infix locals math math.functions prettyprint ;"
+    ":: binary_entropy ( p -- h )"
+    "    [infix -(p*log(p) + (1-p)*log(1-p)) / log(2) infix] ;"
+    "[infix binary_entropy( sqrt(0.25) ) infix] ."
+    "1.0"
+}
+$nl
+"You can access " { $vocab-link "sequences" } " inside infix expressions with the familiar " { $snippet "arr[index]" } " notation."
+{ $example
+    "USING: arrays infix prettyprint ;"
+    "[infix| myarr [ { 1 2 3 4 } ] | myarr[4/2]*3 infix] ."
+    "9"
+}
+"Please note: in Factor " { $emphasis "fixnums are sequences too." } " If you are not careful with sequence accesses you may introduce subtle bugs:"
+{ $example
+    "USING: arrays infix locals prettyprint ;"
+    ":: add-2nd-element ( x y -- res )"
+    "    [infix x[1] + y[1] infix] ;"
+    "{ 1 2 3 } 5 add-2nd-element ."
+    "3"
+}
+;
+
+ABOUT: "infix"
index 5ee64681310ef27bd82e59cde1ce48165b16a287..7e8e2dfcc97c2ecfa4342a3b0142cdea5c4cb87f 100644 (file)
@@ -1,3 +1,5 @@
+! Copyright (C) 2009 Philipp Brüschweiler
+! See http://factorcode.org/license.txt for BSD license.
 USING: infix infix.private kernel locals math math.functions
 tools.test ;
 IN: infix.tests
index 31cd1cbe1f4ea82c08373681293a3978f7430779..3e2ba49e3cc926c343538e5bfb5c62145915e4c5 100644 (file)
@@ -1,3 +1,5 @@
+! Copyright (C) 2009 Philipp Brüschweiler
+! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs combinators combinators.short-circuit
 effects fry infix.parser infix.ast kernel locals.parser
 locals.types math multiline namespaces parser quotations
index 0a0288c41b97cc36a12e634a1ff4c915722a7250..d6b5d0559c5f74d45c664020d3ec5a1e58bc54dc 100644 (file)
@@ -1,3 +1,5 @@
+! Copyright (C) 2009 Philipp Brüschweiler
+! See http://factorcode.org/license.txt for BSD license.
 USING: infix.ast infix.parser infix.tokenizer tools.test ;
 IN: infix.parser.tests
 
index beaf3c335d2b7f6889d0295b6ac9a287ee1e57de..2f9ab03d18b9925e8cf17ff323245da2a3aa6ee6 100644 (file)
@@ -1,3 +1,5 @@
+! Copyright (C) 2009 Philipp Brüschweiler
+! See http://factorcode.org/license.txt for BSD license.
 USING: infix.ast infix.tokenizer kernel math peg.ebnf sequences
 strings vectors ;
 IN: infix.parser
diff --git a/extra/infix/summary.txt b/extra/infix/summary.txt
new file mode 100644 (file)
index 0000000..63d366d
--- /dev/null
@@ -0,0 +1 @@
+Support for infix notation in Factor programs
diff --git a/extra/infix/tags.txt b/extra/infix/tags.txt
new file mode 100644 (file)
index 0000000..f427429
--- /dev/null
@@ -0,0 +1 @@
+extensions
index 7e1fb005efe9f1f1d8cfaeb9d32dacdb9bccac74..f9c908414a80efabfa8a58c97218f423153d6fe6 100644 (file)
@@ -1,3 +1,5 @@
+! Copyright (C) 2009 Philipp Brüschweiler
+! See http://factorcode.org/license.txt for BSD license.
 USING: infix.ast infix.tokenizer tools.test ;
 IN: infix.tokenizer.tests
 
index 8c1a1b4a18a5b15c690853aa7279a759c11cbe65..f5bce4b6d7270e860c4001f83a90bc0a2a3d0bc6 100644 (file)
@@ -1,3 +1,5 @@
+! Copyright (C) 2009 Philipp Brüschweiler
+! See http://factorcode.org/license.txt for BSD license.
 USING: infix.ast kernel peg peg.ebnf math.parser sequences
 strings ;
 IN: infix.tokenizer