Merge branch 'master' of git://factorcode.org/git/factor

db4
Slava Pestov 2008-03-19 21:26:13 -05:00
commit 4675811d68
112 changed files with 656 additions and 572 deletions

View File

@ -30,6 +30,7 @@ crossref off
"syntax" vocab vocab-words bootstrap-syntax set "syntax" vocab vocab-words bootstrap-syntax set
H{ } clone dictionary set H{ } clone dictionary set
H{ } clone changed-words set H{ } clone changed-words set
H{ } clone root-cache set
! Trivial recompile hook. We don't want to touch the code heap ! Trivial recompile hook. We don't want to touch the code heap
! during stage1 bootstrap, it would just waste time. ! during stage1 bootstrap, it would just waste time.

View File

@ -25,7 +25,7 @@ SYMBOL: bootstrap-time
"exclude" "include" "exclude" "include"
[ get-global " " split [ empty? not ] subset ] 2apply [ get-global " " split [ empty? not ] subset ] 2apply
seq-diff seq-diff
[ "bootstrap." swap append require ] each ; [ "bootstrap." prepend require ] each ;
: compile-remaining ( -- ) : compile-remaining ( -- )
"Compiling remaining words..." print flush "Compiling remaining words..." print flush

View File

@ -21,6 +21,7 @@ IN: bootstrap.syntax
"C:" "C:"
"CHAR:" "CHAR:"
"DEFER:" "DEFER:"
"ERROR:"
"F{" "F{"
"FV{" "FV{"
"FORGET:" "FORGET:"

View File

@ -1,6 +1,6 @@
USING: alien arrays definitions generic assocs hashtables io USING: alien arrays definitions generic assocs hashtables io
kernel math namespaces parser prettyprint sequences strings kernel math namespaces parser prettyprint sequences strings
tools.test vectors words quotations classes io.streams.string tools.test vectors words quotations classes
classes.private classes.union classes.mixin classes.predicate classes.private classes.union classes.mixin classes.predicate
vectors definitions source-files compiler.units ; vectors definitions source-files compiler.units ;
IN: classes.tests IN: classes.tests
@ -63,10 +63,6 @@ UNION: c a b ;
UNION: bah fixnum alien ; UNION: bah fixnum alien ;
[ bah ] [ \ bah? "predicating" word-prop ] unit-test [ bah ] [ \ bah? "predicating" word-prop ] unit-test
! Test generic see and parsing
[ "USING: alien math ;\nIN: classes.tests\nUNION: bah fixnum alien ;\n" ]
[ [ \ bah see ] with-string-writer ] unit-test
! Test redefinition of classes ! Test redefinition of classes
UNION: union-1 fixnum float ; UNION: union-1 fixnum float ;
@ -180,6 +176,8 @@ UNION: forget-class-bug-2 forget-class-bug-1 dll ;
[ f ] [ forget-class-bug-2 typemap get values [ memq? ] with contains? ] unit-test [ f ] [ forget-class-bug-2 typemap get values [ memq? ] with contains? ] unit-test
USE: io.streams.string
2 [ 2 [
[ "mixin-forget-test" forget-source ] with-compilation-unit [ "mixin-forget-test" forget-source ] with-compilation-unit
@ -224,3 +222,7 @@ MIXIN: flat-mx-2 INSTANCE: flat-mx-2 flat-mx-1
TUPLE: flat-mx-2-1 ; INSTANCE: flat-mx-2-1 flat-mx-2 TUPLE: flat-mx-2-1 ; INSTANCE: flat-mx-2-1 flat-mx-2
[ t ] [ T{ flat-mx-2-1 } flat-mx-1? ] unit-test [ t ] [ T{ flat-mx-2-1 } flat-mx-1? ] unit-test
! Test generic see and parsing
[ "USING: alien math ;\nIN: classes.tests\nUNION: bah fixnum alien ;\n" ]
[ [ \ bah see ] with-string-writer ] unit-test

View File

@ -13,7 +13,7 @@ PREDICATE: class union-class
drop [ drop f ] drop [ drop f ]
] [ ] [
unclip first "predicate" word-prop swap unclip first "predicate" word-prop swap
[ >r "predicate" word-prop [ dup ] swap append r> ] [ >r "predicate" word-prop [ dup ] prepend r> ]
assoc-map alist>quot assoc-map alist>quot
] if ; ] if ;

View File

@ -80,7 +80,7 @@ M: hashtable hashcode*
: hash-case-quot ( default assoc -- quot ) : hash-case-quot ( default assoc -- quot )
hash-case-table hash-dispatch-quot hash-case-table hash-dispatch-quot
[ dup hashcode >fixnum ] swap append ; [ dup hashcode >fixnum ] prepend ;
: contiguous-range? ( keys -- from to ? ) : contiguous-range? ( keys -- from to ? )
dup [ fixnum? ] all? [ dup [ fixnum? ] all? [

View File

@ -7,12 +7,12 @@ splitting io.files ;
: run-bootstrap-init ( -- ) : run-bootstrap-init ( -- )
"user-init" get [ "user-init" get [
home ".factor-boot-rc" path+ ?run-file home ".factor-boot-rc" append-path ?run-file
] when ; ] when ;
: run-user-init ( -- ) : run-user-init ( -- )
"user-init" get [ "user-init" get [
home ".factor-rc" path+ ?run-file home ".factor-rc" append-path ?run-file
] when ; ] when ;
: cli-var-param ( name value -- ) swap set-global ; : cli-var-param ( name value -- ) swap set-global ;

View File

@ -385,7 +385,7 @@ cell 8 = [
[ 252 ] [ B{ 1 2 3 -4 5 } 3 [ { byte-array fixnum } declare alien-unsigned-1 ] compile-call ] unit-test [ 252 ] [ B{ 1 2 3 -4 5 } 3 [ { byte-array fixnum } declare alien-unsigned-1 ] compile-call ] unit-test
[ -4 ] [ B{ 1 2 3 -4 5 } 3 [ { byte-array fixnum } declare alien-signed-1 ] compile-call ] unit-test [ -4 ] [ B{ 1 2 3 -4 5 } 3 [ { byte-array fixnum } declare alien-signed-1 ] compile-call ] unit-test
: xword-def word-def [ { fixnum } declare ] swap append ; : xword-def word-def [ { fixnum } declare ] prepend ;
[ -100 ] [ -100 <char> [ { byte-array } declare *char ] compile-call ] unit-test [ -100 ] [ -100 <char> [ { byte-array } declare *char ] compile-call ] unit-test
[ 156 ] [ -100 <uchar> [ { byte-array } declare *uchar ] compile-call ] unit-test [ 156 ] [ -100 <uchar> [ { byte-array } declare *uchar ] compile-call ] unit-test

View File

@ -53,7 +53,7 @@ TUPLE: no-math-method left right generic ;
2dup and [ 2dup and [
2dup math-upgrade >r 2dup math-upgrade >r
math-class-max over order min-class applicable-method math-class-max over order min-class applicable-method
r> swap append r> prepend
] [ ] [
2drop object-method 2drop object-method
] if ; ] if ;

View File

@ -161,7 +161,7 @@ C: <hook-combination> hook-combination
0 (dispatch#) [ 0 (dispatch#) [
swap slip swap slip
hook-combination-var [ get ] curry hook-combination-var [ get ] curry
swap append prepend
] with-variable ; inline ] with-variable ; inline
M: hook-combination make-default-method M: hook-combination make-default-method
@ -170,7 +170,7 @@ M: hook-combination make-default-method
M: hook-combination perform-combination M: hook-combination perform-combination
[ [
standard-methods standard-methods
[ [ drop ] swap append ] assoc-map [ [ drop ] prepend ] assoc-map
single-combination single-combination
] with-hook ; ] with-hook ;

View File

@ -14,19 +14,26 @@ GENERIC: encode-char ( char stream encoding -- )
GENERIC: <decoder> ( stream decoding -- newstream ) GENERIC: <decoder> ( stream decoding -- newstream )
GENERIC: <encoder> ( stream encoding -- newstream )
: replacement-char HEX: fffd ; : replacement-char HEX: fffd ;
! Decoding TUPLE: decoder stream code cr ;
<PRIVATE
TUPLE: decode-error ; TUPLE: decode-error ;
: decode-error ( -- * ) \ decode-error construct-empty throw ; : decode-error ( -- * ) \ decode-error construct-empty throw ;
TUPLE: decoder stream code cr ; GENERIC: <encoder> ( stream encoding -- newstream )
TUPLE: encoder stream code ;
TUPLE: encode-error ;
: encode-error ( -- * ) \ encode-error construct-empty throw ;
! Decoding
<PRIVATE
M: tuple-class <decoder> construct-empty <decoder> ; M: tuple-class <decoder> construct-empty <decoder> ;
M: tuple <decoder> f decoder construct-boa ; M: tuple <decoder> f decoder construct-boa ;
@ -101,12 +108,6 @@ M: decoder stream-readln ( stream -- str )
M: decoder dispose decoder-stream dispose ; M: decoder dispose decoder-stream dispose ;
! Encoding ! Encoding
TUPLE: encode-error ;
: encode-error ( -- * ) \ encode-error construct-empty throw ;
TUPLE: encoder stream code ;
M: tuple-class <encoder> construct-empty <encoder> ; M: tuple-class <encoder> construct-empty <encoder> ;
M: tuple <encoder> encoder construct-boa ; M: tuple <encoder> encoder construct-boa ;
@ -132,6 +133,7 @@ INSTANCE: encoder plain-writer
: redecode ( stream encoding -- newstream ) : redecode ( stream encoding -- newstream )
over decoder? [ >r decoder-stream r> ] when <decoder> ; over decoder? [ >r decoder-stream r> ] when <decoder> ;
PRIVATE> PRIVATE>
: <encoder-duplex> ( stream-in stream-out encoding -- duplex ) : <encoder-duplex> ( stream-in stream-out encoding -- duplex )

View File

@ -19,7 +19,7 @@ ARTICLE: "pathnames" "Pathname manipulation"
{ $subsection parent-directory } { $subsection parent-directory }
{ $subsection file-name } { $subsection file-name }
{ $subsection last-path-separator } { $subsection last-path-separator }
{ $subsection path+ } { $subsection append-path }
"Pathnames relative to Factor's install directory:" "Pathnames relative to Factor's install directory:"
{ $subsection resource-path } { $subsection resource-path }
{ $subsection ?resource-path } { $subsection ?resource-path }
@ -224,7 +224,7 @@ HELP: stat ( path -- directory? permissions length modified )
{ stat exists? directory? } related-words { stat exists? directory? } related-words
HELP: path+ HELP: append-path
{ $values { "str1" "a string" } { "str2" "a string" } { "str" "a string" } } { $values { "str1" "a string" } { "str2" "a string" } { "str" "a string" } }
{ $description "Concatenates two pathnames." } ; { $description "Concatenates two pathnames." } ;

View File

@ -32,10 +32,13 @@ HOOK: rename-file io-backend ( from to -- )
: left-trim-separators ( str -- newstr ) : left-trim-separators ( str -- newstr )
[ path-separator? ] left-trim ; [ path-separator? ] left-trim ;
: path+ ( str1 str2 -- str ) : append-path ( str1 str2 -- str )
>r right-trim-separators "/" r> >r right-trim-separators "/" r>
left-trim-separators 3append ; left-trim-separators 3append ;
: prepend-path ( str1 str2 -- str )
swap append-path ; inline
: last-path-separator ( path -- n ? ) : last-path-separator ( path -- n ? )
[ length 1- ] keep [ path-separator? ] find-last* ; [ length 1- ] keep [ path-separator? ] find-last* ;
@ -119,7 +122,7 @@ HOOK: make-directory io-backend ( path -- )
: fixup-directory ( path seq -- newseq ) : fixup-directory ( path seq -- newseq )
[ [
dup string? dup string?
[ tuck path+ directory? 2array ] [ nip ] if [ tuck append-path directory? 2array ] [ nip ] if
] with map ] with map
[ first special-directory? not ] subset ; [ first special-directory? not ] subset ;
@ -127,7 +130,7 @@ HOOK: make-directory io-backend ( path -- )
normalize-directory dup (directory) fixup-directory ; normalize-directory dup (directory) fixup-directory ;
: directory* ( path -- seq ) : directory* ( path -- seq )
dup directory [ first2 >r path+ r> 2array ] with map ; dup directory [ first2 >r append-path r> 2array ] with map ;
! Touching files ! Touching files
HOOK: touch-file io-backend ( path -- ) HOOK: touch-file io-backend ( path -- )
@ -146,7 +149,7 @@ HOOK: delete-directory io-backend ( path -- )
: delete-tree ( path -- ) : delete-tree ( path -- )
dup directory? (delete-tree) ; dup directory? (delete-tree) ;
: to-directory over file-name path+ ; : to-directory over file-name append-path ;
! Moving and renaming files ! Moving and renaming files
HOOK: move-file io-backend ( from to -- ) HOOK: move-file io-backend ( from to -- )
@ -179,7 +182,7 @@ DEFER: copy-tree-into
: copy-tree ( from to -- ) : copy-tree ( from to -- )
over directory? [ over directory? [
>r dup directory swap r> [ >r dup directory swap r> [
>r swap first path+ r> copy-tree-into >r swap first append-path r> copy-tree-into
] 2curry each ] 2curry each
] [ ] [
copy-file copy-file
@ -194,7 +197,7 @@ DEFER: copy-tree-into
! Special paths ! Special paths
: resource-path ( path -- newpath ) : resource-path ( path -- newpath )
\ resource-path get [ image parent-directory ] unless* \ resource-path get [ image parent-directory ] unless*
swap path+ ; prepend-path ;
: ?resource-path ( path -- newpath ) : ?resource-path ( path -- newpath )
"resource:" ?head [ resource-path ] when ; "resource:" ?head [ resource-path ] when ;
@ -236,7 +239,7 @@ M: pathname <=> [ pathname-string ] compare ;
[ dup make-directory ] [ dup make-directory ]
when ; when ;
: temp-file ( name -- path ) temp-directory swap path+ ; : temp-file ( name -- path ) temp-directory prepend-path ;
! Home directory ! Home directory
: home ( -- dir ) : home ( -- dir )

View File

@ -35,7 +35,7 @@ IN: optimizer.specializers
swap "method-class" word-prop add* ; swap "method-class" word-prop add* ;
: specialize-method ( quot method -- quot' ) : specialize-method ( quot method -- quot' )
method-declaration [ declare ] curry swap append ; method-declaration [ declare ] curry prepend ;
: specialize-quot ( quot specializer -- quot' ) : specialize-quot ( quot specializer -- quot' )
dup { number } = [ dup { number } = [

View File

@ -299,6 +299,8 @@ M: immutable-sequence clone-like like ;
: append ( seq1 seq2 -- newseq ) over (append) ; : append ( seq1 seq2 -- newseq ) over (append) ;
: prepend ( seq1 seq2 -- newseq ) swap append ; inline
: 3append ( seq1 seq2 seq3 -- newseq ) pick (3append) ; : 3append ( seq1 seq2 seq3 -- newseq ) pick (3append) ;
: change-nth ( i seq quot -- ) : change-nth ( i seq quot -- )

View File

@ -163,6 +163,11 @@ IN: bootstrap.syntax
[ construct-boa ] curry define-inline [ construct-boa ] curry define-inline
] define-syntax ] define-syntax
"ERROR:" [
CREATE-CLASS dup ";" parse-tokens define-tuple-class
dup [ construct-boa throw ] curry define
] define-syntax
"FORGET:" [ "FORGET:" [
scan-word scan-word
dup parsing? [ V{ } clone swap execute first ] when dup parsing? [ V{ } clone swap execute first ] when

View File

@ -43,8 +43,6 @@ HELP: find-vocab-root
{ $values { "vocab" "a vocabulary specifier" } { "path/f" "a pathname string" } } { $values { "vocab" "a vocabulary specifier" } { "path/f" "a pathname string" } }
{ $description "Searches for a vocabulary in the vocabulary roots." } ; { $description "Searches for a vocabulary in the vocabulary roots." } ;
{ vocab-root find-vocab-root } related-words
HELP: no-vocab HELP: no-vocab
{ $values { "name" "a vocabulary name" } } { $values { "name" "a vocabulary name" } }
{ $description "Throws a " { $link no-vocab } "." } { $description "Throws a " { $link no-vocab } "." }

View File

@ -13,15 +13,15 @@ debugger compiler.units tools.vocabs ;
] unit-test ] unit-test
[ T{ vocab-link f "vocabs.loader.test" } ] [ T{ vocab-link f "vocabs.loader.test" } ]
[ "vocabs.loader.test" f >vocab-link ] unit-test [ "vocabs.loader.test" >vocab-link ] unit-test
[ t ] [ t ]
[ "kernel" f >vocab-link "kernel" vocab = ] unit-test [ "kernel" >vocab-link "kernel" vocab = ] unit-test
[ t ] [ [ t ] [
"kernel" vocab-files "kernel" vocab-files
"kernel" vocab vocab-files "kernel" vocab vocab-files
"kernel" f <vocab-link> vocab-files "kernel" <vocab-link> vocab-files
3array all-equal? 3array all-equal?
] unit-test ] unit-test
@ -36,7 +36,7 @@ IN: vocabs.loader.tests
[ { 3 3 3 } ] [ [ { 3 3 3 } ] [
"vocabs.loader.test.2" run "vocabs.loader.test.2" run
"vocabs.loader.test.2" vocab run "vocabs.loader.test.2" vocab run
"vocabs.loader.test.2" f <vocab-link> run "vocabs.loader.test.2" <vocab-link> run
3array 3array
] unit-test ] unit-test
@ -115,7 +115,7 @@ IN: vocabs.loader.tests
[ 3 ] [ "count-me" get-global ] unit-test [ 3 ] [ "count-me" get-global ] unit-test
[ { "resource:core/kernel/kernel.factor" 1 } ] [ { "resource:core/kernel/kernel.factor" 1 } ]
[ "kernel" f <vocab-link> where ] unit-test [ "kernel" <vocab-link> where ] unit-test
[ { "resource:core/kernel/kernel.factor" 1 } ] [ { "resource:core/kernel/kernel.factor" 1 } ]
[ "kernel" vocab where ] unit-test [ "kernel" vocab where ] unit-test
@ -136,7 +136,7 @@ IN: vocabs.loader.tests
[ [
{ "2" "a" "b" "d" "e" "f" } { "2" "a" "b" "d" "e" "f" }
[ [
"vocabs.loader.test." swap append forget-vocab "vocabs.loader.test." prepend forget-vocab
] each ] each
] with-compilation-unit ; ] with-compilation-unit ;

View File

@ -23,30 +23,30 @@ V{
[ >r dup peek r> append add ] when* [ >r dup peek r> append add ] when*
"/" join ; "/" join ;
: vocab-path+ ( vocab path -- newpath )
swap vocab-root dup [ swap path+ ] [ 2drop f ] if ;
: vocab-source-path ( vocab -- path/f )
dup ".factor" vocab-dir+ vocab-path+ ;
: vocab-docs-path ( vocab -- path/f )
dup "-docs.factor" vocab-dir+ vocab-path+ ;
: vocab-dir? ( root name -- ? ) : vocab-dir? ( root name -- ? )
over [ over [
".factor" vocab-dir+ path+ resource-exists? ".factor" vocab-dir+ append-path resource-exists?
] [ ] [
2drop f 2drop f
] if ; ] if ;
SYMBOL: root-cache
H{ } clone root-cache set-global
: find-vocab-root ( vocab -- path/f ) : find-vocab-root ( vocab -- path/f )
vocab-roots get swap [ vocab-dir? ] curry find nip ; vocab-name root-cache get [
vocab-roots get swap [ vocab-dir? ] curry find nip
] cache ;
M: string vocab-root : vocab-append-path ( vocab path -- newpath )
vocab dup [ vocab-root ] when ; swap find-vocab-root dup [ prepend-path ] [ 2drop f ] if ;
M: vocab-link vocab-root : vocab-source-path ( vocab -- path/f )
vocab-link-root ; dup ".factor" vocab-dir+ vocab-append-path ;
: vocab-docs-path ( vocab -- path/f )
dup "-docs.factor" vocab-dir+ vocab-append-path ;
SYMBOL: load-help? SYMBOL: load-help?
@ -56,7 +56,7 @@ SYMBOL: load-help?
: load-source ( vocab -- ) : load-source ( vocab -- )
[ source-wasn't-loaded ] keep [ source-wasn't-loaded ] keep
[ vocab-source-path bootstrap-file ] keep [ vocab-source-path [ bootstrap-file ] when* ] keep
source-was-loaded ; source-was-loaded ;
: docs-were-loaded t swap set-vocab-docs-loaded? ; : docs-were-loaded t swap set-vocab-docs-loaded? ;
@ -70,18 +70,9 @@ SYMBOL: load-help?
docs-were-loaded docs-were-loaded
] [ drop ] if ; ] [ drop ] if ;
: create-vocab-with-root ( name root -- vocab )
swap create-vocab [ set-vocab-root ] keep ;
: update-root ( vocab -- )
dup vocab-root
[ drop ] [ dup find-vocab-root swap set-vocab-root ] if ;
: reload ( name -- ) : reload ( name -- )
[ [
dup vocab [ dup vocab [ dup load-source load-docs ] [ no-vocab ] ?if
dup update-root dup load-source load-docs
] [ no-vocab ] ?if
] with-compiler-errors ; ] with-compiler-errors ;
: require ( vocab -- ) : require ( vocab -- )
@ -104,22 +95,17 @@ SYMBOL: blacklist
GENERIC: (load-vocab) ( name -- ) GENERIC: (load-vocab) ( name -- )
M: vocab (load-vocab) M: vocab (load-vocab)
dup update-root [
dup vocab-source-loaded? [ dup load-source ] unless
dup vocab-root [ dup vocab-docs-loaded? [ dup load-docs ] unless
[ drop
dup vocab-source-loaded? [ dup load-source ] unless ] [ [ swap add-to-blacklist ] keep rethrow ] recover ;
dup vocab-docs-loaded? [ dup load-docs ] unless
] [ [ swap add-to-blacklist ] keep rethrow ] recover
] when drop ;
M: string (load-vocab)
! ".private" ?tail drop
dup find-vocab-root >vocab-link (load-vocab) ;
M: vocab-link (load-vocab) M: vocab-link (load-vocab)
dup vocab-name swap vocab-root dup vocab-name create-vocab (load-vocab) ;
[ create-vocab-with-root (load-vocab) ] [ 2drop ] if ;
M: string (load-vocab)
create-vocab (load-vocab) ;
[ [
[ [

View File

@ -16,7 +16,6 @@ $nl
{ $subsection vocab } { $subsection vocab }
"Accessors for various vocabulary attributes:" "Accessors for various vocabulary attributes:"
{ $subsection vocab-name } { $subsection vocab-name }
{ $subsection vocab-root }
{ $subsection vocab-main } { $subsection vocab-main }
{ $subsection vocab-help } { $subsection vocab-help }
"Looking up existing vocabularies and creating new vocabularies:" "Looking up existing vocabularies and creating new vocabularies:"
@ -50,10 +49,6 @@ HELP: vocab-name
{ $values { "vocab" "a vocabulary specifier" } { "name" string } } { $values { "vocab" "a vocabulary specifier" } { "name" string } }
{ $description "Outputs the name of a vocabulary." } ; { $description "Outputs the name of a vocabulary." } ;
HELP: vocab-root
{ $values { "vocab" "a vocabulary specifier" } { "root" "a pathname string or " { $link f } } }
{ $description "Outputs the vocabulary root where the source code for a vocabulary is located, or " { $link f } " if the vocabulary is not defined in source files." } ;
HELP: vocab-words HELP: vocab-words
{ $values { "vocab" "a vocabulary specifier" } { "words" "an assoc mapping strings to words" } } { $values { "vocab" "a vocabulary specifier" } { "words" "an assoc mapping strings to words" } }
{ $description "Outputs the words defined in a vocabulary." } ; { $description "Outputs the words defined in a vocabulary." } ;
@ -101,11 +96,11 @@ HELP: child-vocabs
} ; } ;
HELP: vocab-link HELP: vocab-link
{ $class-description "Instances of this class identify vocabularies which are potentially not loaded. The " { $link vocab-name } " slot is the vocabulary name, and " { $link vocab-root } " is a pathname string identifying the vocabulary root where the sources to this vocabulary are located, or " { $link f } " if the root is not known." { $class-description "Instances of this class identify vocabularies which are potentially not loaded. The " { $link vocab-name } " slot is the vocabulary name."
$nl $nl
"Vocabulary links are created by calling " { $link >vocab-link } "." "Vocabulary links are created by calling " { $link >vocab-link } "."
} ; } ;
HELP: >vocab-link HELP: >vocab-link
{ $values { "name" string } { "root" "a pathname string or " { $link f } } { "vocab" "a vocabulary specifier" } } { $values { "name" string } { "vocab" "a vocabulary specifier" } }
{ $description "If the vocabulary is loaded, outputs the corresponding " { $link vocab } " instance, otherwise creates a new " { $link vocab-link } "." } ; { $description "If the vocabulary is loaded, outputs the corresponding " { $link vocab } " instance, otherwise creates a new " { $link vocab-link } "." } ;

View File

@ -92,10 +92,10 @@ SYMBOL: load-vocab-hook ! ( name -- )
: child-vocabs ( vocab -- seq ) : child-vocabs ( vocab -- seq )
vocab-name vocabs [ child-vocab? ] with subset ; vocab-name vocabs [ child-vocab? ] with subset ;
TUPLE: vocab-link name root ; TUPLE: vocab-link name ;
: <vocab-link> ( name root -- vocab-link ) : <vocab-link> ( name -- vocab-link )
[ dup vocab-root ] unless* vocab-link construct-boa ; vocab-link construct-boa ;
M: vocab-link equal? M: vocab-link equal?
over vocab-link? over vocab-link?
@ -106,17 +106,14 @@ M: vocab-link hashcode*
M: vocab-link vocab-name vocab-link-name ; M: vocab-link vocab-name vocab-link-name ;
GENERIC# >vocab-link 1 ( name root -- vocab )
M: vocab >vocab-link drop ;
M: vocab-link >vocab-link drop ;
M: string >vocab-link
over vocab dup [ 2nip ] [ drop <vocab-link> ] if ;
UNION: vocab-spec vocab vocab-link ; UNION: vocab-spec vocab vocab-link ;
GENERIC: >vocab-link ( name -- vocab )
M: vocab-spec >vocab-link ;
M: string >vocab-link dup vocab [ ] [ <vocab-link> ] ?if ;
: forget-vocab ( vocab -- ) : forget-vocab ( vocab -- )
dup words forget-all dup words forget-all
vocab-name dictionary get delete-at ; vocab-name dictionary get delete-at ;

View File

@ -135,18 +135,18 @@ SYMBOL: end
GENERIC: >ber ( obj -- byte-array ) GENERIC: >ber ( obj -- byte-array )
M: fixnum >ber ( n -- byte-array ) M: fixnum >ber ( n -- byte-array )
>128-ber dup length 2 swap 2array >128-ber dup length 2 swap 2array
"cc" pack-native swap append ; "cc" pack-native prepend ;
: >ber-enumerated ( n -- byte-array ) : >ber-enumerated ( n -- byte-array )
>128-ber >byte-array dup length 10 swap 2array >128-ber >byte-array dup length 10 swap 2array
"CC" pack-native swap append ; "CC" pack-native prepend ;
: >ber-length-encoding ( n -- byte-array ) : >ber-length-encoding ( n -- byte-array )
dup 127 <= [ dup 127 <= [
1array "C" pack-be 1array "C" pack-be
] [ ] [
1array "I" pack-be 0 swap remove dup length 1array "I" pack-be 0 swap remove dup length
HEX: 80 + 1array "C" pack-be swap append HEX: 80 + 1array "C" pack-be prepend
] if ; ] if ;
! ========================================================= ! =========================================================
@ -158,7 +158,7 @@ M: bignum >ber ( n -- byte-array )
dup 126 > [ dup 126 > [
"range error in bignum" throw "range error in bignum" throw
] [ ] [
2 swap 2array "CC" pack-native swap append 2 swap 2array "CC" pack-native prepend
] if ; ] if ;
! ========================================================= ! =========================================================

View File

@ -41,7 +41,7 @@ IN: assocs.lib
>r 2array flip r> assoc-like ; >r 2array flip r> assoc-like ;
: generate-key ( assoc -- str ) : generate-key ( assoc -- str )
>r random-256 >hex r> >r 256 random-bits >hex r>
2dup key? [ nip generate-key ] [ drop ] if ; 2dup key? [ nip generate-key ] [ drop ] if ;
: set-at-unique ( value assoc -- key ) : set-at-unique ( value assoc -- key )

View File

@ -46,7 +46,7 @@ dup >rule-number rule-values rule-keys [ rule> set-at ] 2each ;
: pattern>state ( {_a_b_c_} -- state ) rule> at ; : pattern>state ( {_a_b_c_} -- state ) rule> at ;
: cap-line ( line -- 0-line-0 ) { 0 } swap append { 0 } append ; : cap-line ( line -- 0-line-0 ) { 0 } prepend { 0 } append ;
: wrap-line ( a-line-z -- za-line-za ) : wrap-line ( a-line-z -- za-line-za )
dup peek 1array swap dup first 1array append append ; dup peek 1array swap dup first 1array append append ;

View File

@ -88,7 +88,7 @@ M: check< summary drop "Number exceeds upper bound" ;
>r keys r> define-slots ; >r keys r> define-slots ;
: define-setters ( classname slots -- ) : define-setters ( classname slots -- )
>r "with-" swap append r> >r "with-" prepend r>
dup values [setters] dup values [setters]
>r keys r> define-slots ; >r keys r> define-slots ;

View File

@ -18,7 +18,7 @@ bootstrap.image sequences io ;
: download-image ( arch -- ) : download-image ( arch -- )
boot-image-name dup need-new-image? [ boot-image-name dup need-new-image? [
"Downloading " write dup write "..." print "Downloading " write dup write "..." print
url swap append download url prepend download
] [ ] [
"Boot image up to date" print "Boot image up to date" print
drop drop

View File

@ -0,0 +1,8 @@
USING: vocabs.loader sequences system ;
"random.mersenne-twister" require
{
{ [ windows? ] [ "random.windows" require ] }
{ [ unix? ] [ "random.unix" require ] }
} cond

View File

@ -1,7 +1,7 @@
USING: kernel vocabs vocabs.loader sequences system ; USING: kernel vocabs vocabs.loader sequences system ;
{ "ui" "help" "tools" } { "ui" "help" "tools" }
[ "bootstrap." swap append vocab ] all? [ [ "bootstrap." prepend vocab ] all? [
"ui.tools" require "ui.tools" require
"ui.cocoa" vocab [ "ui.cocoa" vocab [

View File

@ -8,7 +8,7 @@ vocabs vocabs.loader ;
{ [ windows? ] [ "windows" ] } { [ windows? ] [ "windows" ] }
{ [ unix? ] [ "x11" ] } { [ unix? ] [ "x11" ] }
} cond } cond
] unless* "ui." swap append require ] unless* "ui." prepend require
"ui.freetype" require "ui.freetype" require
] when ] when

View File

@ -58,8 +58,8 @@ IN: builder
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: copy-image ( -- ) : copy-image ( -- )
builds "factor" path+ my-boot-image-name path+ ".." copy-file-into builds "factor" append-path my-boot-image-name append-path ".." copy-file-into
builds "factor" path+ my-boot-image-name path+ "." copy-file-into ; builds "factor" append-path my-boot-image-name append-path "." copy-file-into ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

View File

@ -8,7 +8,7 @@ IN: builder.release
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: releases ( -- path ) : releases ( -- path )
builds "releases" path+ builds "releases" append-path
dup exists? not dup exists? not
[ dup make-directory ] [ dup make-directory ]
when ; when ;

View File

@ -2,4 +2,4 @@ USING: kernel ;
IN: calendar.backend IN: calendar.backend
SYMBOL: calendar-backend SYMBOL: calendar-backend
HOOK: gmt-offset calendar-backend HOOK: gmt-offset calendar-backend ( -- hours minutes seconds )

View File

@ -2,14 +2,14 @@ USING: arrays calendar kernel math sequences tools.test
continuations system ; continuations system ;
IN: calendar.tests IN: calendar.tests
[ f ] [ 2004 12 32 0 0 0 0 <timestamp> valid-timestamp? ] unit-test [ f ] [ 2004 12 32 0 0 0 instant <timestamp> valid-timestamp? ] unit-test
[ f ] [ 2004 2 30 0 0 0 0 <timestamp> valid-timestamp? ] unit-test [ f ] [ 2004 2 30 0 0 0 instant <timestamp> valid-timestamp? ] unit-test
[ f ] [ 2003 2 29 0 0 0 0 <timestamp> valid-timestamp? ] unit-test [ f ] [ 2003 2 29 0 0 0 instant <timestamp> valid-timestamp? ] unit-test
[ f ] [ 2004 -2 9 0 0 0 0 <timestamp> valid-timestamp? ] unit-test [ f ] [ 2004 -2 9 0 0 0 instant <timestamp> valid-timestamp? ] unit-test
[ f ] [ 2004 12 0 0 0 0 0 <timestamp> valid-timestamp? ] unit-test [ f ] [ 2004 12 0 0 0 0 instant <timestamp> valid-timestamp? ] unit-test
[ f ] [ 2004 12 1 24 0 0 0 <timestamp> valid-timestamp? ] unit-test [ f ] [ 2004 12 1 24 0 0 instant <timestamp> valid-timestamp? ] unit-test
[ f ] [ 2004 12 1 23 60 0 0 <timestamp> valid-timestamp? ] unit-test [ f ] [ 2004 12 1 23 60 0 instant <timestamp> valid-timestamp? ] unit-test
[ f ] [ 2004 12 1 23 59 60 0 <timestamp> valid-timestamp? ] unit-test [ f ] [ 2004 12 1 23 59 60 instant <timestamp> valid-timestamp? ] unit-test
[ t ] [ now valid-timestamp? ] unit-test [ t ] [ now valid-timestamp? ] unit-test
[ f ] [ 1900 leap-year? ] unit-test [ f ] [ 1900 leap-year? ] unit-test
@ -18,126 +18,126 @@ IN: calendar.tests
[ f ] [ 2001 leap-year? ] unit-test [ f ] [ 2001 leap-year? ] unit-test
[ f ] [ 2006 leap-year? ] unit-test [ f ] [ 2006 leap-year? ] unit-test
[ t ] [ 2006 10 10 0 0 0 0 <timestamp> 1 seconds time+ [ t ] [ 2006 10 10 0 0 0 instant <timestamp> 1 seconds time+
2006 10 10 0 0 1 0 <timestamp> = ] unit-test 2006 10 10 0 0 1 instant <timestamp> = ] unit-test
[ t ] [ 2006 10 10 0 0 0 0 <timestamp> 100 seconds time+ [ t ] [ 2006 10 10 0 0 0 instant <timestamp> 100 seconds time+
2006 10 10 0 1 40 0 <timestamp> = ] unit-test 2006 10 10 0 1 40 instant <timestamp> = ] unit-test
[ t ] [ 2006 10 10 0 0 0 0 <timestamp> -100 seconds time+ [ t ] [ 2006 10 10 0 0 0 instant <timestamp> -100 seconds time+
2006 10 9 23 58 20 0 <timestamp> = ] unit-test 2006 10 9 23 58 20 instant <timestamp> = ] unit-test
[ t ] [ 2006 10 10 0 0 0 0 <timestamp> 86400 seconds time+ [ t ] [ 2006 10 10 0 0 0 instant <timestamp> 86400 seconds time+
2006 10 11 0 0 0 0 <timestamp> = ] unit-test 2006 10 11 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 10 10 0 0 0 0 <timestamp> 10 minutes time+ [ t ] [ 2006 10 10 0 0 0 instant <timestamp> 10 minutes time+
2006 10 10 0 10 0 0 <timestamp> = ] unit-test 2006 10 10 0 10 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 10 10 0 0 0 0 <timestamp> 10.5 minutes time+ [ t ] [ 2006 10 10 0 0 0 instant <timestamp> 10.5 minutes time+
2006 10 10 0 10 30 0 <timestamp> = ] unit-test 2006 10 10 0 10 30 instant <timestamp> = ] unit-test
[ t ] [ 2006 10 10 0 0 0 0 <timestamp> 3/4 minutes time+ [ t ] [ 2006 10 10 0 0 0 instant <timestamp> 3/4 minutes time+
2006 10 10 0 0 45 0 <timestamp> = ] unit-test 2006 10 10 0 0 45 instant <timestamp> = ] unit-test
[ t ] [ 2006 10 10 0 0 0 0 <timestamp> -3/4 minutes time+ [ t ] [ 2006 10 10 0 0 0 instant <timestamp> -3/4 minutes time+
2006 10 9 23 59 15 0 <timestamp> = ] unit-test 2006 10 9 23 59 15 instant <timestamp> = ] unit-test
[ t ] [ 2006 10 10 0 0 0 0 <timestamp> 7200 minutes time+ [ t ] [ 2006 10 10 0 0 0 instant <timestamp> 7200 minutes time+
2006 10 15 0 0 0 0 <timestamp> = ] unit-test 2006 10 15 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 10 10 0 0 0 0 <timestamp> -10 minutes time+ [ t ] [ 2006 10 10 0 0 0 instant <timestamp> -10 minutes time+
2006 10 9 23 50 0 0 <timestamp> = ] unit-test 2006 10 9 23 50 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 10 10 0 0 0 0 <timestamp> -100 minutes time+ [ t ] [ 2006 10 10 0 0 0 instant <timestamp> -100 minutes time+
2006 10 9 22 20 0 0 <timestamp> = ] unit-test 2006 10 9 22 20 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 1 hours time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 1 hours time+
2006 1 1 1 0 0 0 <timestamp> = ] unit-test 2006 1 1 1 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 24 hours time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 24 hours time+
2006 1 2 0 0 0 0 <timestamp> = ] unit-test 2006 1 2 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> -24 hours time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> -24 hours time+
2005 12 31 0 0 0 0 <timestamp> = ] unit-test 2005 12 31 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 12 hours time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 12 hours time+
2006 1 1 12 0 0 0 <timestamp> = ] unit-test 2006 1 1 12 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 72 hours time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 72 hours time+
2006 1 4 0 0 0 0 <timestamp> = ] unit-test 2006 1 4 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 1 days time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 1 days time+
2006 1 2 0 0 0 0 <timestamp> = ] unit-test 2006 1 2 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> -1 days time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> -1 days time+
2005 12 31 0 0 0 0 <timestamp> = ] unit-test 2005 12 31 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 365 days time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 365 days time+
2007 1 1 0 0 0 0 <timestamp> = ] unit-test 2007 1 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> -365 days time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> -365 days time+
2005 1 1 0 0 0 0 <timestamp> = ] unit-test 2005 1 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2004 1 1 0 0 0 0 <timestamp> 365 days time+ [ t ] [ 2004 1 1 0 0 0 instant <timestamp> 365 days time+
2004 12 31 0 0 0 0 <timestamp> = ] unit-test 2004 12 31 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2004 1 1 0 0 0 0 <timestamp> 366 days time+ [ t ] [ 2004 1 1 0 0 0 instant <timestamp> 366 days time+
2005 1 1 0 0 0 0 <timestamp> = ] unit-test 2005 1 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 11 months time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 11 months time+
2006 12 1 0 0 0 0 <timestamp> = ] unit-test 2006 12 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 12 months time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 12 months time+
2007 1 1 0 0 0 0 <timestamp> = ] unit-test 2007 1 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 24 months time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 24 months time+
2008 1 1 0 0 0 0 <timestamp> = ] unit-test 2008 1 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 13 months time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 13 months time+
2007 2 1 0 0 0 0 <timestamp> = ] unit-test 2007 2 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 1 months time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 1 months time+
2006 2 1 0 0 0 0 <timestamp> = ] unit-test 2006 2 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 0 months time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 0 months time+
2006 1 1 0 0 0 0 <timestamp> = ] unit-test 2006 1 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> -1 months time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> -1 months time+
2005 12 1 0 0 0 0 <timestamp> = ] unit-test 2005 12 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> -2 months time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> -2 months time+
2005 11 1 0 0 0 0 <timestamp> = ] unit-test 2005 11 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> -13 months time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> -13 months time+
2004 12 1 0 0 0 0 <timestamp> = ] unit-test 2004 12 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> -24 months time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> -24 months time+
2004 1 1 0 0 0 0 <timestamp> = ] unit-test 2004 1 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2004 2 29 0 0 0 0 <timestamp> 12 months time+ [ t ] [ 2004 2 29 0 0 0 instant <timestamp> 12 months time+
2005 3 1 0 0 0 0 <timestamp> = ] unit-test 2005 3 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2004 2 29 0 0 0 0 <timestamp> -12 months time+ [ t ] [ 2004 2 29 0 0 0 instant <timestamp> -12 months time+
2003 3 1 0 0 0 0 <timestamp> = ] unit-test 2003 3 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 0 years time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 0 years time+
2006 1 1 0 0 0 0 <timestamp> = ] unit-test 2006 1 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> 1 years time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> 1 years time+
2007 1 1 0 0 0 0 <timestamp> = ] unit-test 2007 1 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> -1 years time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> -1 years time+
2005 1 1 0 0 0 0 <timestamp> = ] unit-test 2005 1 1 0 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2006 1 1 0 0 0 0 <timestamp> -100 years time+ [ t ] [ 2006 1 1 0 0 0 instant <timestamp> -100 years time+
1906 1 1 0 0 0 0 <timestamp> = ] unit-test 1906 1 1 0 0 0 instant <timestamp> = ] unit-test
! [ t ] [ 2004 2 29 0 0 0 0 <timestamp> -1 years time+ ! [ t ] [ 2004 2 29 0 0 0 instant <timestamp> -1 years time+
! 2003 2 28 0 0 0 0 <timestamp> = ] unit-test ! 2003 2 28 0 0 0 instant <timestamp> = ] unit-test
[ 5 ] [ 2006 7 14 0 0 0 0 <timestamp> day-of-week ] unit-test [ 5 ] [ 2006 7 14 0 0 0 instant <timestamp> day-of-week ] unit-test
[ t ] [ 2006 7 14 [ julian-day-number julian-day-number>date 0 0 0 0 <timestamp> ] 3keep 0 0 0 0 <timestamp> = ] unit-test [ t ] [ 2006 7 14 [ julian-day-number julian-day-number>date 0 0 0 instant <timestamp> ] 3keep 0 0 0 instant <timestamp> = ] unit-test
[ 1 ] [ 2006 1 1 0 0 0 0 <timestamp> day-of-year ] unit-test [ 1 ] [ 2006 1 1 0 0 0 instant <timestamp> day-of-year ] unit-test
[ 60 ] [ 2004 2 29 0 0 0 0 <timestamp> day-of-year ] unit-test [ 60 ] [ 2004 2 29 0 0 0 instant <timestamp> day-of-year ] unit-test
[ 61 ] [ 2004 3 1 0 0 0 0 <timestamp> day-of-year ] unit-test [ 61 ] [ 2004 3 1 0 0 0 instant <timestamp> day-of-year ] unit-test
[ 366 ] [ 2004 12 31 0 0 0 0 <timestamp> day-of-year ] unit-test [ 366 ] [ 2004 12 31 0 0 0 instant <timestamp> day-of-year ] unit-test
[ 365 ] [ 2003 12 31 0 0 0 0 <timestamp> day-of-year ] unit-test [ 365 ] [ 2003 12 31 0 0 0 instant <timestamp> day-of-year ] unit-test
[ 60 ] [ 2003 3 1 0 0 0 0 <timestamp> day-of-year ] unit-test [ 60 ] [ 2003 3 1 0 0 0 instant <timestamp> day-of-year ] unit-test
[ t ] [ 2004 12 31 0 0 0 0 <timestamp> dup = ] unit-test [ t ] [ 2004 12 31 0 0 0 instant <timestamp> dup = ] unit-test
[ t ] [ 2004 1 1 0 0 0 0 <timestamp> 10 seconds 5 years time+ time+ [ t ] [ 2004 1 1 0 0 0 instant <timestamp> 10 seconds 5 years time+ time+
2009 1 1 0 0 10 0 <timestamp> = ] unit-test 2009 1 1 0 0 10 instant <timestamp> = ] unit-test
[ t ] [ 2004 1 1 0 0 0 0 <timestamp> -10 seconds -5 years time+ time+ [ t ] [ 2004 1 1 0 0 0 instant <timestamp> -10 seconds -5 years time+ time+
1998 12 31 23 59 50 0 <timestamp> = ] unit-test 1998 12 31 23 59 50 instant <timestamp> = ] unit-test
[ t ] [ 2004 1 1 23 0 0 12 <timestamp> 0 convert-timezone [ t ] [ 2004 1 1 23 0 0 12 hours <timestamp> >gmt
2004 1 1 11 0 0 0 <timestamp> = ] unit-test 2004 1 1 11 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2004 1 1 5 0 0 -11 <timestamp> 0 convert-timezone [ t ] [ 2004 1 1 5 0 0 -11 hours <timestamp> >gmt
2004 1 1 16 0 0 0 <timestamp> = ] unit-test 2004 1 1 16 0 0 instant <timestamp> = ] unit-test
[ t ] [ 2004 1 1 23 0 0 9+1/2 <timestamp> 0 convert-timezone [ t ] [ 2004 1 1 23 0 0 9+1/2 hours <timestamp> >gmt
2004 1 1 13 30 0 0 <timestamp> = ] unit-test 2004 1 1 13 30 0 instant <timestamp> = ] unit-test
[ 0 ] [ 2004 1 1 13 30 0 0 <timestamp> [ 0 ] [ 2004 1 1 13 30 0 instant <timestamp>
2004 1 1 12 30 0 -1 <timestamp> <=> ] unit-test 2004 1 1 12 30 0 -1 hours <timestamp> <=> ] unit-test
[ 1 ] [ 2004 1 1 13 30 0 0 <timestamp> [ 1 ] [ 2004 1 1 13 30 0 instant <timestamp>
2004 1 1 12 30 0 0 <timestamp> <=> ] unit-test 2004 1 1 12 30 0 instant <timestamp> <=> ] unit-test
[ -1 ] [ 2004 1 1 12 30 0 0 <timestamp> [ -1 ] [ 2004 1 1 12 30 0 instant <timestamp>
2004 1 1 13 30 0 0 <timestamp> <=> ] unit-test 2004 1 1 13 30 0 instant <timestamp> <=> ] unit-test
[ 1 ] [ 2005 1 1 12 30 0 0 <timestamp> [ 1 ] [ 2005 1 1 12 30 0 instant <timestamp>
2004 1 1 13 30 0 0 <timestamp> <=> ] unit-test 2004 1 1 13 30 0 instant <timestamp> <=> ] unit-test
[ t ] [ now timestamp>millis millis - 1000 < ] unit-test [ t ] [ now timestamp>millis millis - 1000 < ] unit-test
[ t ] [ 0 millis>timestamp unix-1970 = ] unit-test [ t ] [ 0 millis>timestamp unix-1970 = ] unit-test

