Merge branch 'infix' of git://github.com/EdwardXXIV/factor into edwardxxiv
						commit
						9cfa9817da
					
				|  | @ -1,3 +1,5 @@ | ||||||
|  | ! Copyright (C) 2009 Philipp Brüschweiler | ||||||
|  | ! See http://factorcode.org/license.txt for BSD license. | ||||||
| IN: infix.ast | IN: infix.ast | ||||||
| 
 | 
 | ||||||
| TUPLE: ast-number value ; | TUPLE: ast-number value ; | ||||||
|  |  | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | Philipp Brüschweiler | ||||||
|  | @ -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 | IN: infix | ||||||
| 
 | 
 | ||||||
| HELP: [infix | HELP: [infix | ||||||
|  | @ -36,3 +38,54 @@ HELP: [infix| | ||||||
| } ; | } ; | ||||||
| 
 | 
 | ||||||
| { POSTPONE: [infix POSTPONE: [infix| } related-words | { 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" | ||||||
|  |  | ||||||
|  | @ -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 | USING: infix infix.private kernel locals math math.functions | ||||||
| tools.test ; | tools.test ; | ||||||
| IN: infix.tests | IN: infix.tests | ||||||
|  |  | ||||||
|  | @ -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 | USING: accessors assocs combinators combinators.short-circuit | ||||||
| effects fry infix.parser infix.ast kernel locals.parser | effects fry infix.parser infix.ast kernel locals.parser | ||||||
| locals.types math multiline namespaces parser quotations | locals.types math multiline namespaces parser quotations | ||||||
|  |  | ||||||
|  | @ -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 ; | USING: infix.ast infix.parser infix.tokenizer tools.test ; | ||||||
| IN: infix.parser.tests | IN: infix.parser.tests | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -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 | USING: infix.ast infix.tokenizer kernel math peg.ebnf sequences | ||||||
| strings vectors ; | strings vectors ; | ||||||
| IN: infix.parser | IN: infix.parser | ||||||
|  |  | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | Support for infix notation in Factor programs | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | extensions | ||||||
|  | @ -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 ; | USING: infix.ast infix.tokenizer tools.test ; | ||||||
| IN: infix.tokenizer.tests | IN: infix.tokenizer.tests | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -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 | USING: infix.ast kernel peg peg.ebnf math.parser sequences | ||||||
| strings ; | strings ; | ||||||
| IN: infix.tokenizer | IN: infix.tokenizer | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue