]> gitweb.factorcode.org Git - factor.git/commitdiff
Fixing embarassing mistake
authorDaniel Ehrenberg <microdan@gmail.com>
Tue, 31 May 2005 00:19:37 +0000 (00:19 +0000)
committerDaniel Ehrenberg <microdan@gmail.com>
Tue, 31 May 2005 00:19:37 +0000 (00:19 +0000)
doc/comparison.tex

index 6d092b68cfacab778bb3db777b0cd3e255230844..27fa2b6802496024f5b25e0c79b59b4112c4e485 100644 (file)
@@ -127,7 +127,7 @@ Common Lisp and Scheme don't have many similarities to Factor on the surface, bu
 
 \subsection{Data}
 
-Factor's builtin datatypes are also similar to Lisp and Scheme. Lists and vectors have correctly corresponding names and meanings in all three languages we're discussing, and so are hashtables between Lisp and Factor. The biggest difference is that lists are now immutable in Factor whereas they are mutable in Lisp and Scheme. Factor provides library functions for dealing with alists, though not plists. In Factor, you can use \texttt{cons} to cons things together, \texttt{car} to get the car of a list, and \texttt{cdr} to get the cdr of a list, pretty intuitive for a Lisp or Scheme programmer. The empty list is false (\texttt{f}), just like Lisp, and the car or cdr of f is f, just like Lisp. Factor's list literal syntax is \verb|[ 1 2 3 ]| for the equivalent of \verb|'(1 2 3)|. You can include symbols in your list literals too, for example \verb|[ blah ]| is like \verb|'(blah)|. Factor has some of the same basic list higher order functions as Lisp and Scheme. Lisp's \texttt{mapcar} and Scheme's \texttt{map} are \texttt{map} in Factor. Lisp's \texttt{remove-if-not} and Scheme's \texttt{filter} are \texttt{filter} in Factor.
+Factor's builtin datatypes are also similar to Lisp and Scheme. Lists and vectors have correctly corresponding names and meanings in all three languages we're discussing, and so are hashtables between Lisp and Factor. The biggest difference is that lists are now immutable in Factor whereas they are mutable in Lisp and Scheme. Factor provides library functions for dealing with alists, though not plists. In Factor, you can use \texttt{cons} to cons things together, \texttt{car} to get the car of a list, and \texttt{cdr} to get the cdr of a list, pretty intuitive for a Lisp or Scheme programmer. The empty list is false (\texttt{f}), just like Lisp, and the car or cdr of f is f, just like Lisp. Factor's list literal syntax is \verb|[ 1 2 3 ]| for the equivalent of \verb|'(1 2 3)|. You can include symbols in your list literals too, for example \verb|[ blah ]| is like \verb|'(blah)|. Factor has some of the same basic list higher order functions as Lisp and Scheme. Lisp's \texttt{mapcar} and Scheme's \texttt{map} are \texttt{map} in Factor. Lisp's \texttt{remove-if-not} and Scheme's \texttt{filter} are \texttt{subset} in Factor.
 
 
 Strings in Factor are created by enclosing characters in double quotes, just like Scheme and Lisp. Characters, however, are not made with the \verb|#\a| syntax, rather they are made like \verb|CHAR: a| For the thing following the \texttt{CHAR:} word, you use the same escape sequences as in a string.
@@ -181,7 +181,7 @@ Although Python and Factor aren't the most similar languages, you can still see
 
 Strings in Factor are similar to Python. They are immutable and can be made by placing double quotes around a sequence of letters, which may include escape patterns. But Factor doesn't give the option of single quotes, raw strings or multiline strings.
 
-Factor has no direct equivalent of Python's lists, but instead it has several other collection types for different purposes. Factor has something called lists, but don't confuse them with Python's lists: Factor lists are linked lists, aka cons cells. These linked lists are immutable. The syntax for creating the equivalent of \verb|[1, 2, 3]| as a linked list in Factor is \verb|[ 1 2 3 ]|. Notice where spaces are: you can't remove any of those. Additionally, you can't put arbitrary expressions in this form; you must use literals. To use arbitrary expressions, you use the \texttt{makelist} combinator. The equivalent of \verb|[1+2, 3+4]| is \verb|[ 1 2 + , 3 4 + , ] make-list|. Notice how you have to put a comma after each item including the last one, not just between items. For list comprehensions, Factor uses functions much like the old \texttt{map}() and \texttt{filter}(). Confusingly, Factor's method of making a lambda is putting those same square brackets around code. The way to write \verb|[value for item in list]| in Factor is \verb|list [ value ] map|, and the equivalent of \verb|[item for item in list if test]| is \verb|list [ test ] filter|.
+Factor has no direct equivalent of Python's lists, but instead it has several other collection types for different purposes. Factor has something called lists, but don't confuse them with Python's lists: Factor lists are linked lists, aka cons cells. These linked lists are immutable. The syntax for creating the equivalent of \verb|[1, 2, 3]| as a linked list in Factor is \verb|[ 1 2 3 ]|. Notice where spaces are: you can't remove any of those. Additionally, you can't put arbitrary expressions in this form; you must use literals. To use arbitrary expressions, you use the \texttt{makelist} combinator. The equivalent of \verb|[1+2, 3+4]| is \verb|[ 1 2 + , 3 4 + , ] make-list|. Notice how you have to put a comma after each item including the last one, not just between items. For list comprehensions, Factor uses functions much like the old \texttt{map}() and \texttt{filter}(). Confusingly, Factor's method of making a lambda is putting those same square brackets around code. The way to write \verb|[value for item in list]| in Factor is \verb|list [ value ] map|, and the equivalent of \verb|[item for item in list if test]| is \verb|list [ test ] subset|.
 
 Another collection type in Factor is the vector. Vectors are used when you want to index it with a number. The syntax is similar to lists: \verb|{ 1 2 3 }| is like \verb|[1, 2, 3]|. There is no equivalent of make-list for vectors. Vectors are fixed-length but they are mutable. Factor has hashtables in place of Pythons's dictionaries. \verb|{"hi": 1, "hello": 2}| is \verb|{{ [[ "hi" 1 ]] [[ "hello" 2 ]] }}|.