View File

@ -3,20 +3,23 @@
USING: arrays kernel math math.functions namespaces sequences USING: arrays kernel math math.functions namespaces sequences
strings tuples system vocabs.loader calendar.backend threads strings tuples system vocabs.loader calendar.backend threads
new-slots accessors combinators ; new-slots accessors combinators locals ;
IN: calendar IN: calendar
TUPLE: timestamp year month day hour minute second gmt-offset ; TUPLE: timestamp year month day hour minute second gmt-offset ;
C: <timestamp> timestamp C: <timestamp> timestamp
: <date> ( year month day -- timestamp )
0 0 0 gmt-offset <timestamp> ;
TUPLE: duration year month day hour minute second ; TUPLE: duration year month day hour minute second ;
C: <duration> duration C: <duration> duration
: gmt-offset-duration ( -- duration )
0 0 0 gmt-offset <duration> ;
: <date> ( year month day -- timestamp )
0 0 0 gmt-offset-duration <timestamp> ;
: month-names : month-names
{ {
"Not a month" "January" "February" "March" "April" "May" "June" "Not a month" "January" "February" "March" "April" "May" "June"
@ -226,16 +229,18 @@ M: duration <=> [ dt>years ] compare ;
: dt>seconds ( dt -- x ) dt>years seconds-per-year * ; : dt>seconds ( dt -- x ) dt>years seconds-per-year * ;
: dt>milliseconds ( dt -- x ) dt>seconds 1000 * ; : dt>milliseconds ( dt -- x ) dt>seconds 1000 * ;
: convert-timezone ( timestamp n -- timestamp ) GENERIC: time- ( time1 time2 -- time )
: convert-timezone ( timestamp duration -- timestamp )
over gmt-offset>> over = [ drop ] [ over gmt-offset>> over = [ drop ] [
[ over gmt-offset>> - hours time+ ] keep >>gmt-offset [ over gmt-offset>> time- time+ ] keep >>gmt-offset
] if ; ] if ;
: >local-time ( timestamp -- timestamp ) : >local-time ( timestamp -- timestamp )
gmt-offset convert-timezone ; gmt-offset-duration convert-timezone ;
: >gmt ( timestamp -- timestamp ) : >gmt ( timestamp -- timestamp )
0 convert-timezone ; instant convert-timezone ;
M: timestamp <=> ( ts1 ts2 -- n ) M: timestamp <=> ( ts1 ts2 -- n )
[ >gmt tuple-slots ] compare ; [ >gmt tuple-slots ] compare ;
@ -245,8 +250,6 @@ M: timestamp <=> ( ts1 ts2 -- n )
[ [ >date< julian-day-number ] 2apply - 86400 * ] 2keep [ [ >date< julian-day-number ] 2apply - 86400 * ] 2keep
[ >time< >r >r 3600 * r> 60 * r> + + ] 2apply - + ; [ >time< >r >r 3600 * r> 60 * r> + + ] 2apply - + ;
GENERIC: time- ( time1 time2 -- time )
M: timestamp time- M: timestamp time-
#! Exact calendar-time difference #! Exact calendar-time difference
(time-) seconds ; (time-) seconds ;
@ -263,14 +266,14 @@ M: timestamp time-
M: duration time- M: duration time-
before time+ ; before time+ ;
: <zero> 0 0 0 0 0 0 0 <timestamp> ; : <zero> 0 0 0 0 0 0 instant <timestamp> ;
: valid-timestamp? ( timestamp -- ? ) : valid-timestamp? ( timestamp -- ? )
clone 0 >>gmt-offset clone instant >>gmt-offset
dup <zero> time- <zero> time+ = ; dup <zero> time- <zero> time+ = ;
: unix-1970 ( -- timestamp ) : unix-1970 ( -- timestamp )
1970 1 1 0 0 0 0 <timestamp> ; foldable 1970 1 1 0 0 0 instant <timestamp> ; foldable
: millis>timestamp ( n -- timestamp ) : millis>timestamp ( n -- timestamp )
>r unix-1970 r> milliseconds time+ ; >r unix-1970 r> milliseconds time+ ;

View File

@ -1,5 +1,6 @@
USING: calendar.format calendar kernel tools.test
io.streams.string ;
IN: calendar.format.tests IN: calendar.format.tests
USING: calendar.format tools.test io.streams.string ;
[ 0 ] [ [ 0 ] [
"Z" [ read-rfc3339-gmt-offset ] with-string-reader "Z" [ read-rfc3339-gmt-offset ] with-string-reader
@ -20,3 +21,6 @@ USING: calendar.format tools.test io.streams.string ;
[ 1+1/2 ] [ [ 1+1/2 ] [
"+01:30" [ read-rfc3339-gmt-offset ] with-string-reader "+01:30" [ read-rfc3339-gmt-offset ] with-string-reader
] unit-test ] unit-test
[ ] [ now timestamp>rfc3339 drop ] unit-test
[ ] [ now timestamp>rfc822 drop ] unit-test

View File

@ -1,6 +1,7 @@
IN: calendar.format
USING: math math.parser kernel sequences io calendar USING: math math.parser kernel sequences io calendar
accessors arrays io.streams.string combinators accessors ; accessors arrays io.streams.string combinators accessors
combinators.cleave ;
IN: calendar.format
GENERIC: day. ( obj -- ) GENERIC: day. ( obj -- )
@ -54,17 +55,17 @@ M: timestamp year. ( timestamp -- )
: timestamp>string ( timestamp -- str ) : timestamp>string ( timestamp -- str )
[ (timestamp>string) ] with-string-writer ; [ (timestamp>string) ] with-string-writer ;
: (write-gmt-offset) ( ratio -- ) : (write-gmt-offset) ( duration -- )
1 /mod swap write-00 60 * write-00 ; [ hour>> write-00 ] [ minute>> write-00 ] bi ;
: write-gmt-offset ( gmt-offset -- ) : write-gmt-offset ( gmt-offset -- )
{ dup instant <=> {
{ [ dup zero? ] [ drop "GMT" write ] } { [ dup 0 = ] [ 2drop "GMT" write ] }
{ [ dup 0 < ] [ "-" write neg (write-gmt-offset) ] } { [ dup 0 < ] [ drop "-" write before (write-gmt-offset) ] }
{ [ dup 0 > ] [ "+" write (write-gmt-offset) ] } { [ dup 0 > ] [ drop "+" write (write-gmt-offset) ] }
} cond ; } cond ;
: timestamp>rfc822-string ( timestamp -- str ) : timestamp>rfc822 ( timestamp -- str )
#! RFC822 timestamp format #! RFC822 timestamp format
#! Example: Tue, 15 Nov 1994 08:12:31 +0200 #! Example: Tue, 15 Nov 1994 08:12:31 +0200
[ [
@ -76,14 +77,19 @@ M: timestamp year. ( timestamp -- )
: timestamp>http-string ( timestamp -- str ) : timestamp>http-string ( timestamp -- str )
#! http timestamp format #! http timestamp format
#! Example: Tue, 15 Nov 1994 08:12:31 GMT #! Example: Tue, 15 Nov 1994 08:12:31 GMT
>gmt timestamp>rfc822-string ; >gmt timestamp>rfc822 ;
: write-rfc3339-gmt-offset ( n -- ) : (write-rfc3339-gmt-offset) ( duration -- )
dup zero? [ drop "Z" write ] [ [ hour>> write-00 CHAR: : write1 ]
dup 0 < [ CHAR: - write1 neg ] [ CHAR: + write1 ] if [ minute>> write-00 ] bi ;
60 * 60 /mod swap write-00 CHAR: : write1 write-00
] if ;
: write-rfc3339-gmt-offset ( duration -- )
dup instant <=> {
{ [ dup 0 = ] [ 2drop "Z" write ] }
{ [ dup 0 < ] [ drop CHAR: - write1 before (write-rfc3339-gmt-offset) ] }
{ [ dup 0 > ] [ drop CHAR: + write1 (write-rfc3339-gmt-offset) ] }
} cond ;
: (timestamp>rfc3339) ( timestamp -- ) : (timestamp>rfc3339) ( timestamp -- )
dup year>> number>string write CHAR: - write1 dup year>> number>string write CHAR: - write1
dup month>> write-00 CHAR: - write1 dup month>> write-00 CHAR: - write1

View File

@ -1,6 +1,5 @@
USING: alien alien.c-types arrays calendar.backend USING: alien alien.c-types arrays calendar.backend
kernel structs math unix.time namespaces ; kernel structs math unix.time namespaces ;
IN: calendar.unix IN: calendar.unix
@ -8,11 +7,11 @@ TUPLE: unix-calendar ;
T{ unix-calendar } calendar-backend set-global T{ unix-calendar } calendar-backend set-global
: get-time : get-time ( -- alien )
f time <uint> localtime ; f time <uint> localtime ;
: timezone-name : timezone-name ( -- string )
get-time tm-zone ; get-time tm-zone ;
M: unix-calendar gmt-offset M: unix-calendar gmt-offset ( -- hours minutes seconds )
get-time tm-gmtoff 3600 / ; get-time tm-gmtoff 3600 /mod 60 /mod ;

View File

@ -8,8 +8,14 @@ T{ windows-calendar } calendar-backend set-global
: TIME_ZONE_ID_INVALID HEX: ffffffff ; inline : TIME_ZONE_ID_INVALID HEX: ffffffff ; inline
M: windows-calendar gmt-offset ( -- float ) M: windows-calendar gmt-offset ( -- hours minutes seconds )
"TIME_ZONE_INFORMATION" <c-object> "TIME_ZONE_INFORMATION" <c-object>
dup GetTimeZoneInformation dup GetTimeZoneInformation {
TIME_ZONE_ID_INVALID = [ win32-error ] when { [ dup TIME_ZONE_ID_INVALID = ] [ win32-error ] }
TIME_ZONE_INFORMATION-Bias 60 / neg ; { [ dup { TIME_ZONE_ID_UNKNOWN TIME_ZONE_ID_STANDARD } member? ]
[ TIME_ZONE_INFORMATION-Bias 60 / neg ] }
{ [ dup TIME_ZONE_ID_DAYLIGHT = ] [
[ TIME_ZONE_INFORMATION-Bias 60 / neg ]
[ TIME_ZONE_INFORMATION-DaylightBias ] bi
] }
} cond ;

View File

@ -14,7 +14,7 @@ IN: channels.remote
PRIVATE> PRIVATE>
: publish ( channel -- id ) : publish ( channel -- id )
random-256 dup >r remote-channels set-at r> ; 256 random-bits dup >r remote-channels set-at r> ;
: get-channel ( id -- channel ) : get-channel ( id -- channel )
remote-channels at ; remote-channels at ;

View File

@ -59,7 +59,7 @@ objc-methods global [ H{ } assoc-like ] change-at
: lookup-method ( selector -- method ) : lookup-method ( selector -- method )
dup objc-methods get at dup objc-methods get at
[ ] [ "No such method: " swap append throw ] ?if ; [ ] [ "No such method: " prepend throw ] ?if ;
: make-dip ( quot n -- quot' ) : make-dip ( quot n -- quot' )
dup dup
@ -90,7 +90,7 @@ MACRO: (send) ( selector super? -- quot )
! Runtime introspection ! Runtime introspection
: (objc-class) ( string word -- class ) : (objc-class) ( string word -- class )
dupd execute dupd execute
[ ] [ "No such class: " swap append throw ] ?if ; inline [ ] [ "No such class: " prepend throw ] ?if ; inline
: objc-class ( string -- class ) : objc-class ( string -- class )
\ objc_getClass (objc-class) ; \ objc_getClass (objc-class) ;

View File

@ -54,6 +54,8 @@ MACRO: 2cleave ( seq -- )
: bi* ( x y p q -- p(x) q(y) ) >r swap slip r> call ; inline : bi* ( x y p q -- p(x) q(y) ) >r swap slip r> call ; inline
: 2bi* ( w x y z p q -- p(x) q(y) ) >r -rot 2slip r> call ; inline
: tri* ( x y z p q r -- p(x) q(y) r(z) ) : tri* ( x y z p q r -- p(x) q(y) r(z) )
>r rot >r bi* r> r> call ; inline >r rot >r bi* r> r> call ; inline
@ -68,7 +70,7 @@ MACRO: spread ( seq -- )
dup dup
[ drop [ >r ] ] map concat [ drop [ >r ] ] map concat
swap swap
[ [ r> ] swap append ] map concat [ [ r> ] prepend ] map concat
append ; append ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

View File

@ -8,13 +8,6 @@ continuations ;
IN: combinators.lib IN: combinators.lib
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: generate ( generator predicate -- obj )
#! Call 'generator' until the result satisfies 'predicate'.
[ slip over slip ] 2keep
roll [ 2drop ] [ rot drop generate ] if ; inline
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Generalized versions of core combinators ! Generalized versions of core combinators
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@ -82,11 +75,11 @@ MACRO: && ( quots -- ? )
[ [ not ] append [ f ] ] t short-circuit ; [ [ not ] append [ f ] ] t short-circuit ;
MACRO: <-&& ( quots -- ) MACRO: <-&& ( quots -- )
[ [ dup ] swap append [ not ] append [ f ] ] t short-circuit [ [ dup ] prepend [ not ] append [ f ] ] t short-circuit
[ nip ] append ; [ nip ] append ;
MACRO: <--&& ( quots -- ) MACRO: <--&& ( quots -- )
[ [ 2dup ] swap append [ not ] append [ f ] ] t short-circuit [ [ 2dup ] prepend [ not ] append [ f ] ] t short-circuit
[ 2nip ] append ; [ 2nip ] append ;
MACRO: || ( quots -- ? ) [ [ t ] ] f short-circuit ; MACRO: || ( quots -- ? ) [ [ t ] ] f short-circuit ;
@ -137,12 +130,12 @@ MACRO: map-call-with ( quots -- )
[ (make-call-with) ] keep length [ narray ] curry compose ; [ (make-call-with) ] keep length [ narray ] curry compose ;
: (make-call-with2) ( quots -- quot ) : (make-call-with2) ( quots -- quot )
[ [ 2dup >r >r ] swap append [ r> r> ] append ] map concat [ [ 2dup >r >r ] prepend [ r> r> ] append ] map concat
[ 2drop ] append ; [ 2drop ] append ;
MACRO: map-call-with2 ( quots -- ) MACRO: map-call-with2 ( quots -- )
[ [
[ [ 2dup >r >r ] swap append [ r> r> ] append ] map concat [ [ 2dup >r >r ] prepend [ r> r> ] append ] map concat
[ 2drop ] append [ 2drop ] append
] keep length [ narray ] curry append ; ] keep length [ narray ] curry append ;
@ -175,3 +168,10 @@ MACRO: multikeep ( word out-indexes -- ... )
: retry ( quot n -- ) : retry ( quot n -- )
[ drop ] rot compose attempt-all ; inline [ drop ] rot compose attempt-all ; inline
: do-while ( pred body tail -- )
>r tuck 2slip r> while ;
: generate ( generator predicate -- obj )
[ dup ] swap [ dup [ nip ] unless not ] 3compose
swap [ ] do-while ;

View File

@ -40,7 +40,7 @@ M: thread send ( message thread -- )
TUPLE: synchronous data sender tag ; TUPLE: synchronous data sender tag ;
: <synchronous> ( data -- sync ) : <synchronous> ( data -- sync )
self random-256 synchronous construct-boa ; self 256 random-bits synchronous construct-boa ;
TUPLE: reply data tag ; TUPLE: reply data tag ;

View File

@ -83,7 +83,7 @@ FUNCTION: void CFRelease ( void* cf ) ;
dup <CFBundle> [ dup <CFBundle> [
CFBundleLoadExecutable drop CFBundleLoadExecutable drop
] [ ] [
"Cannot load bundled named " swap append throw "Cannot load bundled named " prepend throw
] ?if ; ] ?if ;
FUNCTION: CFRunLoopRef CFRunLoopGetMain ( ) ; FUNCTION: CFRunLoopRef CFRunLoopGetMain ( ) ;

View File

@ -446,7 +446,7 @@ M: cpu reset ( cpu -- )
SYMBOL: rom-root SYMBOL: rom-root
: rom-dir ( -- string ) : rom-dir ( -- string )
rom-root get [ home "roms" path+ dup exists? [ drop f ] unless ] unless* ; rom-root get [ home "roms" append-path dup exists? [ drop f ] unless ] unless* ;
: load-rom* ( seq cpu -- ) : load-rom* ( seq cpu -- )
#! 'seq' is an array of arrays. Each array contains #! 'seq' is an array of arrays. Each array contains
@ -455,7 +455,7 @@ SYMBOL: rom-root
#! file path shoul dbe relative to the '/roms' resource path. #! file path shoul dbe relative to the '/roms' resource path.
rom-dir [ rom-dir [
cpu-ram [ cpu-ram [
swap first2 rom-dir swap path+ binary [ swap first2 rom-dir prepend-path binary [
swap (load-rom) swap (load-rom)
] with-file-reader ] with-file-reader
] curry each ] curry each
@ -1027,14 +1027,14 @@ SYMBOL: $4
8-bit-registers sp <&> 8-bit-registers sp <&>
"," token <& "," token <&
8-bit-registers <&> 8-bit-registers <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: ADC-R,(RR)-instruction ( -- parser ) : ADC-R,(RR)-instruction ( -- parser )
"ADC-R,(RR)" "ADC" complex-instruction "ADC-R,(RR)" "ADC" complex-instruction
8-bit-registers sp <&> 8-bit-registers sp <&>
"," token <& "," token <&
16-bit-registers indirect <&> 16-bit-registers indirect <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: SBC-R,N-instruction ( -- parser ) : SBC-R,N-instruction ( -- parser )
"SBC-R,N" "SBC" complex-instruction "SBC-R,N" "SBC" complex-instruction
@ -1047,14 +1047,14 @@ SYMBOL: $4
8-bit-registers sp <&> 8-bit-registers sp <&>
"," token <& "," token <&
8-bit-registers <&> 8-bit-registers <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: SBC-R,(RR)-instruction ( -- parser ) : SBC-R,(RR)-instruction ( -- parser )
"SBC-R,(RR)" "SBC" complex-instruction "SBC-R,(RR)" "SBC" complex-instruction
8-bit-registers sp <&> 8-bit-registers sp <&>
"," token <& "," token <&
16-bit-registers indirect <&> 16-bit-registers indirect <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: SUB-R-instruction ( -- parser ) : SUB-R-instruction ( -- parser )
"SUB-R" "SUB" complex-instruction "SUB-R" "SUB" complex-instruction
@ -1082,21 +1082,21 @@ SYMBOL: $4
8-bit-registers sp <&> 8-bit-registers sp <&>
"," token <& "," token <&
8-bit-registers <&> 8-bit-registers <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: ADD-RR,RR-instruction ( -- parser ) : ADD-RR,RR-instruction ( -- parser )
"ADD-RR,RR" "ADD" complex-instruction "ADD-RR,RR" "ADD" complex-instruction
16-bit-registers sp <&> 16-bit-registers sp <&>
"," token <& "," token <&
16-bit-registers <&> 16-bit-registers <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: ADD-R,(RR)-instruction ( -- parser ) : ADD-R,(RR)-instruction ( -- parser )
"ADD-R,(RR)" "ADD" complex-instruction "ADD-R,(RR)" "ADD" complex-instruction
8-bit-registers sp <&> 8-bit-registers sp <&>
"," token <& "," token <&
16-bit-registers indirect <&> 16-bit-registers indirect <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: LD-RR,NN-instruction : LD-RR,NN-instruction
#! LD BC,nn #! LD BC,nn
@ -1124,28 +1124,28 @@ SYMBOL: $4
16-bit-registers indirect sp <&> 16-bit-registers indirect sp <&>
"," token <& "," token <&
8-bit-registers <&> 8-bit-registers <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: LD-R,R-instruction : LD-R,R-instruction
"LD-R,R" "LD" complex-instruction "LD-R,R" "LD" complex-instruction
8-bit-registers sp <&> 8-bit-registers sp <&>
"," token <& "," token <&
8-bit-registers <&> 8-bit-registers <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: LD-RR,RR-instruction : LD-RR,RR-instruction
"LD-RR,RR" "LD" complex-instruction "LD-RR,RR" "LD" complex-instruction
16-bit-registers sp <&> 16-bit-registers sp <&>
"," token <& "," token <&
16-bit-registers <&> 16-bit-registers <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: LD-R,(RR)-instruction : LD-R,(RR)-instruction
"LD-R,(RR)" "LD" complex-instruction "LD-R,(RR)" "LD" complex-instruction
8-bit-registers sp <&> 8-bit-registers sp <&>
"," token <& "," token <&
16-bit-registers indirect <&> 16-bit-registers indirect <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: LD-(NN),RR-instruction : LD-(NN),RR-instruction
"LD-(NN),RR" "LD" complex-instruction "LD-(NN),RR" "LD" complex-instruction
@ -1194,14 +1194,14 @@ SYMBOL: $4
16-bit-registers indirect sp <&> 16-bit-registers indirect sp <&>
"," token <& "," token <&
16-bit-registers <&> 16-bit-registers <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: EX-RR,RR-instruction : EX-RR,RR-instruction
"EX-RR,RR" "EX" complex-instruction "EX-RR,RR" "EX" complex-instruction
16-bit-registers sp <&> 16-bit-registers sp <&>
"," token <& "," token <&
16-bit-registers <&> 16-bit-registers <&>
just [ first2 swap first2 swap >r swap append r> curry ] <@ ; just [ first2 swap first2 swap >r prepend r> curry ] <@ ;
: 8080-generator-parser : 8080-generator-parser
NOP-instruction NOP-instruction

View File

@ -1,36 +0,0 @@
USING: kernel math sequences namespaces crypto math-contrib ;
IN: crypto-internals
! TODO: take (log log M) bits instead of 1 bit
! Blum Blum Shub, M = pq
TUPLE: bbs x n ;
: generate-bbs-primes ( numbits -- p q )
#! two primes congruent to 3 (mod 4)
dup [ random-miller-rabin-prime==3(mod4) ] 2apply ;
IN: crypto
: make-bbs ( numbits -- blum-blum-shub )
#! returns a Blum-Blum-Shub tuple
generate-bbs-primes * [ find-relative-prime ] keep <bbs> ;
IN: crypto-internals
SYMBOL: blum-blum-shub 256 make-bbs blum-blum-shub set-global
: next-bbs-bit ( bbs -- bit )
#! x = x^2 mod n, return low bit of calculated x
[ [ bbs-x ] keep 2 swap bbs-n ^mod ] keep
[ set-bbs-x ] keep bbs-x 1 bitand ;
SYMBOL: temp-bbs
: (bbs-bits) ( numbits bbs -- n )
temp-bbs set [ [ temp-bbs get next-bbs-bit ] swap make-bits ] with-scope ;
IN: crypto
: random-bbs-bits* ( numbits bbs -- n ) (bbs-bits) ;
: random-bits ( numbits -- n ) blum-blum-shub get (bbs-bits) ;
: random-bytes ( numbits -- n ) 8 * random-bits ;
: random ( n -- n )
! #! Cryptographically secure random number using Blum-Blum-Shub 256
[ log2 1+ random-bits ] keep dupd >= [ -1 shift ] when ;

View File

@ -71,7 +71,7 @@ M: sqlite-statement bind-tuple ( tuple statement -- )
[ [
statement-in-params statement-in-params
[ [
[ sql-spec-column-name ":" swap append ] [ sql-spec-column-name ":" prepend ]
[ sql-spec-slot-name rot get-slot-named ] [ sql-spec-slot-name rot get-slot-named ]
[ sql-spec-type ] tri 3array [ sql-spec-type ] tri 3array
] with map ] with map
@ -173,7 +173,7 @@ M: sqlite-db <delete-tuple-statement> ( specs table -- sql )
! : select-sequence ( seq name -- ) ; ! : select-sequence ( seq name -- ) ;
M: sqlite-db bind% ( spec -- ) M: sqlite-db bind% ( spec -- )
dup 1, sql-spec-column-name ":" swap append 0% ; dup 1, sql-spec-column-name ":" prepend 0% ;
M: sqlite-db <select-by-slots-statement> ( tuple class -- statement ) M: sqlite-db <select-by-slots-statement> ( tuple class -- statement )
[ [

View File

@ -127,7 +127,7 @@ TUPLE: no-sql-modifier ;
: modifiers ( spec -- str ) : modifiers ( spec -- str )
sql-spec-modifiers sql-spec-modifiers
[ lookup-modifier ] map " " join [ lookup-modifier ] map " " join
dup empty? [ " " swap append ] unless ; dup empty? [ " " prepend ] unless ;
HOOK: bind% db ( spec -- ) HOOK: bind% db ( spec -- )

View File

@ -74,7 +74,7 @@ TUPLE: document locs ;
0 swap [ append ] change-nth ; 0 swap [ append ] change-nth ;
: append-last ( str seq -- ) : append-last ( str seq -- )
[ length 1- ] keep [ swap append ] change-nth ; [ length 1- ] keep [ prepend ] change-nth ;
: loc-col/str ( loc document -- str col ) : loc-col/str ( loc document -- str col )
>r first2 swap r> nth swap ; >r first2 swap r> nth swap ;

View File

@ -5,7 +5,7 @@ IN: editors.editpadpro
: editpadpro-path : editpadpro-path
\ editpadpro-path get-global [ \ editpadpro-path get-global [
program-files "JGsoft" path+ program-files "JGsoft" append-path
t [ >lower "editpadpro.exe" tail? ] find-file t [ >lower "editpadpro.exe" tail? ] find-file
] unless* ; ] unless* ;

View File

@ -4,7 +4,7 @@ IN: editors.editplus
: editplus-path ( -- path ) : editplus-path ( -- path )
\ editplus-path get-global [ \ editplus-path get-global [
program-files "\\EditPlus 2\\editplus.exe" path+ program-files "\\EditPlus 2\\editplus.exe" append-path
] unless* ; ] unless* ;
: editplus ( file line -- ) : editplus ( file line -- )

View File

@ -4,7 +4,7 @@ IN: editors.emeditor
: emeditor-path ( -- path ) : emeditor-path ( -- path )
\ emeditor-path get-global [ \ emeditor-path get-global [
program-files "\\EmEditor\\EmEditor.exe" path+ program-files "\\EmEditor\\EmEditor.exe" append-path
] unless* ; ] unless* ;
: emeditor ( file line -- ) : emeditor ( file line -- )

View File

@ -4,6 +4,6 @@ IN: editors.gvim.windows
M: windows-io gvim-path M: windows-io gvim-path
\ gvim-path get-global [ \ gvim-path get-global [
program-files "vim" path+ program-files "vim" append-path
t [ "gvim.exe" tail? ] find-file t [ "gvim.exe" tail? ] find-file
] unless* ; ] unless* ;

View File

@ -8,7 +8,7 @@ io.encodings.utf8 ;
IN: editors.jedit IN: editors.jedit
: jedit-server-info ( -- port auth ) : jedit-server-info ( -- port auth )
home "/.jedit/server" path+ ascii [ home "/.jedit/server" append-path ascii [
readln drop readln drop
readln string>number readln string>number
readln string>number readln string>number
@ -32,7 +32,7 @@ IN: editors.jedit
] with-stream ; ] with-stream ;
: jedit-location ( file line -- ) : jedit-location ( file line -- )
number>string "+line:" swap append 2array number>string "+line:" prepend 2array
make-jedit-request send-jedit-request ; make-jedit-request send-jedit-request ;
: jedit-file ( file -- ) : jedit-file ( file -- )

View File

@ -4,7 +4,7 @@ IN: editors.notepadpp
: notepadpp-path : notepadpp-path
\ notepadpp-path get-global [ \ notepadpp-path get-global [
program-files "notepad++\\notepad++.exe" path+ program-files "notepad++\\notepad++.exe" append-path
] unless* ; ] unless* ;
: notepadpp ( file line -- ) : notepadpp ( file line -- )

View File

@ -14,7 +14,7 @@ IN: editors.scite
: scite-path ( -- path ) : scite-path ( -- path )
\ scite-path get-global [ \ scite-path get-global [
program-files "wscite\\SciTE.exe" path+ program-files "wscite\\SciTE.exe" append-path
] unless* ; ] unless* ;
: scite-command ( file line -- cmd ) : scite-command ( file line -- cmd )

View File

@ -4,7 +4,7 @@ IN: editors.ted-notepad
: ted-notepad-path : ted-notepad-path
\ ted-notepad-path get-global [ \ ted-notepad-path get-global [
program-files "\\TED Notepad\\TedNPad.exe" path+ program-files "\\TED Notepad\\TedNPad.exe" append-path
] unless* ; ] unless* ;
: ted-notepad ( file line -- ) : ted-notepad ( file line -- )

View File

@ -5,7 +5,7 @@ IN: editors.ultraedit
: ultraedit-path ( -- path ) : ultraedit-path ( -- path )
\ ultraedit-path get-global [ \ ultraedit-path get-global [
program-files program-files
"\\IDM Computer Solutions\\UltraEdit-32\\uedit32.exe" path+ "\\IDM Computer Solutions\\UltraEdit-32\\uedit32.exe" append-path
] unless* ; ] unless* ;
: ultraedit ( file line -- ) : ultraedit ( file line -- )

View File

@ -5,7 +5,7 @@ IN: editors.wordpad
: wordpad-path ( -- path ) : wordpad-path ( -- path )
\ wordpad-path get [ \ wordpad-path get [
program-files "\\Windows NT\\Accessories\\wordpad.exe" path+ program-files "\\Windows NT\\Accessories\\wordpad.exe" append-path
] unless* ; ] unless* ;
: wordpad ( file line -- ) : wordpad ( file line -- )

View File

@ -79,7 +79,7 @@ C: <faq> faq
"br" contained, nl, ; "br" contained, nl, ;
: toc-link, ( question-list number -- ) : toc-link, ( question-list number -- )
number>string "#" swap append "href" swap 2array 1array number>string "#" prepend "href" swap 2array 1array
"a" swap [ question-list-title , ] tag*, br, ; "a" swap [ question-list-title , ] tag*, br, ;
: toc, ( faq -- ) : toc, ( faq -- )

View File

@ -98,7 +98,7 @@ M: word set-article-parent swap "help-parent" set-word-prop ;
: about ( vocab -- ) : about ( vocab -- )
dup require dup require
dup vocab [ ] [ dup vocab [ ] [
"No such vocabulary: " swap append throw "No such vocabulary: " prepend throw
] ?if ] ?if
dup vocab-help [ dup vocab-help [
help help

View File

@ -159,7 +159,7 @@ M: f print-element drop ;
[ first ($long-link) ] ($subsection) ; [ first ($long-link) ] ($subsection) ;
: ($vocab-link) ( text vocab -- ) : ($vocab-link) ( text vocab -- )
dup vocab-root >vocab-link write-link ; >vocab-link write-link ;
: $vocab-subsection ( element -- ) : $vocab-subsection ( element -- )
[ [

View File

@ -38,7 +38,7 @@ IN: html.elements
! <a =href a> "Click me" write </a> ! <a =href a> "Click me" write </a>
! !
! (url -- ) ! (url -- )
! <a "http://" swap append =href a> "click" write </a> ! <a "http://" prepend =href a> "click" write </a>
! !
! (url -- ) ! (url -- )
! <a [ "http://" % % ] "" make =href a> "click" write </a> ! <a [ "http://" % % ] "" make =href a> "click" write </a>
@ -72,7 +72,7 @@ SYMBOL: html
dup <foo> swap [ <foo> write-html ] curry dup <foo> swap [ <foo> write-html ] curry
empty-effect html-word ; empty-effect html-word ;
: <foo "<" swap append ; : <foo "<" prepend ;
: def-for-html-word-<foo ( name -- ) : def-for-html-word-<foo ( name -- )
#! Return the name and code for the <foo patterned #! Return the name and code for the <foo patterned
@ -134,7 +134,7 @@ SYMBOL: html
: attribute-effect T{ effect f { "string" } 0 } ; : attribute-effect T{ effect f { "string" } 0 } ;
: define-attribute-word ( name -- ) : define-attribute-word ( name -- )
dup "=" swap append swap dup "=" prepend swap
[ write-attr ] curry attribute-effect html-word ; [ write-attr ] curry attribute-effect html-word ;
[ [

View File

@ -12,7 +12,7 @@ DEFER: http-request
: parse-url ( url -- resource host port ) : parse-url ( url -- resource host port )
"http://" ?head [ "Only http:// supported" throw ] unless "http://" ?head [ "Only http:// supported" throw ] unless
"/" split1 [ "/" swap append ] [ "/" ] if* "/" split1 [ "/" prepend ] [ "/" ] if*
swap parse-host ; swap parse-host ;
: store-path ( request path -- request ) : store-path ( request path -- request )

View File

@ -27,8 +27,8 @@ blah
] unit-test ] unit-test
<action> <action>
[ +path+ get "xxx" get "X" <repetition> concat append ] >>submit [ +append-path get "xxx" get "X" <repetition> concat append ] >>submit
{ { +path+ [ ] } { "xxx" [ v-number ] } } >>post-params { { +append-path [ ] } { "xxx" [ v-number ] } } >>post-params
"action-2" set "action-2" set
STRING: action-request-test-2 STRING: action-request-test-2

View File

@ -5,7 +5,7 @@ http.server http.server.validators http hashtables namespaces
combinators.cleave fry continuations locals ; combinators.cleave fry continuations locals ;
IN: http.server.actions IN: http.server.actions
SYMBOL: +path+ SYMBOL: +append-path
SYMBOL: params SYMBOL: params
@ -40,7 +40,7 @@ TUPLE: action init display submit get-params post-params ;
M: action call-responder ( path action -- response ) M: action call-responder ( path action -- response )
'[ '[
, , , ,
[ +path+ associate request-params union params set ] [ +append-path associate request-params union params set ]
[ action set ] bi* [ action set ] bi*
request get method>> { request get method>> {
{ "GET" [ handle-get ] } { "GET" [ handle-get ] }

View File

@ -27,7 +27,7 @@ GENERIC: new-user ( user provider -- user/f )
user email>> length 0 > [ user email>> length 0 > [
user email>> email = [ user email>> email = [
user user
random-256 >hex >>ticket 256 random-bits >hex >>ticket
dup provider update-user dup provider update-user
] [ f ] if ] [ f ] if
] [ f ] if ] [ f ] if

View File

@ -13,7 +13,7 @@ TUPLE: component id required default ;
: component ( name -- component ) : component ( name -- component )
dup components get at dup components get at
[ ] [ "No such component: " swap append throw ] ?if ; [ ] [ "No such component: " prepend throw ] ?if ;
GENERIC: validate* ( value component -- result ) GENERIC: validate* ( value component -- result )
GENERIC: render-view* ( value component -- ) GENERIC: render-view* ( value component -- )

View File

@ -39,7 +39,7 @@ TUPLE: file-responder root hook special ;
[ 2drop <304> ] [ file-responder get hook>> call ] if ; [ 2drop <304> ] [ file-responder get hook>> call ] if ;
: serving-path ( filename -- filename ) : serving-path ( filename -- filename )
"" or file-responder get root>> swap path+ ; "" or file-responder get root>> prepend-path ;
: serve-file ( filename -- response ) : serve-file ( filename -- response )
dup mime-type dup mime-type
@ -68,7 +68,7 @@ TUPLE: file-responder root hook special ;
swap '[ , directory. ] >>body ; swap '[ , directory. ] >>body ;
: find-index ( filename -- path ) : find-index ( filename -- path )
{ "index.html" "index.fhtml" } [ path+ ] with map { "index.html" "index.fhtml" } [ append-path ] with map
[ exists? ] find nip ; [ exists? ] find nip ;
: serve-directory ( filename -- response ) : serve-directory ( filename -- response )

View File

@ -5,7 +5,7 @@ IN: http.server.templating.fhtml.tests
: test-template ( path -- ? ) : test-template ( path -- ? )
"resource:extra/http/server/templating/fhtml/test/" "resource:extra/http/server/templating/fhtml/test/"
swap append prepend
[ [
".fhtml" append [ run-template ] with-string-writer ".fhtml" append [ run-template ] with-string-writer
] keep ] keep

View File

@ -59,7 +59,7 @@ C: <validation-error> validation-error
: v-regexp ( str what regexp -- str ) : v-regexp ( str what regexp -- str )
>r over r> matches? >r over r> matches?
[ drop ] [ "invalid " swap append throw ] if ; [ drop ] [ "invalid " prepend throw ] if ;
: v-email ( str -- str ) : v-email ( str -- str )
#! From http://www.regular-expressions.info/email.html #! From http://www.regular-expressions.info/email.html

View File

@ -18,13 +18,13 @@ TUPLE: utf16 ;
over [ 8 shift bitor ] [ 2drop replacement-char ] if ; over [ 8 shift bitor ] [ 2drop replacement-char ] if ;
: double-be ( stream byte -- stream char ) : double-be ( stream byte -- stream char )
over stream-read1 swap append-nums ; over stream-read1 prepend-nums ;
: quad-be ( stream byte -- stream char ) : quad-be ( stream byte -- stream char )
double-be over stream-read1 [ double-be over stream-read1 [
dup -2 shift BIN: 110111 number= [ dup -2 shift BIN: 110111 number= [
>r 2 shift r> BIN: 11 bitand bitor >r 2 shift r> BIN: 11 bitand bitor
over stream-read1 swap append-nums HEX: 10000 + over stream-read1 prepend-nums HEX: 10000 +
] [ 2drop dup stream-read1 drop replacement-char ] if ] [ 2drop dup stream-read1 drop replacement-char ] if
] when* ; ] when* ;

View File

@ -24,7 +24,7 @@ PRIVATE>
: make-unique-file ( prefix suffix -- path stream ) : make-unique-file ( prefix suffix -- path stream )
temporary-path -rot temporary-path -rot
[ [
unique-length random-name swap 3append path+ unique-length random-name swap 3append append-path
dup (make-unique-file) dup (make-unique-file)
] 3curry unique-retries retry ; ] 3curry unique-retries retry ;
@ -36,7 +36,7 @@ PRIVATE>
: make-unique-directory ( -- path ) : make-unique-directory ( -- path )
[ [
temporary-path unique-length random-name path+ temporary-path unique-length random-name append-path
dup make-directory dup make-directory
] unique-retries retry ; ] unique-retries retry ;

View File

@ -5,7 +5,7 @@ IN: io.paths
TUPLE: directory-iterator path bfs queue ; TUPLE: directory-iterator path bfs queue ;
: qualified-directory ( path -- seq ) : qualified-directory ( path -- seq )
dup directory [ first2 >r path+ r> 2array ] with map ; dup directory [ first2 >r append-path r> 2array ] with map ;
: push-directory ( path iter -- ) : push-directory ( path iter -- )
>r qualified-directory r> [ >r qualified-directory r> [

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Slava Pestov, Doug Coleman ! Copyright (C) 2008 Slava Pestov, Doug Coleman
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel calendar alarms io.streams.duplex ; USING: kernel calendar alarms io.streams.duplex io.encodings ;
IN: io.timeouts IN: io.timeouts
! Won't need this with new slot accessors ! Won't need this with new slot accessors
@ -12,6 +12,10 @@ M: duplex-stream set-timeout
duplex-stream-in set-timeout duplex-stream-in set-timeout
duplex-stream-out set-timeout ; duplex-stream-out set-timeout ;
M: decoder set-timeout decoder-stream set-timeout ;
M: encoder set-timeout encoder-stream set-timeout ;
GENERIC: timed-out ( obj -- ) GENERIC: timed-out ( obj -- )
M: object timed-out drop ; M: object timed-out drop ;

View File

@ -32,9 +32,9 @@ M: windows-nt-io root-directory? ( path -- ? )
} && [ 2 head ] [ "Not an absolute path" throw ] if ; } && [ 2 head ] [ "Not an absolute path" throw ] if ;
: prepend-prefix ( string -- string' ) : prepend-prefix ( string -- string' )
unicode-prefix swap append ; unicode-prefix prepend ;
: windows-path+ ( cwd path -- newpath ) : windows-append-path ( cwd path -- newpath )
{ {
! empty ! empty
{ [ dup empty? ] [ drop ] } { [ dup empty? ] [ drop ] }
@ -43,7 +43,7 @@ M: windows-nt-io root-directory? ( path -- ? )
! \\\\?\\c:\\foo ! \\\\?\\c:\\foo
{ [ dup unicode-prefix head? ] [ nip ] } { [ dup unicode-prefix head? ] [ nip ] }
! ..\\foo ! ..\\foo
{ [ dup "..\\" head? ] [ >r parent-directory r> 3 tail windows-path+ ] } { [ dup "..\\" head? ] [ >r parent-directory r> 3 tail windows-append-path ] }
! .\\foo ! .\\foo
{ [ dup ".\\" head? ] [ 1 tail append prepend-prefix ] } { [ dup ".\\" head? ] [ 1 tail append prepend-prefix ] }
! \\foo ! \\foo
@ -62,7 +62,7 @@ M: windows-nt-io normalize-pathname ( string -- string )
dup string? [ "Pathname must be a string" throw ] unless dup string? [ "Pathname must be a string" throw ] unless
dup empty? [ "Empty pathname" throw ] when dup empty? [ "Empty pathname" throw ] when
{ { CHAR: / CHAR: \\ } } substitute { { CHAR: / CHAR: \\ } } substitute
cwd swap windows-path+ cwd swap windows-append-path
[ "/\\." member? ] right-trim [ "/\\." member? ] right-trim
dup peek CHAR: : = [ "\\" append ] when ; dup peek CHAR: : = [ "\\" append ] when ;

View File

@ -22,15 +22,15 @@ IN: io.windows.nt.tests
[ "\\\\?\\C:\\builds\\factor\\log.txt" ] [ [ "\\\\?\\C:\\builds\\factor\\log.txt" ] [
"C:\\builds\\factor\\12345\\" "C:\\builds\\factor\\12345\\"
"..\\log.txt" windows-path+ "..\\log.txt" windows-append-path
] unit-test ] unit-test
[ "\\\\?\\C:\\builds\\" ] [ [ "\\\\?\\C:\\builds\\" ] [
"C:\\builds\\factor\\12345\\" "C:\\builds\\factor\\12345\\"
"..\\.." windows-path+ "..\\.." windows-append-path
] unit-test ] unit-test
[ "\\\\?\\C:\\builds\\" ] [ [ "\\\\?\\C:\\builds\\" ] [
"C:\\builds\\factor\\12345\\" "C:\\builds\\factor\\12345\\"
"..\\.." windows-path+ "..\\.." windows-append-path
] unit-test ] unit-test

View File

@ -33,7 +33,7 @@ SYMBOL: terms
{ {
{ [ dup 1 = ] [ drop " + " ] } { [ dup 1 = ] [ drop " + " ] }
{ [ dup -1 = ] [ drop " - " ] } { [ dup -1 = ] [ drop " - " ] }
{ [ t ] [ number>string " + " swap append ] } { [ t ] [ number>string " + " prepend ] }
} cond ; } cond ;
: (alt.) ( basis n -- str ) : (alt.) ( basis n -- str )
@ -155,7 +155,7 @@ DEFER: (d)
: (tensor) ( seq1 seq2 -- seq ) : (tensor) ( seq1 seq2 -- seq )
[ [
[ swap append natural-sort ] curry map [ prepend natural-sort ] curry map
] with map concat ; ] with map concat ;
: tensor ( graded-basis1 graded-basis2 -- bigraded-basis ) : tensor ( graded-basis1 graded-basis2 -- bigraded-basis )
@ -202,7 +202,7 @@ DEFER: (d)
: bigraded-betti ( u-generators z-generators -- seq ) : bigraded-betti ( u-generators z-generators -- seq )
[ basis graded ] 2apply tensor bigraded-ker/im-d [ basis graded ] 2apply tensor bigraded-ker/im-d
[ [ [ first ] map ] map ] keep [ [ [ first ] map ] map ] keep
[ [ second ] map 2 head* { 0 0 } swap append ] map [ [ second ] map 2 head* { 0 0 } prepend ] map
1 tail dup first length 0 <array> add 1 tail dup first length 0 <array> add
[ v- ] 2map ; [ v- ] 2map ;

View File

@ -180,7 +180,7 @@ M: block lambda-rewrite*
#! Turn free variables into bound variables, curry them #! Turn free variables into bound variables, curry them
#! onto the body #! onto the body
dup free-vars [ <quote> ] map dup % [ dup free-vars [ <quote> ] map dup % [
over block-vars swap append over block-vars prepend
swap block-body [ [ lambda-rewrite* ] each ] [ ] make swap block-body [ [ lambda-rewrite* ] each ] [ ] make
swap point-free , swap point-free ,
] keep length \ curry <repetition> % ; ] keep length \ curry <repetition> % ;

View File

@ -11,10 +11,10 @@ IN: logging.server
\ log-root get "logs" resource-path or ; \ log-root get "logs" resource-path or ;
: log-path ( service -- path ) : log-path ( service -- path )
log-root swap path+ ; log-root prepend-path ;
: log# ( path n -- path' ) : log# ( path n -- path' )
number>string ".log" append path+ ; number>string ".log" append append-path ;
SYMBOL: log-files SYMBOL: log-files

View File

@ -12,4 +12,4 @@ IN: math.haar
2 group dup averages [ differences ] keep ; 2 group dup averages [ differences ] keep ;
: haar ( seq -- seq ) : haar ( seq -- seq )
dup length 1 <= [ haar-step haar swap append ] unless ; dup length 1 <= [ haar-step haar prepend ] unless ;

View File

@ -19,8 +19,6 @@ SYMBOL: trials
: next-odd ( m -- n ) : next-odd ( m -- n )
dup even? [ 1+ ] [ 2 + ] if ; dup even? [ 1+ ] [ 2 + ] if ;
: random-bits ( m -- n ) 2^ random ; foldable
TUPLE: positive-even-expected n ; TUPLE: positive-even-expected n ;
: (factor-2s) ( r s -- r s ) : (factor-2s) ( r s -- r s )

View File

@ -27,7 +27,7 @@ IN: new-slots
: setter-effect T{ effect f { "object" "value" } { "value" } } ; inline : setter-effect T{ effect f { "object" "value" } { "value" } } ; inline
: setter-word ( name -- word ) : setter-word ( name -- word )
">>" swap append setter-effect create-accessor ; ">>" prepend setter-effect create-accessor ;
: define-setter ( name -- ) : define-setter ( name -- )
dup setter-word dup deferred? [ dup setter-word dup deferred? [
@ -37,7 +37,7 @@ IN: new-slots
: changer-effect T{ effect f { "object" "quot" } { "object" } } ; inline : changer-effect T{ effect f { "object" "quot" } { "object" } } ; inline
: changer-word ( name -- word ) : changer-word ( name -- word )
"change-" swap append changer-effect create-accessor ; "change-" prepend changer-effect create-accessor ;
: define-changer ( name -- ) : define-changer ( name -- )
dup changer-word dup deferred? [ dup changer-word dup deferred? [

View File

@ -65,7 +65,7 @@ MATCH-VARS: ?a ?b ?c ;
M: #shuffle node>quot M: #shuffle node>quot
dup node-in-d over node-out-d pretty-shuffle dup node-in-d over node-out-d pretty-shuffle
[ , ] [ >r drop t r> ] if* [ , ] [ >r drop t r> ] if*
dup effect-str "#shuffle: " swap append comment, ; dup effect-str "#shuffle: " prepend comment, ;
: pushed-literals node-out-d [ value-literal literalize ] map ; : pushed-literals node-out-d [ value-literal literalize ] map ;

View File

@ -41,7 +41,7 @@ PRIVATE>
: fib-upto* ( n -- seq ) : fib-upto* ( n -- seq )
0 1 [ pick over >= ] [ tuck + dup ] [ ] unfold 3nip 0 1 [ pick over >= ] [ tuck + dup ] [ ] unfold 3nip
1 head-slice* { 0 1 } swap append ; 1 head-slice* { 0 1 } prepend ;
: euler002a ( -- answer ) : euler002a ( -- answer )
1000000 fib-upto* [ even? ] subset sum ; 1000000 fib-upto* [ even? ] subset sum ;

View File

@ -34,7 +34,7 @@ IN: project-euler.035
] if ; ] if ;
: rotate ( seq n -- seq ) : rotate ( seq n -- seq )
cut* swap append ; cut* prepend ;
: (circular?) ( seq n -- ? ) : (circular?) ( seq n -- ? )
dup 0 > [ dup 0 > [

View File

@ -30,7 +30,7 @@ IN: project-euler
number>string 3 CHAR: 0 pad-left ; number>string 3 CHAR: 0 pad-left ;
: solution-path ( n -- str/f ) : solution-path ( n -- str/f )
number>euler "project-euler." swap append number>euler "project-euler." prepend
vocab where dup [ first ?resource-path ] when ; vocab where dup [ first ?resource-path ] when ;
PRIVATE> PRIVATE>
@ -40,7 +40,7 @@ PRIVATE>
: run-project-euler ( -- ) : run-project-euler ( -- )
problem-prompt dup problem-solved? [ problem-prompt dup problem-solved? [
dup number>euler "project-euler." swap append run dup number>euler "project-euler." prepend run
"Answer: " swap dup number? [ number>string ] when append print "Answer: " swap dup number? [ number>string ] when append print
"Source: " swap solution-path append print "Source: " swap solution-path append print
] [ ] [

View File

@ -0,0 +1,36 @@
USING: kernel math sequences namespaces
math.miller-rabin combinators.cleave combinators.lib
math.functions new-slots accessors random ;
IN: random.blum-blum-shub
! TODO: take (log log M) bits instead of 1 bit
! Blum Blum Shub, M = pq
TUPLE: blum-blum-shub x n ;
C: <blum-blum-shub> blum-blum-shub
: generate-bbs-primes ( numbits -- p q )
#! two primes congruent to 3 (mod 4)
[ [ random-prime ] curry [ 4 mod 3 = ] generate ] dup bi ;
IN: crypto
: <blum-blum-shub> ( numbits -- blum-blum-shub )
#! returns a Blum-Blum-Shub tuple
generate-bbs-primes *
[ find-relative-prime ] keep
blum-blum-shub construct-boa ;
! 256 make-bbs blum-blum-shub set-global
: next-bbs-bit ( bbs -- bit )
#! x = x^2 mod n, return low bit of calculated x
[ [ x>> 2 ] [ n>> ] bi ^mod ]
[ [ >>x ] keep x>> 1 bitand ] bi ;
IN: crypto
! : random ( n -- n )
! ! #! Cryptographically secure random number using Blum-Blum-Shub 256
! [ log2 1+ random-bits ] keep dupd >= [ -1 shift ] when ;
M: blum-blum-shub random-32 ( bbs -- r )
;

View File

@ -0,0 +1,11 @@
USING: kernel random math new-slots accessors ;
IN: random.dummy
TUPLE: random-dummy i ;
C: <random-dummy> random-dummy
M: random-dummy seed-random ( seed obj -- )
(>>i) ;
M: random-dummy random-32 ( obj -- r )
[ dup 1+ ] change-i drop ;

View File

@ -1,17 +1,17 @@
USING: help.markup help.syntax math ; USING: help.markup help.syntax math ;
IN: random IN: random.mersenne-twister
ARTICLE: "random-numbers" "Generating random integers" ARTICLE: "random-numbers" "Generating random integers"
"The " { $vocab-link "random" } " vocabulary implements the ``Mersenne Twister'' pseudo-random number generator algorithm." "The " { $vocab-link "random" } " vocabulary implements the ``Mersenne Twister'' pseudo-random number generator algorithm."
{ $subsection init-random } ! { $subsection init-random }
{ $subsection (random) } { $subsection (random) }
{ $subsection random } ; { $subsection random } ;
ABOUT: "random-numbers" ABOUT: "random-numbers"
HELP: init-random ! HELP: init-random
{ $values { "seed" integer } } ! { $values { "seed" integer } }
{ $description "Initializes the random number generator with the given seed. This word is called on startup to initialize the random number generator with the current time." } ; ! { $description "Initializes the random number generator with the given seed. This word is called on startup to initialize the random number generator with the current time." } ;
HELP: (random) HELP: (random)
{ $values { "rand" "an integer between 0 and 2^32-1" } } { $values { "rand" "an integer between 0 and 2^32-1" } }

View File

@ -0,0 +1,30 @@
USING: kernel math random namespaces random.mersenne-twister
sequences tools.test ;
IN: random.mersenne-twister.tests
USE: tools.walker
: check-random ( max -- ? )
dup >r random 0 r> between? ;
[ t ] [ 100 [ drop 674 check-random ] all? ] unit-test
: make-100-randoms
[ 100 [ 100 random , ] times ] { } make ;
: test-rng ( seed quot -- )
>r <mersenne-twister> r> with-random ;
[ f ] [ 1234 [ make-100-randoms make-100-randoms = ] test-rng ] unit-test
[ 1333075495 ] [
0 [ 1000 [ drop \ random get random-32 drop ] each \ random get random-32 ] test-rng
] unit-test
[ 1575309035 ] [
0 [ 10000 [ drop \ random get random-32 drop ] each \ random get random-32 ] test-rng
] unit-test
[ 3 ] [ 101 [ 3 random-bytes length ] test-rng ] unit-test
[ 33 ] [ 101 [ 33 random-bytes length ] test-rng ] unit-test
[ t ] [ 101 [ 100 random-bits log2 90 > ] test-rng ] unit-test

View File

@ -0,0 +1,80 @@
! Copyright (C) 2005, 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
! mersenne twister based on
! http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c
USING: arrays kernel math namespaces sequences
system init new-slots accessors
math.ranges combinators.cleave circular random ;
IN: random.mersenne-twister
<PRIVATE
: new-nth ( seq i -- elt ) swap nth ; inline
: new-set-nth ( seq obj n -- seq ) pick set-nth ; inline
TUPLE: mersenne-twister seq i ;
: mt-n 624 ; inline
: mt-m 397 ; inline
: mt-a HEX: 9908b0df ; inline
: mt-hi HEX: 80000000 bitand ; inline
: mt-lo HEX: 7fffffff bitand ; inline
: wrap ( x n -- y ) 2dup >= [ - ] [ drop ] if ; inline
: mt-wrap ( x -- y ) mt-n wrap ; inline
: set-generated ( mt y from-elt to -- )
>r >r [ 2/ ] [ odd? mt-a 0 ? ] bi
r> bitxor bitxor r> new-set-nth drop ; inline
: calculate-y ( mt y1 y2 -- y )
>r over r>
[ new-nth mt-hi ] [ new-nth mt-lo ] 2bi* bitor ; inline
: (mt-generate) ( mt-seq n -- y to from-elt )
[ dup 1+ mt-wrap calculate-y ]
[ mt-m + mt-wrap new-nth ]
[ nip ] 2tri ;
: mt-generate ( mt -- )
[ seq>> mt-n [ dupd (mt-generate) set-generated ] with each ]
[ 0 >>i drop ] bi ;
: init-mt-first ( seed -- seq )
>r mt-n 0 <array> r>
HEX: ffffffff bitand 0 new-set-nth ;
: init-mt-formula ( seq i -- f(seq[i]) )
tuck new-nth dup -30 shift bitxor 1812433253 * +
1+ HEX: ffffffff bitand ;
: init-mt-rest ( seq -- )
mt-n 1- [0,b) [
dupd [ init-mt-formula ] keep 1+ new-set-nth drop
] with each ;
: init-mt-seq ( seed -- seq )
init-mt-first dup init-mt-rest ;
: mt-temper ( y -- yt )
dup -11 shift bitxor
dup 7 shift HEX: 9d2c5680 bitand bitxor
dup 15 shift HEX: efc60000 bitand bitxor
dup -18 shift bitxor ; inline
PRIVATE>
: <mersenne-twister> ( seed -- obj )
init-mt-seq 0 mersenne-twister construct-boa
dup mt-generate ;
M: mersenne-twister seed-random ( mt seed -- )
init-mt-seq >>seq drop ;
M: mersenne-twister random-32 ( mt -- r )
dup [ seq>> ] [ i>> ] bi
dup mt-n < [ drop 0 pick mt-generate ] unless
new-nth mt-temper
swap [ 1+ ] change-i drop ;
[ millis <mersenne-twister> \ random set-global ] "random" add-init-hook

View File

@ -1,15 +0,0 @@
USING: kernel math random namespaces sequences tools.test ;
IN: random.tests
: check-random ( max -- ? )
dup >r random 0 r> between? ;
[ t ] [ 100 [ drop 674 check-random ] all? ] unit-test
: make-100-randoms
[ 100 [ 100 random , ] times ] { } make ;
[ f ] [ make-100-randoms make-100-randoms = ] unit-test
[ 1333075495 ] [ 0 init-random 1000 [ drop (random) drop ] each (random) ] unit-test
[ 1575309035 ] [ 0 init-random 10000 [ drop (random) drop ] each (random) ] unit-test

112
extra/random/random.factor Executable file → Normal file
View File

@ -1,107 +1,39 @@
! Copyright (C) 2005, 2007 Doug Coleman. ! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types kernel math namespaces sequences
! mersenne twister based on io.backend ;
! http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c
USING: arrays kernel math namespaces sequences
system init alien.c-types ;
IN: random IN: random
<PRIVATE HOOK: os-crypto-random-bytes io-backend ( n -- byte-array )
HOOK: os-random-bytes io-backend ( n -- byte-array )
HOOK: os-crypto-random-32 io-backend ( -- r )
HOOK: os-random-32 io-backend ( -- r )
TUPLE: mersenne-twister seed seq i ; GENERIC: seed-random ( tuple seed -- )
GENERIC: random-32 ( tuple -- r )
C: <mersenne-twister> mersenne-twister : (random-bytes) ( tuple n -- byte-array )
[ drop random-32 ] with map >c-uint-array ;
: mt-n 624 ; inline DEFER: random
: mt-m 397 ; inline
: mt-a HEX: 9908b0df ; inline
: mt-hi HEX: 80000000 ; inline
: mt-lo HEX: 7fffffff ; inline
SYMBOL: mt : random-bytes ( n -- r )
[
4 /mod zero? [ 1+ ] unless
\ random get swap (random-bytes)
] keep head ;
: mt-seq ( -- seq ) : random-bits ( n -- r ) 2^ random ;
mt get mersenne-twister-seq ; inline
: mt-nth ( n -- nth )
mt-seq nth ; inline
: mt-i ( -- i )
mt get mersenne-twister-i ; inline
: mti-inc ( -- )
mt get [ mersenne-twister-i 1+ ] keep set-mersenne-twister-i ; inline
: set-mt-ith ( y i-get i-set -- )
>r mt-nth >r
[ 2/ ] keep odd? mt-a 0 ? r> bitxor bitxor r>
mt-seq set-nth ; inline
: mt-y ( y1 y2 -- y )
mt-nth mt-lo bitand
>r mt-nth mt-hi bitand r> bitor ; inline
: mod* ( x n -- y )
#! no floating point
2dup >= [ - ] [ drop ] if ; inline
: (mt-generate) ( n -- y n n+(mt-m) )
dup [ 1+ 624 mod* mt-y ] keep [ mt-m + 624 mod* ] keep ;
: mt-generate ( -- )
mt-n [ (mt-generate) set-mt-ith ] each
0 mt get set-mersenne-twister-i ;
: init-mt-first ( seed -- seq )
>r mt-n 0 <array> r>
HEX: ffffffff bitand 0 pick set-nth ;
: init-mt-formula ( seq i -- f(seq[i]) )
dup rot nth dup -30 shift bitxor
1812433253 * + HEX: ffffffff bitand 1+ ; inline
: init-mt-rest ( seq -- )
mt-n 1 head* [
[ init-mt-formula ] 2keep 1+ swap set-nth
] with each ;
: mt-temper ( y -- yt )
dup -11 shift bitxor
dup 7 shift HEX: 9d2c5680 bitand bitxor
dup 15 shift HEX: efc60000 bitand bitxor
dup -18 shift bitxor ; inline
PRIVATE>
: init-random ( seed -- )
global [
dup init-mt-first
[ init-mt-rest ] keep
0 <mersenne-twister> mt set
mt-generate
] bind ;
: (random) ( -- rand )
global [
mt-i dup mt-n < [ drop mt-generate 0 ] unless
mt-nth mti-inc
mt-temper
] bind ;
: big-random ( n -- r )
[ drop (random) ] map >c-uint-array byte-array>bignum ;
: random-256 ( -- r ) 8 big-random ; inline
: random ( seq -- elt ) : random ( seq -- elt )
dup empty? [ dup empty? [
drop f drop f
] [ ] [
[ [
length dup log2 31 + 32 /i big-random swap mod length dup log2 7 + 8 /i
random-bytes byte-array>bignum swap mod
] keep nth ] keep nth
] if ; ] if ;
[ millis init-random ] "random" add-init-hook : with-random ( tuple quot -- )
\ random swap with-variable ; inline

View File

@ -0,0 +1,22 @@
USING: alien.c-types io io.files io.nonblocking kernel
namespaces random io.encodings.binary singleton ;
IN: random.unix
SINGLETON: unix-random
: file-read-unbuffered ( n path -- bytes )
over default-buffer-size [
binary <file-reader> [ read ] with-stream
] with-variable ;
M: unix-random os-crypto-random-bytes ( n -- byte-array )
"/dev/random" file-read-unbuffered ;
M: unix-random os-random-bytes ( n -- byte-array )
"/dev/urandom" file-read-unbuffered ;
M: unix-random os-crypto-random-32 ( -- r )
4 os-crypto-random-bytes *uint ;
M: unix-random os-random-32 ( -- r )
4 os-random-bytes *uint ;

View File

@ -0,0 +1,3 @@
IN: random.windows
! M: windows-io

View File

@ -31,7 +31,7 @@ LOG: log-smtp-connection NOTICE ( addrspec -- )
: validate-address ( string -- string' ) : validate-address ( string -- string' )
#! Make sure we send funky stuff to the server by accident. #! Make sure we send funky stuff to the server by accident.
dup "\r\n>" seq-intersect empty? dup "\r\n>" seq-intersect empty?
[ "Bad e-mail address: " swap append throw ] unless ; [ "Bad e-mail address: " prepend throw ] unless ;
: mail-from ( fromaddr -- ) : mail-from ( fromaddr -- )
"MAIL FROM:<" write validate-address write ">" write crlf ; "MAIL FROM:<" write validate-address write ">" write crlf ;
@ -89,7 +89,7 @@ LOG: smtp-response DEBUG
: validate-header ( string -- string' ) : validate-header ( string -- string' )
dup "\r\n" seq-intersect empty? dup "\r\n" seq-intersect empty?
[ "Invalid header string: " swap append throw ] unless ; [ "Invalid header string: " prepend throw ] unless ;
: write-header ( key value -- ) : write-header ( key value -- )
swap swap
@ -143,7 +143,7 @@ M: email clone
dup to>> ", " join "To" set-header dup to>> ", " join "To" set-header
[ [ extract-email ] map ] change-to [ [ extract-email ] map ] change-to
dup subject>> "Subject" set-header dup subject>> "Subject" set-header
now timestamp>rfc822-string "Date" set-header now timestamp>rfc822 "Date" set-header
message-id "Message-Id" set-header ; message-id "Message-Id" set-header ;
: <email> ( -- email ) : <email> ( -- email )
@ -164,7 +164,7 @@ M: email clone
! : (cram-md5-auth) ( -- response ) ! : (cram-md5-auth) ( -- response )
! swap challenge get ! swap challenge get
! string>md5-hmac hex-string ! string>md5-hmac hex-string
! " " swap append append ! " " prepend append
! >base64 ; ! >base64 ;
! !
! : cram-md5-auth ( key login -- ) ! : cram-md5-auth ( key login -- )

View File

@ -7,7 +7,7 @@ IN: strings.lib
: >Upper ( str -- str ) : >Upper ( str -- str )
dup empty? [ dup empty? [
unclip ch>upper 1string swap append unclip ch>upper 1string prepend
] unless ; ] unless ;
: >Upper-dashes ( str -- str ) : >Upper-dashes ( str -- str )

Some files were not shown because too many files have changed in this diff Show More