2009-02-11 14:56:09 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								! Copyright (C) 2009 Philipp Brüschweiler 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								! See http://factorcode.org/license.txt for BSD license. 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-01 14:57:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								USING:  help.syntax  help.markup  math  math.functions  prettyprint  locals  sequences  ;
 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-07 19:03:35 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								IN:  infix 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								HELP:  [infix 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $syntax "[infix ... infix]"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $description "Parses the infix code inside the brackets, converts it to stack code and executes it."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { $example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "USING: infix prettyprint ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "IN: scratchpad" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "[infix 8+2*3 infix] ." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "14" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } $nl
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { $link POSTPONE:  [infix  } " isn't that useful by itself, as it can only access literal numbers and no variables. It is designed to be used together with locals; for example with "  { $link POSTPONE:  ::  } " :" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { $example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "USING: infix locals math.functions prettyprint ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "IN: scratchpad" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ":: quadratic-equation ( a b c -- z- z+ )" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "    [infix (-b-sqrt(b*b-4*a*c)) / (2*a) infix]" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "    [infix (-b+sqrt(b*b-4*a*c)) / (2*a) infix] ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "1 0 -1 quadratic-equation . ." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "1.0\n-1.0" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-11 14:56:09 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								ARTICLE: "infix"  "Infix notation" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"The "  { $vocab-link "infix"  } " vocabulary implements support for infix notation in Factor source code." 
							 
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    POSTPONE:  [infix 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-01 14:57:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    POSTPONE:  INFIX:: 
							 
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2009-02-11 14:56:09 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								"The usual infix math operators are supported:" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $list
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { $link +  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { $link -  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { $link *  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { $link /  }
							 
						 
					
						
							
								
									
										
										
										
											2013-05-01 14:57:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { { $snippet "**"  } ", which is the infix operator for "  { $link ^ } "."  }
							 
						 
					
						
							
								
									
										
										
										
											2009-02-11 14:56:09 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    { { $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
							 
						 
					
						
							
								
									
										
										
										
											2009-05-16 01:29:21 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    "USE: infix" 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-11 14:56:09 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    "[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
							 
						 
					
						
							
								
									
										
										
										
											2009-05-16 01:29:21 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    "USING: infix locals math.functions ;" 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-11 14:56:09 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ":: 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
							 
						 
					
						
							
								
									
										
										
										
											2013-05-01 14:57:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								"You can access "  { $vocab-link "sequences"  } " inside infix expressions with the familiar "  { $snippet "seq[index]"  } " notation." 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-11 14:56:09 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $example
							 
						 
					
						
							
								
									
										
										
										
											2009-10-28 15:05:23 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    "USING: arrays locals infix ;" 
							 
						 
					
						
							
								
									
										
										
										
											2009-10-27 22:50:31 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    "[let { 1 2 3 4 } :> myarr [infix myarr[4/2]*3 infix] ] ." 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-11 14:56:09 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    "9" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2011-03-18 01:42:23 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$nl
							 
						 
					
						
							
								
									
										
										
										
											2013-05-01 14:57:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								"You can create sub-"  { $vocab-link "sequences"  } " inside infix expressions using "  { $snippet "seq[from:to]"  } " notation." 
							 
						 
					
						
							
								
									
										
										
										
											2011-03-18 01:42:23 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "USING: arrays locals infix ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "[let \"foobar\" :> s [infix s[0:3] infix] ] ." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "\"foo\"" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2013-05-01 14:57:20 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								$nl
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"Additionally, you can step through "  { $vocab-link "sequences"  } " with "  { $snippet "seq[from:to:step]"  } " notation." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "USING: arrays locals infix ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "[let \"reverse\" :> s [infix s[::-1] infix] ] ." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "\"esrever\"" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "USING: arrays locals infix ;" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "[let \"0123456789\" :> s [infix s[::2] infix] ] ." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "\"02468\"" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2009-02-11 14:56:09 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								ABOUT: "infix"