string-head? head?
?string-head ?head
string-tail tail
+vector-tail tail
+vector-tail* tail*
string-tail? tail?
?string-tail ?tail
substring subseq
cat2 append
cat3 append3
+string/ cut
+string// cut*
+split1 split1
+split split
Factor 0.74:
------------
- virtual hosts\r
- keep alive\r
- sleep word\r
-- update docs\r
- redo new compiler backend for PowerPC\r
\r
- plugin: supportsBackspace\r
- faster sequence operations\r
- generic some? all? memq? all=?\r
- index and index* are very slow with lists\r
-- unsafe-sbuf>string\r
- code walker & exceptions\r
- if two tasks write to a unix stream, the buffer can overflow\r
- rename prettyprint to pprint\r
\glossary{
name=interpreter,
description=executes quotations by iterating them and recursing into nested definitions. see compiler}
+\glossary{
+name=quotation,
+description=a list containing Factor code to be executed}
The Factor interpreter executes quotations. Quotations are lists, and since lists can contain any Factor object, they can contain words. It is words that give quotations their operational behavior, as you can see in the following description of the interpreter algorithm.
"/library/collections/sequences-epilogue.factor"
"/library/collections/hashtables.factor"
"/library/collections/namespaces.factor"
- "/library/collections/slicing.factor"
"/library/collections/vectors-epilogue.factor"
+ "/library/collections/slicing.factor"
"/library/collections/strings-epilogue.factor"
"/library/math/matrices.factor"
"/library/words.factor"
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
+IN: kernel-internals
+USING: kernel math strings ;
+
+: (sbuf>string) underlying dup rehash-string ;
+
IN: strings
-USING: generic kernel kernel-internals math math-internals
-sequences ;
+USING: generic sequences ;
M: string (grow) grow-string ;
] ifte
] ifte ;
+! A repeated sequence is the same element n times.
+TUPLE: repeated length object ;
+M: repeated length repeated-length ;
+M: repeated nth nip repeated-object ;
+
IN: kernel
: depth ( -- n )
r> fill swap append
] ifte ;
-: ch>string ( ch -- str ) 1 <sbuf> [ push ] keep >string ;
+: ch>string ( ch -- str ) 1 <sbuf> [ push ] keep (sbuf>string) ;
: >sbuf ( seq -- sbuf ) dup length <sbuf> [ swap nappend ] keep ;
-M: object >string >sbuf underlying dup rehash-string ;
+M: object >string >sbuf (sbuf>string) ;
M: string thaw >sbuf ;
M: string freeze drop >string ;
: v+ ( v v -- v ) [ + ] 2map ;
: v- ( v v -- v ) [ - ] 2map ;
: v* ( v v -- v ) [ * ] 2map ;
+: v** ( v v -- v ) [ conjugate * ] 2map ;
-! Later, this will fixed when seq-2each works properly
-! : v. ( v v -- x ) 0 swap [ * + ] seq-2each ;
-: +/ ( seq -- n ) 0 swap [ + ] each ;
-: v. ( v v -- x ) v* +/ ;
+! Later, this will fixed when 2each works properly
+! : v. ( v v -- x ) 0 swap [ * + ] 2each ;
+: v. ( v v -- x ) v** 0 swap [ + ] each ;
! Matrices
! The major dimension is the number of elements per row.
[ over ?prettyprint-newline matrix-rows. ] when* ;
M: matrix prettyprint* ( indent obj -- indent )
- \ M[ word. >r <prettyprint r>
+ \ M[ word. bl >r 3 + r>
row-list matrix-rows.
- bl \ ]M word. prettyprint> ;
+ bl \ ]M word. 3 - ;
: prettyprint ( obj -- )
[
[ "abc" ] [ "ab" "c" append ] unit-test
[ "abc" ] [ "a" "b" "c" append3 ] unit-test
-[ 3 ] [ "a" "hola" seq-index ] unit-test
-[ -1 ] [ "x" "hola" seq-index ] unit-test
-[ 0 ] [ "" "a" seq-index ] unit-test
-[ 0 ] [ "" "" seq-index ] unit-test
-[ 0 ] [ "hola" "hola" seq-index ] unit-test
-[ 1 ] [ "ol" "hola" seq-index ] unit-test
-[ -1 ] [ "amigo" "hola" seq-index ] unit-test
-[ -1 ] [ "holaa" "hola" seq-index ] unit-test
+[ 3 ] [ "a" "hola" start ] unit-test
+[ -1 ] [ "x" "hola" start ] unit-test
+[ 0 ] [ "" "a" start ] unit-test
+[ 0 ] [ "" "" start ] unit-test
+[ 0 ] [ "hola" "hola" start ] unit-test
+[ 1 ] [ "ol" "hola" start ] unit-test
+[ -1 ] [ "amigo" "hola" start ] unit-test
+[ -1 ] [ "holaa" "hola" start ] unit-test
[ "Beginning" ] [ 9 "Beginning and end" head ] unit-test
[ f ] [ [ 0 10 "hello" subseq ] [ not ] catch ] unit-test
-[ [ "hell" "o wo" "rld" ] ] [ 4 "hello world" split-n ] unit-test
+[ [ "hell" "o wo" "rld" ] ] [ 4 "hello world" groups ] unit-test
[ 4 ] [
0 "There are Four Upper Case characters"
] make-string print ;
: parse-dump ( error -- )
- [
- "Parsing " %
- dup parse-error-file [ "<interactive>" ] unless* % ":" %
- dup parse-error-line [ 1 ] unless* unparse ,
- ] make-string print
+ "Parsing " write
+ dup parse-error-file [ "<interactive>" ] unless* write
+ ":" write
+ dup parse-error-line [ 1 ] unless* unparse print
dup parse-error-text dup string? [ print ] [ drop ] ifte
- [ parse-error-col CHAR: \s fill % "^" % ] make-string print ;
+ parse-error-col CHAR: \s fill write "^" print ;
M: parse-error error. ( error -- )
dup parse-dump delegate error. ;