Merge OneEyed's patch
commit
25a877e50b
|
@ -78,7 +78,7 @@ M: bit-array byte-length length 7 + -3 shift ;
|
||||||
[ dup 0 = ] [
|
[ dup 0 = ] [
|
||||||
[ pick underlying>> pick set-alien-unsigned-1 ] keep
|
[ pick underlying>> pick set-alien-unsigned-1 ] keep
|
||||||
[ 1+ ] [ -8 shift ] bi*
|
[ 1+ ] [ -8 shift ] bi*
|
||||||
] [ ] until 2drop
|
] until 2drop
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: bit-array>integer ( bit-array -- n )
|
: bit-array>integer ( bit-array -- n )
|
||||||
|
|
|
@ -240,7 +240,7 @@ GENERIC: ' ( obj -- ptr )
|
||||||
#! n is positive or zero.
|
#! n is positive or zero.
|
||||||
[ dup 0 > ]
|
[ dup 0 > ]
|
||||||
[ [ bignum-bits neg shift ] [ bignum-radix bitand ] bi ]
|
[ [ bignum-bits neg shift ] [ bignum-radix bitand ] bi ]
|
||||||
[ ] produce nip ;
|
produce nip ;
|
||||||
|
|
||||||
: emit-bignum ( n -- )
|
: emit-bignum ( n -- )
|
||||||
dup dup 0 < [ neg ] when bignum>seq
|
dup dup 0 < [ neg ] when bignum>seq
|
||||||
|
|
|
@ -441,7 +441,7 @@ TUPLE: mixed-mutable-immutable { x integer } { y sequence read-only } ;
|
||||||
|
|
||||||
[ V{ real } ] [ [ recursive-test-3 ] final-classes ] unit-test
|
[ V{ real } ] [ [ recursive-test-3 ] final-classes ] unit-test
|
||||||
|
|
||||||
[ V{ real } ] [ [ [ dup 10 < ] [ ] [ ] while ] final-classes ] unit-test
|
[ V{ real } ] [ [ [ dup 10 < ] [ ] while ] final-classes ] unit-test
|
||||||
|
|
||||||
[ V{ float } ] [
|
[ V{ float } ] [
|
||||||
[ { float } declare 10 [ 2.3 * ] times ] final-classes
|
[ { float } declare 10 [ 2.3 * ] times ] final-classes
|
||||||
|
|
|
@ -51,13 +51,13 @@ M: mailbox dispose* threads>> notify-all ;
|
||||||
block-if-empty
|
block-if-empty
|
||||||
[ dup mailbox-empty? ]
|
[ dup mailbox-empty? ]
|
||||||
[ dup data>> pop-back ]
|
[ dup data>> pop-back ]
|
||||||
[ ] produce nip ;
|
produce nip ;
|
||||||
|
|
||||||
: mailbox-get-all ( mailbox -- array )
|
: mailbox-get-all ( mailbox -- array )
|
||||||
f mailbox-get-all-timeout ;
|
f mailbox-get-all-timeout ;
|
||||||
|
|
||||||
: while-mailbox-empty ( mailbox quot -- )
|
: while-mailbox-empty ( mailbox quot -- )
|
||||||
[ '[ _ mailbox-empty? ] ] dip [ ] while ; inline
|
[ '[ _ mailbox-empty? ] ] dip while ; inline
|
||||||
|
|
||||||
: mailbox-get-timeout? ( mailbox timeout pred -- obj )
|
: mailbox-get-timeout? ( mailbox timeout pred -- obj )
|
||||||
[ block-unless-pred ]
|
[ block-unless-pred ]
|
||||||
|
|
|
@ -36,6 +36,6 @@ GENERIC: deque-empty? ( deque -- ? )
|
||||||
: slurp-deque ( deque quot -- )
|
: slurp-deque ( deque quot -- )
|
||||||
[ drop '[ _ deque-empty? not ] ]
|
[ drop '[ _ deque-empty? not ] ]
|
||||||
[ '[ _ pop-back @ ] ]
|
[ '[ _ pop-back @ ] ]
|
||||||
2bi [ ] while ; inline
|
2bi while ; inline
|
||||||
|
|
||||||
MIXIN: deque
|
MIXIN: deque
|
||||||
|
|
|
@ -27,7 +27,6 @@ M: winnt (os-envs) ( -- seq )
|
||||||
GetEnvironmentStrings [
|
GetEnvironmentStrings [
|
||||||
<memory-stream> [
|
<memory-stream> [
|
||||||
utf16n decode-input
|
utf16n decode-input
|
||||||
[ "\0" read-until drop dup empty? not ]
|
[ "\0" read-until drop dup empty? not ] [ ] produce nip
|
||||||
[ ] [ drop ] produce
|
|
||||||
] with-input-stream*
|
] with-input-stream*
|
||||||
] [ FreeEnvironmentStrings win32-error=0/f ] bi ;
|
] [ FreeEnvironmentStrings win32-error=0/f ] bi ;
|
||||||
|
|
|
@ -41,7 +41,7 @@ IN: formatting
|
||||||
[ dup 10.0 >=
|
[ dup 10.0 >=
|
||||||
[ 10.0 / [ 1+ ] dip ]
|
[ 10.0 / [ 1+ ] dip ]
|
||||||
[ 10.0 * [ 1- ] dip ] if
|
[ 10.0 * [ 1- ] dip ] if
|
||||||
] [ ] while
|
] while
|
||||||
] keep 0 < [ neg ] when ;
|
] keep 0 < [ neg ] when ;
|
||||||
|
|
||||||
: exp>string ( exp base digits -- string )
|
: exp>string ( exp base digits -- string )
|
||||||
|
|
|
@ -190,7 +190,7 @@ M: heap heap-pop ( heap -- value key )
|
||||||
: heap-pop-all ( heap -- alist )
|
: heap-pop-all ( heap -- alist )
|
||||||
[ dup heap-empty? not ]
|
[ dup heap-empty? not ]
|
||||||
[ dup heap-pop swap 2array ]
|
[ dup heap-pop swap 2array ]
|
||||||
[ ] produce nip ;
|
produce nip ;
|
||||||
|
|
||||||
: slurp-heap ( heap quot: ( elt -- ) -- )
|
: slurp-heap ( heap quot: ( elt -- ) -- )
|
||||||
over heap-empty? [ 2drop ] [
|
over heap-empty? [ 2drop ] [
|
||||||
|
|
|
@ -96,8 +96,6 @@ M: object specializer-declaration class ;
|
||||||
{ string string }
|
{ string string }
|
||||||
"specializer" set-word-prop
|
"specializer" set-word-prop
|
||||||
|
|
||||||
\ find-last-sep { string sbuf } "specializer" set-word-prop
|
|
||||||
|
|
||||||
\ >string { sbuf } "specializer" set-word-prop
|
\ >string { sbuf } "specializer" set-word-prop
|
||||||
|
|
||||||
\ >array { { vector } } "specializer" set-word-prop
|
\ >array { { vector } } "specializer" set-word-prop
|
||||||
|
|
|
@ -12,7 +12,7 @@ base64 ;
|
||||||
IN: http
|
IN: http
|
||||||
|
|
||||||
: (read-header) ( -- alist )
|
: (read-header) ( -- alist )
|
||||||
[ read-crlf dup f like ] [ parse-header-line ] [ drop ] produce ;
|
[ read-crlf dup f like ] [ parse-header-line ] produce nip ;
|
||||||
|
|
||||||
: collect-headers ( assoc -- assoc' )
|
: collect-headers ( assoc -- assoc' )
|
||||||
H{ } clone [ '[ _ push-at ] assoc-each ] keep ;
|
H{ } clone [ '[ _ push-at ] assoc-each ] keep ;
|
||||||
|
|
|
@ -61,5 +61,5 @@ M: unix (directory-entries) ( path -- seq )
|
||||||
[
|
[
|
||||||
'[ _ find-next-file dup ]
|
'[ _ find-next-file dup ]
|
||||||
[ >directory-entry ]
|
[ >directory-entry ]
|
||||||
[ drop ] produce
|
produce nip
|
||||||
] with-unix-directory ;
|
] with-unix-directory ;
|
||||||
|
|
|
@ -61,7 +61,7 @@ M: windows (directory-entries) ( path -- seq )
|
||||||
'[
|
'[
|
||||||
[ _ find-next-file dup ]
|
[ _ find-next-file dup ]
|
||||||
[ >directory-entry ]
|
[ >directory-entry ]
|
||||||
[ drop ] produce
|
produce nip
|
||||||
over name>> "." = [ nip ] [ swap prefix ] if
|
over name>> "." = [ nip ] [ swap prefix ] if
|
||||||
]
|
]
|
||||||
] [ '[ _ FindClose win32-error=0/f ] ] bi [ ] cleanup ;
|
] [ '[ _ FindClose win32-error=0/f ] ] bi [ ] cleanup ;
|
||||||
|
|
|
@ -159,9 +159,7 @@ M: winnt file-system-info ( path -- file-system-info )
|
||||||
find-first-volume
|
find-first-volume
|
||||||
[
|
[
|
||||||
'[
|
'[
|
||||||
[ _ find-next-volume dup ]
|
[ _ find-next-volume dup ] [ ] produce nip
|
||||||
[ ]
|
|
||||||
[ drop ] produce
|
|
||||||
swap prefix
|
swap prefix
|
||||||
]
|
]
|
||||||
] [ '[ _ FindVolumeClose win32-error=0/f ] ] bi [ ] cleanup ;
|
] [ '[ _ FindVolumeClose win32-error=0/f ] ] bi [ ] cleanup ;
|
||||||
|
|
|
@ -101,13 +101,13 @@ os { winnt linux macosx } member? [
|
||||||
! Non-recursive
|
! Non-recursive
|
||||||
[ ] [ "monitor-timeout-test" temp-file f <monitor> "m" set ] unit-test
|
[ ] [ "monitor-timeout-test" temp-file f <monitor> "m" set ] unit-test
|
||||||
[ ] [ 3 seconds "m" get set-timeout ] unit-test
|
[ ] [ 3 seconds "m" get set-timeout ] unit-test
|
||||||
[ [ t ] [ "m" get next-change drop ] [ ] while ] must-fail
|
[ [ t ] [ "m" get next-change drop ] while ] must-fail
|
||||||
[ ] [ "m" get dispose ] unit-test
|
[ ] [ "m" get dispose ] unit-test
|
||||||
|
|
||||||
! Recursive
|
! Recursive
|
||||||
[ ] [ "monitor-timeout-test" temp-file t <monitor> "m" set ] unit-test
|
[ ] [ "monitor-timeout-test" temp-file t <monitor> "m" set ] unit-test
|
||||||
[ ] [ 3 seconds "m" get set-timeout ] unit-test
|
[ ] [ 3 seconds "m" get set-timeout ] unit-test
|
||||||
[ [ t ] [ "m" get next-change drop ] [ ] while ] must-fail
|
[ [ t ] [ "m" get next-change drop ] while ] must-fail
|
||||||
[ ] [ "m" get dispose ] unit-test
|
[ ] [ "m" get dispose ] unit-test
|
||||||
] with-monitors
|
] with-monitors
|
||||||
] when
|
] when
|
||||||
|
|
|
@ -35,7 +35,7 @@ GENERIC: make-connection ( pool -- conn )
|
||||||
|
|
||||||
: acquire-connection ( pool -- conn )
|
: acquire-connection ( pool -- conn )
|
||||||
dup check-pool
|
dup check-pool
|
||||||
[ dup connections>> empty? ] [ dup new-connection ] [ ] while
|
[ dup connections>> empty? ] [ dup new-connection ] while
|
||||||
connections>> pop ;
|
connections>> pop ;
|
||||||
|
|
||||||
: (with-pooled-connection) ( conn pool quot -- )
|
: (with-pooled-connection) ( conn pool quot -- )
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
! Copyright (C) 2008, 2009 Daniel Ehrenberg
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: byte-arrays byte-vectors kernel io.encodings io.streams.string
|
USING: byte-arrays byte-vectors kernel io.encodings io.streams.string
|
||||||
sequences io namespaces io.encodings.private accessors ;
|
sequences io namespaces io.encodings.private accessors sequences.private
|
||||||
|
io.streams.sequence destructors ;
|
||||||
IN: io.streams.byte-array
|
IN: io.streams.byte-array
|
||||||
|
|
||||||
: <byte-writer> ( encoding -- stream )
|
: <byte-writer> ( encoding -- stream )
|
||||||
|
@ -9,8 +12,16 @@ IN: io.streams.byte-array
|
||||||
[ <byte-writer> ] dip [ output-stream get ] compose with-output-stream*
|
[ <byte-writer> ] dip [ output-stream get ] compose with-output-stream*
|
||||||
dup encoder? [ stream>> ] when >byte-array ; inline
|
dup encoder? [ stream>> ] when >byte-array ; inline
|
||||||
|
|
||||||
|
TUPLE: byte-reader { underlying byte-array read-only } { i array-capacity } ;
|
||||||
|
|
||||||
|
M: byte-reader stream-read-partial stream-read ;
|
||||||
|
M: byte-reader stream-read sequence-read ;
|
||||||
|
M: byte-reader stream-read1 sequence-read1 ;
|
||||||
|
M: byte-reader stream-read-until sequence-read-until ;
|
||||||
|
M: byte-reader dispose drop ;
|
||||||
|
|
||||||
: <byte-reader> ( byte-array encoding -- stream )
|
: <byte-reader> ( byte-array encoding -- stream )
|
||||||
[ >byte-vector dup reverse-here ] dip <decoder> ;
|
[ B{ } like 0 byte-reader boa ] dip <decoder> ;
|
||||||
|
|
||||||
: with-byte-reader ( byte-array encoding quot -- )
|
: with-byte-reader ( byte-array encoding quot -- )
|
||||||
[ <byte-reader> ] dip with-input-stream* ; inline
|
[ <byte-reader> ] dip with-input-stream* ; inline
|
||||||
|
|
|
@ -15,12 +15,12 @@ unit-test
|
||||||
|
|
||||||
[ "xyzzy" ] [ [ "xyzzy" write ] with-string-writer ] unit-test
|
[ "xyzzy" ] [ [ "xyzzy" write ] with-string-writer ] unit-test
|
||||||
|
|
||||||
[ "a" ] [ 1 SBUF" cba" stream-read ] unit-test
|
[ "a" ] [ 1 "abc" <string-reader> stream-read ] unit-test
|
||||||
[ "ab" ] [ 2 SBUF" cba" stream-read ] unit-test
|
[ "ab" ] [ 2 "abc" <string-reader> stream-read ] unit-test
|
||||||
[ "abc" ] [ 3 SBUF" cba" stream-read ] unit-test
|
[ "abc" ] [ 3 "abc" <string-reader> stream-read ] unit-test
|
||||||
[ "abc" ] [ 4 SBUF" cba" stream-read ] unit-test
|
[ "abc" ] [ 4 "abc" <string-reader> stream-read ] unit-test
|
||||||
[ "abc" f ] [
|
[ "abc" f ] [
|
||||||
3 SBUF" cba" [ stream-read ] keep stream-read1
|
3 "abc" <string-reader> [ stream-read ] keep stream-read1
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
! Copyright (C) 2003, 2009 Slava Pestov.
|
! Copyright (C) 2003, 2009 Slava Pestov, Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors io kernel math namespaces sequences sbufs
|
USING: accessors io kernel math namespaces sequences sbufs
|
||||||
strings generic splitting continuations destructors
|
strings generic splitting continuations destructors sequences.private
|
||||||
io.streams.plain io.encodings math.order growable ;
|
io.streams.plain io.encodings math.order growable io.streams.sequence ;
|
||||||
IN: io.streams.string
|
IN: io.streams.string
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: harden-as ( seq growble-exemplar -- newseq )
|
|
||||||
underlying>> like ;
|
|
||||||
|
|
||||||
: growable-read-until ( growable n -- str )
|
|
||||||
>fixnum dupd tail-slice swap harden-as dup reverse-here ;
|
|
||||||
|
|
||||||
SINGLETON: null-encoding
|
SINGLETON: null-encoding
|
||||||
|
|
||||||
M: null-encoding decode-char drop stream-read1 ;
|
M: null-encoding decode-char drop stream-read1 ;
|
||||||
|
@ -32,34 +26,18 @@ M: growable stream-flush drop ;
|
||||||
<string-writer> swap [ output-stream get ] compose with-output-stream*
|
<string-writer> swap [ output-stream get ] compose with-output-stream*
|
||||||
>string ; inline
|
>string ; inline
|
||||||
|
|
||||||
M: growable stream-read1 [ f ] [ pop ] if-empty ;
|
! New implementation
|
||||||
|
|
||||||
: find-last-sep ( seq seps -- n )
|
TUPLE: string-reader { underlying string read-only } { i array-capacity } ;
|
||||||
swap [ memq? ] curry find-last drop ;
|
|
||||||
|
|
||||||
M: growable stream-read-until
|
M: string-reader stream-read-partial stream-read ;
|
||||||
[ find-last-sep ] keep over [
|
M: string-reader stream-read sequence-read ;
|
||||||
[ swap 1+ growable-read-until ] 2keep [ nth ] 2keep
|
M: string-reader stream-read1 sequence-read1 ;
|
||||||
set-length
|
M: string-reader stream-read-until sequence-read-until ;
|
||||||
] [
|
M: string-reader dispose drop ;
|
||||||
[ swap drop 0 growable-read-until f like f ] keep
|
|
||||||
delete-all
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
M: growable stream-read
|
|
||||||
[
|
|
||||||
drop f
|
|
||||||
] [
|
|
||||||
[ length swap - 0 max ] keep
|
|
||||||
[ swap growable-read-until ] 2keep
|
|
||||||
set-length
|
|
||||||
] if-empty ;
|
|
||||||
|
|
||||||
M: growable stream-read-partial
|
|
||||||
stream-read ;
|
|
||||||
|
|
||||||
: <string-reader> ( str -- stream )
|
: <string-reader> ( str -- stream )
|
||||||
>sbuf dup reverse-here null-encoding <decoder> ;
|
0 string-reader boa null-encoding <decoder> ;
|
||||||
|
|
||||||
: with-string-reader ( str quot -- )
|
: with-string-reader ( str quot -- )
|
||||||
[ <string-reader> ] dip with-input-stream ; inline
|
[ <string-reader> ] dip with-input-stream ; inline
|
||||||
|
|
|
@ -11,7 +11,7 @@ SYMBOL: io-thread-running?
|
||||||
sleep-time io-multiplex yield ;
|
sleep-time io-multiplex yield ;
|
||||||
|
|
||||||
: start-io-thread ( -- )
|
: start-io-thread ( -- )
|
||||||
[ [ io-thread-running? get-global ] [ io-thread ] [ ] while ]
|
[ [ io-thread-running? get-global ] [ io-thread ] while ]
|
||||||
"I/O wait" spawn drop ;
|
"I/O wait" spawn drop ;
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
|
@ -16,7 +16,7 @@ IN: math.combinatorics
|
||||||
! http://msdn2.microsoft.com/en-us/library/aa302371.aspx
|
! http://msdn2.microsoft.com/en-us/library/aa302371.aspx
|
||||||
|
|
||||||
: factoradic ( n -- factoradic )
|
: factoradic ( n -- factoradic )
|
||||||
0 [ over 0 > ] [ 1+ [ /mod ] keep swap ] [ ] produce reverse 2nip ;
|
0 [ over 0 > ] [ 1+ [ /mod ] keep swap ] produce reverse 2nip ;
|
||||||
|
|
||||||
: (>permutation) ( seq n -- seq )
|
: (>permutation) ( seq n -- seq )
|
||||||
[ '[ _ dupd >= [ 1+ ] when ] map ] keep prefix ;
|
[ '[ _ dupd >= [ 1+ ] when ] map ] keep prefix ;
|
||||||
|
|
|
@ -29,7 +29,7 @@ M: real sqrt
|
||||||
: factor-2s ( n -- r s )
|
: factor-2s ( n -- r s )
|
||||||
#! factor an integer into 2^r * s
|
#! factor an integer into 2^r * s
|
||||||
dup 0 = [ 1 ] [
|
dup 0 = [ 1 ] [
|
||||||
0 swap [ dup even? ] [ [ 1+ ] [ 2/ ] bi* ] [ ] while
|
0 swap [ dup even? ] [ [ 1+ ] [ 2/ ] bi* ] while
|
||||||
] if ; inline
|
] if ; inline
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
|
@ -7,7 +7,7 @@ IN: math.primes.factors
|
||||||
|
|
||||||
: count-factor ( n d -- n' c )
|
: count-factor ( n d -- n' c )
|
||||||
[ 1 ] 2dip [ /i ] keep
|
[ 1 ] 2dip [ /i ] keep
|
||||||
[ dupd /mod zero? ] curry [ nip [ 1+ ] dip ] [ drop ] while
|
[ dupd /mod zero? ] curry [ nip [ 1+ ] dip ] while drop
|
||||||
swap ;
|
swap ;
|
||||||
|
|
||||||
: write-factor ( n d -- n' d )
|
: write-factor ( n d -- n' d )
|
||||||
|
@ -18,7 +18,7 @@ PRIVATE>
|
||||||
: group-factors ( n -- seq )
|
: group-factors ( n -- seq )
|
||||||
[
|
[
|
||||||
2
|
2
|
||||||
[ 2dup sq < ] [ write-factor next-prime ] [ ] until
|
[ 2dup sq < ] [ write-factor next-prime ] until
|
||||||
drop dup 2 < [ drop ] [ 1 2array , ] if
|
drop dup 2 < [ drop ] [ 1 2array , ] if
|
||||||
] { } make ;
|
] { } make ;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ PRIVATE>
|
||||||
} cond ; foldable
|
} cond ; foldable
|
||||||
|
|
||||||
: next-prime ( n -- p )
|
: next-prime ( n -- p )
|
||||||
next-odd [ dup really-prime? ] [ 2 + ] [ ] until ; foldable
|
next-odd [ dup really-prime? ] [ 2 + ] until ; foldable
|
||||||
|
|
||||||
: primes-between ( low high -- seq )
|
: primes-between ( low high -- seq )
|
||||||
[ dup 3 max dup even? [ 1 + ] when ] dip
|
[ dup 3 max dup even? [ 1 + ] when ] dip
|
||||||
|
|
|
@ -67,4 +67,4 @@ PRIVATE>
|
||||||
<deque> [ push-back ] reduce ;
|
<deque> [ push-back ] reduce ;
|
||||||
|
|
||||||
: deque>sequence ( deque -- sequence )
|
: deque>sequence ( deque -- sequence )
|
||||||
[ dup deque-empty? not ] [ pop-front swap ] [ ] produce nip ;
|
[ dup deque-empty? not ] [ pop-front swap ] produce nip ;
|
||||||
|
|
|
@ -98,6 +98,6 @@ M: branch pheap-push
|
||||||
<persistent-heap> swap [ rot pheap-push ] assoc-each ;
|
<persistent-heap> swap [ rot pheap-push ] assoc-each ;
|
||||||
|
|
||||||
: pheap>alist ( heap -- alist )
|
: pheap>alist ( heap -- alist )
|
||||||
[ dup pheap-empty? not ] [ pheap-pop 2array ] [ ] produce nip ;
|
[ dup pheap-empty? not ] [ pheap-pop 2array ] produce nip ;
|
||||||
|
|
||||||
: pheap>values ( heap -- seq ) pheap>alist keys ;
|
: pheap>values ( heap -- seq ) pheap>alist keys ;
|
||||||
|
|
|
@ -32,7 +32,7 @@ IN: quoted-printable
|
||||||
[ 1- cut-slice swap ] [ f swap ] if* concat ;
|
[ 1- cut-slice swap ] [ f swap ] if* concat ;
|
||||||
|
|
||||||
: divide-lines ( strings -- strings )
|
: divide-lines ( strings -- strings )
|
||||||
[ dup ] [ take-some ] [ ] produce nip ;
|
[ dup ] [ take-some ] produce nip ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ PRIVATE>
|
||||||
] when ;
|
] when ;
|
||||||
|
|
||||||
: read-quoted ( -- bytes )
|
: read-quoted ( -- bytes )
|
||||||
[ read1 dup ] [ read-char ] [ drop ] B{ } produce-as ;
|
[ read1 dup ] [ read-char ] B{ } produce-as nip ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ PRIVATE>
|
||||||
: randomize ( seq -- seq )
|
: randomize ( seq -- seq )
|
||||||
dup length [ dup 1 > ]
|
dup length [ dup 1 > ]
|
||||||
[ [ random ] [ 1- ] bi [ pick exchange ] keep ]
|
[ [ random ] [ 1- ] bi [ pick exchange ] keep ]
|
||||||
[ ] while drop ;
|
while drop ;
|
||||||
|
|
||||||
: delete-random ( seq -- elt )
|
: delete-random ( seq -- elt )
|
||||||
[ length random-integer ] keep [ nth ] 2keep delete-nth ;
|
[ length random-integer ] keep [ nth ] 2keep delete-nth ;
|
||||||
|
|
|
@ -75,7 +75,7 @@ IN: regexp
|
||||||
[ [ split1-slice nip ] keep ] [ 2drop f f ] if ;
|
[ [ split1-slice nip ] keep ] [ 2drop f f ] if ;
|
||||||
|
|
||||||
: all-matches ( string regexp -- seq )
|
: all-matches ( string regexp -- seq )
|
||||||
[ dup ] swap '[ _ next-match ] [ ] produce nip harvest ;
|
[ dup ] swap '[ _ next-match ] produce nip harvest ;
|
||||||
|
|
||||||
: count-matches ( string regexp -- n )
|
: count-matches ( string regexp -- n )
|
||||||
all-matches length ;
|
all-matches length ;
|
||||||
|
|
|
@ -512,9 +512,9 @@ ERROR: custom-error ;
|
||||||
[ [ missing->r-check ] infer ] must-fail
|
[ [ missing->r-check ] infer ] must-fail
|
||||||
|
|
||||||
! Corner case
|
! Corner case
|
||||||
[ [ [ f dup ] [ dup ] [ ] produce ] infer ] must-fail
|
[ [ [ f dup ] [ dup ] produce ] infer ] must-fail
|
||||||
|
|
||||||
[ [ [ f dup ] [ ] [ ] while ] infer ] must-fail
|
[ [ [ f dup ] [ ] while ] infer ] must-fail
|
||||||
|
|
||||||
: erg's-inference-bug ( -- ) f dup [ erg's-inference-bug ] when ; inline
|
: erg's-inference-bug ( -- ) f dup [ erg's-inference-bug ] when ; inline
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ DEFER: stop
|
||||||
sleep-queue
|
sleep-queue
|
||||||
[ dup expire-sleep? ]
|
[ dup expire-sleep? ]
|
||||||
[ dup heap-pop drop expire-sleep ]
|
[ dup heap-pop drop expire-sleep ]
|
||||||
[ ] while
|
while
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
: start ( namestack thread -- * )
|
: start ( namestack thread -- * )
|
||||||
|
|
|
@ -205,7 +205,7 @@ SYMBOL: +stopped+
|
||||||
]
|
]
|
||||||
} case
|
} case
|
||||||
] handle-synchronous
|
] handle-synchronous
|
||||||
] [ ] while ;
|
] while ;
|
||||||
|
|
||||||
: step-back-msg ( continuation -- continuation' )
|
: step-back-msg ( continuation -- continuation' )
|
||||||
walker-history tget
|
walker-history tget
|
||||||
|
@ -233,7 +233,7 @@ SYMBOL: +stopped+
|
||||||
{ step-back [ step-back-msg ] }
|
{ step-back [ step-back-msg ] }
|
||||||
} case f
|
} case f
|
||||||
] handle-synchronous
|
] handle-synchronous
|
||||||
] [ ] while ;
|
] while ;
|
||||||
|
|
||||||
: walker-loop ( -- )
|
: walker-loop ( -- )
|
||||||
+running+ set-status
|
+running+ set-status
|
||||||
|
@ -256,7 +256,7 @@ SYMBOL: +stopped+
|
||||||
[ walker-suspended ]
|
[ walker-suspended ]
|
||||||
} case
|
} case
|
||||||
] handle-synchronous
|
] handle-synchronous
|
||||||
] [ ] until ;
|
] until ;
|
||||||
|
|
||||||
: associate-thread ( walker -- )
|
: associate-thread ( walker -- )
|
||||||
walker-thread tset
|
walker-thread tset
|
||||||
|
|
|
@ -13,6 +13,6 @@ IN: ui.event-loop
|
||||||
|
|
||||||
HOOK: do-events ui-backend ( -- )
|
HOOK: do-events ui-backend ( -- )
|
||||||
|
|
||||||
: event-loop ( -- ) [ event-loop? ] [ do-events ] [ ] while ;
|
: event-loop ( -- ) [ event-loop? ] [ do-events ] while ;
|
||||||
|
|
||||||
: ui-wait ( -- ) 10 milliseconds sleep ;
|
: ui-wait ( -- ) 10 milliseconds sleep ;
|
||||||
|
|
|
@ -146,7 +146,7 @@ PRIVATE>
|
||||||
: update-ui-loop ( -- )
|
: update-ui-loop ( -- )
|
||||||
[ ui-running? ui-thread get-global self eq? and ]
|
[ ui-running? ui-thread get-global self eq? and ]
|
||||||
[ ui-notify-flag get lower-flag update-ui ]
|
[ ui-notify-flag get lower-flag update-ui ]
|
||||||
[ ] while ;
|
while ;
|
||||||
|
|
||||||
: start-ui-thread ( -- )
|
: start-ui-thread ( -- )
|
||||||
[ self ui-thread set-global update-ui-loop ]
|
[ self ui-thread set-global update-ui-loop ]
|
||||||
|
|
|
@ -102,8 +102,7 @@ PRIVATE>
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: >pieces ( str quot: ( str -- i ) -- graphemes )
|
: >pieces ( str quot: ( str -- i ) -- graphemes )
|
||||||
[ dup empty? not ] swap '[ dup @ cut-slice swap ]
|
[ dup empty? not ] swap '[ dup @ cut-slice swap ] produce nip ; inline
|
||||||
[ ] produce nip ; inline
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ SYMBOL: locale ! Just casing locale, or overall?
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: split-subseq ( string sep -- strings )
|
: split-subseq ( string sep -- strings )
|
||||||
[ dup ] swap '[ _ split1-slice swap ] [ ] produce nip ;
|
[ dup ] swap '[ _ split1-slice swap ] produce nip ;
|
||||||
|
|
||||||
: replace ( old new str -- newstr )
|
: replace ( old new str -- newstr )
|
||||||
[ split-subseq ] dip join ; inline
|
[ split-subseq ] dip join ; inline
|
||||||
|
|
|
@ -77,7 +77,7 @@ M: integer user-groups ( id -- seq )
|
||||||
user-name (user-groups) ;
|
user-name (user-groups) ;
|
||||||
|
|
||||||
: all-groups ( -- seq )
|
: all-groups ( -- seq )
|
||||||
[ getgrent dup ] [ group-struct>group ] [ drop ] produce ;
|
[ getgrent dup ] [ group-struct>group ] produce nip ;
|
||||||
|
|
||||||
: <group-cache> ( -- assoc )
|
: <group-cache> ( -- assoc )
|
||||||
all-groups [ [ id>> ] keep ] H{ } map>assoc ;
|
all-groups [ [ id>> ] keep ] H{ } map>assoc ;
|
||||||
|
|
|
@ -36,7 +36,7 @@ PRIVATE>
|
||||||
|
|
||||||
: all-users ( -- seq )
|
: all-users ( -- seq )
|
||||||
[
|
[
|
||||||
[ getpwent dup ] [ passwd>new-passwd ] [ drop ] produce
|
[ getpwent dup ] [ passwd>new-passwd ] produce nip
|
||||||
] with-pwent ;
|
] with-pwent ;
|
||||||
|
|
||||||
SYMBOL: user-cache
|
SYMBOL: user-cache
|
||||||
|
|
|
@ -14,7 +14,7 @@ IN: unix.utilities
|
||||||
: alien>strings ( alien encoding -- strings )
|
: alien>strings ( alien encoding -- strings )
|
||||||
[ [ dup more? ] ] dip
|
[ [ dup more? ] ] dip
|
||||||
'[ [ advance ] [ *void* _ alien>string ] bi ]
|
'[ [ advance ] [ *void* _ alien>string ] bi ]
|
||||||
[ ] produce nip ;
|
produce nip ;
|
||||||
|
|
||||||
: strings>alien ( strings encoding -- array )
|
: strings>alien ( strings encoding -- array )
|
||||||
'[ _ malloc-string ] void*-array{ } map-as f suffix ;
|
'[ _ malloc-string ] void*-array{ } map-as f suffix ;
|
||||||
|
|
|
@ -57,7 +57,7 @@ M: unix utmpx>utmpx-record ( utmpx -- utmpx-record )
|
||||||
[
|
[
|
||||||
[ getutxent dup ]
|
[ getutxent dup ]
|
||||||
[ utmpx>utmpx-record ]
|
[ utmpx>utmpx-record ]
|
||||||
[ drop ] produce
|
produce nip
|
||||||
] with-utmpx ;
|
] with-utmpx ;
|
||||||
|
|
||||||
os {
|
os {
|
||||||
|
|
|
@ -210,7 +210,7 @@ M: anonymous-complement (classes-intersect?)
|
||||||
[ [ name>> ] compare ] sort >vector
|
[ [ name>> ] compare ] sort >vector
|
||||||
[ dup empty? not ]
|
[ dup empty? not ]
|
||||||
[ dup largest-class [ over delete-nth ] dip ]
|
[ dup largest-class [ over delete-nth ] dip ]
|
||||||
[ ] produce nip ;
|
produce nip ;
|
||||||
|
|
||||||
: min-class ( class seq -- class/f )
|
: min-class ( class seq -- class/f )
|
||||||
over [ classes-intersect? ] curry filter
|
over [ classes-intersect? ] curry filter
|
||||||
|
|
|
@ -21,7 +21,7 @@ ERROR: bad-effect ;
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: parse-effect-tokens ( end -- tokens )
|
: parse-effect-tokens ( end -- tokens )
|
||||||
[ parse-effect-token dup ] curry [ ] [ drop ] produce ;
|
[ parse-effect-token dup ] curry [ ] produce nip ;
|
||||||
|
|
||||||
: parse-effect ( end -- effect )
|
: parse-effect ( end -- effect )
|
||||||
parse-effect-tokens { "--" } split1 dup
|
parse-effect-tokens { "--" } split1 dup
|
||||||
|
|
|
@ -224,7 +224,7 @@ $io-error ;
|
||||||
ARTICLE: "stream-protocol" "Stream protocol"
|
ARTICLE: "stream-protocol" "Stream protocol"
|
||||||
"The stream protocol consists of a large number of generic words, many of which are optional."
|
"The stream protocol consists of a large number of generic words, many of which are optional."
|
||||||
$nl
|
$nl
|
||||||
"Stream protocol words are rarely called directly, since code which only works with one stream at a time should be written use " { $link "stdio" } " instead, wrapping I/O operations such as " { $link read } " and " { $link write } " in " { $link with-input-stream } " and " { $link with-output-stream } "."
|
"Stream protocol words are rarely called directly, since code which only works with one stream at a time should be written to use " { $link "stdio" } " instead, wrapping I/O operations such as " { $link read } " and " { $link write } " in " { $link with-input-stream } " and " { $link with-output-stream } "."
|
||||||
$nl
|
$nl
|
||||||
"All streams must implement the " { $link dispose } " word in addition to the stream protocol."
|
"All streams must implement the " { $link dispose } " word in addition to the stream protocol."
|
||||||
$nl
|
$nl
|
||||||
|
|
|
@ -65,12 +65,12 @@ SYMBOL: error-stream
|
||||||
: bl ( -- ) " " write ;
|
: bl ( -- ) " " write ;
|
||||||
|
|
||||||
: lines ( stream -- seq )
|
: lines ( stream -- seq )
|
||||||
[ [ readln dup ] [ ] [ drop ] produce ] with-input-stream ;
|
[ [ readln dup ] [ ] produce nip ] with-input-stream ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: each-morsel ( handler: ( data -- ) reader: ( -- data ) -- )
|
: each-morsel ( handler: ( data -- ) reader: ( -- data ) -- )
|
||||||
[ dup ] compose swap [ drop ] while ; inline
|
[ dup ] compose swap while drop ; inline
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
@ -79,8 +79,7 @@ PRIVATE>
|
||||||
|
|
||||||
: contents ( stream -- seq )
|
: contents ( stream -- seq )
|
||||||
[
|
[
|
||||||
[ 65536 read-partial dup ]
|
[ 65536 read-partial dup ] [ ] produce nip concat f like
|
||||||
[ ] [ drop ] produce concat f like
|
|
||||||
] with-input-stream ;
|
] with-input-stream ;
|
||||||
|
|
||||||
: each-block ( quot: ( block -- ) -- )
|
: each-block ( quot: ( block -- ) -- )
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
! Copyright (C) 2009 Daniel Ehrenberg
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: sequences io kernel accessors math math.order ;
|
||||||
|
IN: io.streams.sequence
|
||||||
|
|
||||||
|
SLOT: underlying
|
||||||
|
SLOT: i
|
||||||
|
|
||||||
|
: >sequence-stream< ( stream -- i underlying )
|
||||||
|
[ i>> ] [ underlying>> ] bi ; inline
|
||||||
|
|
||||||
|
: next ( stream -- )
|
||||||
|
[ 1+ ] change-i drop ;
|
||||||
|
|
||||||
|
: sequence-read1 ( stream -- elt/f )
|
||||||
|
[ >sequence-stream< ?nth ]
|
||||||
|
[ next ] bi ; inline
|
||||||
|
|
||||||
|
: add-length ( n stream -- i+n )
|
||||||
|
[ i>> + ] [ underlying>> length ] bi min ;
|
||||||
|
|
||||||
|
: (sequence-read) ( n stream -- seq/f )
|
||||||
|
[ add-length ] keep
|
||||||
|
[ [ swap dup ] change-i drop ]
|
||||||
|
[ underlying>> ] bi
|
||||||
|
subseq ; inline
|
||||||
|
|
||||||
|
: sequence-read ( n stream -- seq/f )
|
||||||
|
dup >sequence-stream< bounds-check?
|
||||||
|
[ (sequence-read) ] [ 2drop f ] if ; inline
|
||||||
|
|
||||||
|
: find-sep ( seps stream -- sep/f n )
|
||||||
|
swap [ >sequence-stream< ] dip
|
||||||
|
[ memq? ] curry find-from swap ; inline
|
||||||
|
|
||||||
|
: sequence-read-until ( separators stream -- seq sep/f )
|
||||||
|
[ find-sep ] keep
|
||||||
|
[ sequence-read ] [ next ] bi swap ; inline
|
|
@ -765,15 +765,15 @@ HELP: 4dip
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: while
|
HELP: while
|
||||||
{ $values { "pred" { $quotation "( -- ? )" } } { "body" "a quotation" } { "tail" "a quotation" } }
|
{ $values { "pred" { $quotation "( -- ? )" } } { "body" "a quotation" } }
|
||||||
{ $description "Calls " { $snippet "body" } " until " { $snippet "pred" } " returns " { $link f } "." } ;
|
{ $description "Calls " { $snippet "body" } " until " { $snippet "pred" } " returns " { $link f } "." } ;
|
||||||
|
|
||||||
HELP: until
|
HELP: until
|
||||||
{ $values { "pred" { $quotation "( -- ? )" } } { "body" "a quotation" } { "tail" "a quotation" } }
|
{ $values { "pred" { $quotation "( -- ? )" } } { "body" "a quotation" } }
|
||||||
{ $description "Calls " { $snippet "body" } " until " { $snippet "pred" } " returns " { $link t } "." } ;
|
{ $description "Calls " { $snippet "body" } " until " { $snippet "pred" } " returns " { $link t } "." } ;
|
||||||
|
|
||||||
HELP: do
|
HELP: do
|
||||||
{ $values { "pred" { $quotation "( -- ? )" } } { "body" "a quotation" } { "tail" "a quotation" } }
|
{ $values { "pred" { $quotation "( -- ? )" } } { "body" "a quotation" } }
|
||||||
{ $description "Executes one iteration of a " { $link while } " or " { $link until } " loop." } ;
|
{ $description "Executes one iteration of a " { $link while } " or " { $link until } " loop." } ;
|
||||||
|
|
||||||
HELP: loop
|
HELP: loop
|
||||||
|
@ -794,18 +794,11 @@ ARTICLE: "looping-combinators" "Looping combinators"
|
||||||
"In most cases, loops should be written using high-level combinators (such as " { $link "sequences-combinators" } ") or tail recursion. However, sometimes, the best way to express intent is with a loop."
|
"In most cases, loops should be written using high-level combinators (such as " { $link "sequences-combinators" } ") or tail recursion. However, sometimes, the best way to express intent is with a loop."
|
||||||
{ $subsection while }
|
{ $subsection while }
|
||||||
{ $subsection until }
|
{ $subsection until }
|
||||||
"The above two combinators take a " { $snippet "tail" } " quotation. Strictly speaking, the " { $snippet "tail" } " is not necessary, since the following are equivalent:"
|
|
||||||
{ $code
|
|
||||||
"[ P ] [ Q ] [ T ] while"
|
|
||||||
"[ P ] [ Q ] [ ] while T"
|
|
||||||
}
|
|
||||||
"However, depending on the stack effects of " { $snippet "pred" } " and " { $snippet "quot" } ", the " { $snippet "tail" } " quotation might need to be non-empty in order to balance out the stack effect of branches for stack effect inference."
|
|
||||||
$nl
|
|
||||||
"To execute one iteration of a loop, use the following word:"
|
"To execute one iteration of a loop, use the following word:"
|
||||||
{ $subsection do }
|
{ $subsection do }
|
||||||
"This word is intended as a modifier. The normal " { $link while } " loop never executes the body if the predicate returns first on the first iteration. To ensure the body executes at least once, use " { $link do } ":"
|
"This word is intended as a modifier. The normal " { $link while } " loop never executes the body if the predicate returns first on the first iteration. To ensure the body executes at least once, use " { $link do } ":"
|
||||||
{ $code
|
{ $code
|
||||||
"[ P ] [ Q ] [ T ] do while"
|
"[ P ] [ Q ] do while"
|
||||||
}
|
}
|
||||||
"A simpler looping combinator which executes a single quotation until it returns " { $link f } ":"
|
"A simpler looping combinator which executes a single quotation until it returns " { $link f } ":"
|
||||||
{ $subsection loop } ;
|
{ $subsection loop } ;
|
||||||
|
|
|
@ -185,21 +185,20 @@ PRIVATE>
|
||||||
|
|
||||||
: either? ( x y quot -- ? ) bi@ or ; inline
|
: either? ( x y quot -- ? ) bi@ or ; inline
|
||||||
|
|
||||||
: most ( x y quot -- z )
|
: most ( x y quot -- z ) 2keep ? ; inline
|
||||||
[ 2dup ] dip call [ drop ] [ nip ] if ; inline
|
|
||||||
|
|
||||||
! Loops
|
! Loops
|
||||||
: loop ( pred: ( -- ? ) -- )
|
: loop ( pred: ( -- ? ) -- )
|
||||||
[ call ] keep [ loop ] curry when ; inline recursive
|
[ call ] keep [ loop ] curry when ; inline recursive
|
||||||
|
|
||||||
: do ( pred body tail -- pred body tail )
|
: do ( pred body -- pred body )
|
||||||
over 3dip ; inline
|
dup 2dip ; inline
|
||||||
|
|
||||||
: while ( pred: ( -- ? ) body: ( -- ) tail: ( -- ) -- )
|
: while ( pred: ( -- ? ) body: ( -- ) -- )
|
||||||
[ pick 3dip [ do while ] 3curry ] keep if ; inline recursive
|
swap do compose [ loop ] curry when ; inline
|
||||||
|
|
||||||
: until ( pred: ( -- ? ) body: ( -- ) tail: ( -- ) -- )
|
: until ( pred: ( -- ? ) body: ( -- ) -- )
|
||||||
[ [ not ] compose ] 2dip while ; inline
|
[ [ not ] compose ] dip while ; inline
|
||||||
|
|
||||||
! Object protocol
|
! Object protocol
|
||||||
GENERIC: hashcode* ( depth obj -- code )
|
GENERIC: hashcode* ( depth obj -- code )
|
||||||
|
|
|
@ -41,7 +41,7 @@ M: fixnum bitnot fixnum-bitnot ;
|
||||||
M: fixnum bit? neg shift 1 bitand 0 > ;
|
M: fixnum bit? neg shift 1 bitand 0 > ;
|
||||||
|
|
||||||
: fixnum-log2 ( x -- n )
|
: fixnum-log2 ( x -- n )
|
||||||
0 swap [ dup 1 eq? ] [ [ 1+ ] [ 2/ ] bi* ] [ ] until drop ;
|
0 swap [ dup 1 eq? ] [ [ 1+ ] [ 2/ ] bi* ] until drop ;
|
||||||
|
|
||||||
M: fixnum (log2) fixnum-log2 ;
|
M: fixnum (log2) fixnum-log2 ;
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ M: bignum (log2) bignum-log2 ;
|
||||||
: /f-loop ( scale mantissa den -- scale' fraction-and-guard rem )
|
: /f-loop ( scale mantissa den -- scale' fraction-and-guard rem )
|
||||||
[ 2dup /i log2 53 > ]
|
[ 2dup /i log2 53 > ]
|
||||||
[ [ shift-mantissa ] dip ]
|
[ [ shift-mantissa ] dip ]
|
||||||
[ ] while /mod ; inline
|
while /mod ; inline
|
||||||
|
|
||||||
! Third step: post-scaling
|
! Third step: post-scaling
|
||||||
: unscaled-float ( mantissa -- n )
|
: unscaled-float ( mantissa -- n )
|
||||||
|
|
|
@ -96,7 +96,7 @@ PRIVATE>
|
||||||
|
|
||||||
: positive>base ( num radix -- str )
|
: positive>base ( num radix -- str )
|
||||||
dup 1 <= [ "Invalid radix" throw ] when
|
dup 1 <= [ "Invalid radix" throw ] when
|
||||||
[ dup 0 > ] swap [ /mod >digit ] curry [ ] "" produce-as nip
|
[ dup 0 > ] swap [ /mod >digit ] curry "" produce-as nip
|
||||||
dup reverse-here ; inline
|
dup reverse-here ; inline
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
|
@ -913,24 +913,19 @@ HELP: supremum
|
||||||
{ $errors "Throws an error if the sequence is empty." } ;
|
{ $errors "Throws an error if the sequence is empty." } ;
|
||||||
|
|
||||||
HELP: produce
|
HELP: produce
|
||||||
{ $values { "pred" { $quotation "( -- ? )" } } { "quot" { $quotation "( -- obj )" } } { "tail" "a quotation" } { "seq" "a sequence" } }
|
{ $values { "pred" { $quotation "( -- ? )" } } { "quot" { $quotation "( -- obj )" } } { "seq" "a sequence" } }
|
||||||
{ $description "Calls " { $snippet "pred" } " repeatedly. If the predicate yields " { $link f } ", stops, otherwise, calls " { $snippet "quot" } " to yield a value. Values are accumulated and returned in a sequence at the end." }
|
{ $description "Calls " { $snippet "pred" } " repeatedly. If the predicate yields " { $link f } ", stops, otherwise, calls " { $snippet "quot" } " to yield a value. Values are accumulated and returned in a sequence at the end." }
|
||||||
{ $examples
|
{ $examples
|
||||||
"The following example divides a number by two until we reach zero, and accumulates intermediate results:"
|
"The following example divides a number by two until we reach zero, and accumulates intermediate results:"
|
||||||
{ $example "USING: kernel math prettyprint sequences ;" "1337 [ dup 0 > ] [ 2/ dup ] [ ] produce nip ." "{ 668 334 167 83 41 20 10 5 2 1 0 }" }
|
{ $example "USING: kernel math prettyprint sequences ;" "1337 [ dup 0 > ] [ 2/ dup ] produce nip ." "{ 668 334 167 83 41 20 10 5 2 1 0 }" }
|
||||||
"The " { $snippet "tail" } " quotation is used when the predicate produces more than one output value. In this case, we have to drop this value even if the predicate fails in order for stack inference to calculate a stack effect for the " { $link produce } " call:"
|
"The following example collects random numbers as long as they are greater than 1:"
|
||||||
{ $unchecked-example "USING: kernel prettyprint random sequences ;" "[ 10 random dup 1 > ] [ ] [ drop ] produce ." "{ 8 2 2 9 }" }
|
{ $unchecked-example "USING: kernel prettyprint random sequences ;" "[ 10 random dup 1 > ] [ ] produce nip ." "{ 8 2 2 9 }" }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: produce-as
|
HELP: produce-as
|
||||||
{ $values { "pred" { $quotation "( -- ? )" } } { "quot" { $quotation "( -- obj )" } } { "tail" "a quotation" } { "exemplar" sequence } { "seq" "a sequence" } }
|
{ $values { "pred" { $quotation "( -- ? )" } } { "quot" { $quotation "( -- obj )" } } { "exemplar" sequence } { "seq" "a sequence" } }
|
||||||
{ $description "Calls " { $snippet "pred" } " repeatedly. If the predicate yields " { $link f } ", stops, otherwise, calls " { $snippet "quot" } " to yield a value. Values are accumulated and returned in a sequence of type " { $snippet "exemplar" } " at the end." }
|
{ $description "Calls " { $snippet "pred" } " repeatedly. If the predicate yields " { $link f } ", stops, otherwise, calls " { $snippet "quot" } " to yield a value. Values are accumulated and returned in a sequence of type " { $snippet "exemplar" } " at the end." }
|
||||||
{ $examples
|
{ $examples "See " { $link produce } " for examples." } ;
|
||||||
"The following example divides a number by two until we reach zero, and accumulates intermediate results:"
|
|
||||||
{ $example "USING: kernel math prettyprint sequences ;" "1337 [ dup 0 > ] [ 2/ dup ] [ ] V{ } produce-as nip ." "V{ 668 334 167 83 41 20 10 5 2 1 0 }" }
|
|
||||||
"The " { $snippet "tail" } " quotation is used when the predicate produces more than one output value. In this case, we have to drop this value even if the predicate fails in order for stack inference to calculate a stack effect for the " { $link produce } " call:"
|
|
||||||
{ $unchecked-example "USING: kernel prettyprint random sequences ;" "[ 10 random dup 1 > ] [ ] [ drop ] B{ } produce-as ." "B{ 8 2 2 9 }" }
|
|
||||||
} ;
|
|
||||||
|
|
||||||
HELP: sigma
|
HELP: sigma
|
||||||
{ $values { "seq" sequence } { "quot" quotation } { "n" number } }
|
{ $values { "seq" sequence } { "quot" quotation } { "n" number } }
|
||||||
|
|
|
@ -481,14 +481,14 @@ PRIVATE>
|
||||||
: accumulator ( quot -- quot' vec )
|
: accumulator ( quot -- quot' vec )
|
||||||
V{ } clone [ [ push ] curry compose ] keep ; inline
|
V{ } clone [ [ push ] curry compose ] keep ; inline
|
||||||
|
|
||||||
: produce-as ( pred quot tail exemplar -- seq )
|
: produce-as ( pred quot exemplar -- seq )
|
||||||
[ swap accumulator [ swap while ] dip ] dip like ; inline
|
[ accumulator [ while ] dip ] dip like ; inline
|
||||||
|
|
||||||
: produce ( pred quot tail -- seq )
|
: produce ( pred quot -- seq )
|
||||||
{ } produce-as ; inline
|
{ } produce-as ; inline
|
||||||
|
|
||||||
: follow ( obj quot -- seq )
|
: follow ( obj quot -- seq )
|
||||||
[ dup ] swap [ keep ] curry [ ] produce nip ; inline
|
[ dup ] swap [ keep ] curry produce nip ; inline
|
||||||
|
|
||||||
: prepare-index ( seq quot -- seq n quot )
|
: prepare-index ( seq quot -- seq n quot )
|
||||||
[ dup length ] dip ; inline
|
[ dup length ] dip ; inline
|
||||||
|
|
|
@ -199,7 +199,7 @@ M: array make-slot
|
||||||
swap
|
swap
|
||||||
peel-off-name
|
peel-off-name
|
||||||
peel-off-class
|
peel-off-class
|
||||||
[ dup empty? ] [ peel-off-attributes ] [ ] until drop
|
[ dup empty? ] [ peel-off-attributes ] until drop
|
||||||
check-initial-value ;
|
check-initial-value ;
|
||||||
|
|
||||||
M: slot-spec make-slot
|
M: slot-spec make-slot
|
||||||
|
|
|
@ -126,7 +126,7 @@ TUPLE: merge
|
||||||
: sort-loop ( merge quot -- )
|
: sort-loop ( merge quot -- )
|
||||||
[ 2 [ over seq>> length over > ] ] dip
|
[ 2 [ over seq>> length over > ] ] dip
|
||||||
[ [ 1 shift 2dup ] dip sort-pass ] curry
|
[ [ 1 shift 2dup ] dip sort-pass ] curry
|
||||||
[ ] while 2drop ; inline
|
while 2drop ; inline
|
||||||
|
|
||||||
: each-pair ( seq quot -- )
|
: each-pair ( seq quot -- )
|
||||||
[ [ length 1+ 2/ ] keep ] dip
|
[ [ length 1+ 2/ ] keep ] dip
|
||||||
|
|
|
@ -25,9 +25,11 @@ SINGLETON: solaris
|
||||||
SINGLETON: macosx
|
SINGLETON: macosx
|
||||||
SINGLETON: linux
|
SINGLETON: linux
|
||||||
|
|
||||||
|
SINGLETON: haiku
|
||||||
|
|
||||||
UNION: bsd freebsd netbsd openbsd macosx ;
|
UNION: bsd freebsd netbsd openbsd macosx ;
|
||||||
|
|
||||||
UNION: unix bsd solaris linux ;
|
UNION: unix bsd solaris linux haiku ;
|
||||||
|
|
||||||
: os ( -- class ) \ os get-global ; foldable
|
: os ( -- class ) \ os get-global ; foldable
|
||||||
|
|
||||||
|
@ -51,6 +53,7 @@ UNION: unix bsd solaris linux ;
|
||||||
{ "solaris" solaris }
|
{ "solaris" solaris }
|
||||||
{ "macosx" macosx }
|
{ "macosx" macosx }
|
||||||
{ "linux" linux }
|
{ "linux" linux }
|
||||||
|
{ "haiku" haiku }
|
||||||
} at ;
|
} at ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
|
@ -337,7 +337,7 @@ TUPLE: solid dimension silhouettes
|
||||||
: compute-adjacencies ( solid -- solid )
|
: compute-adjacencies ( solid -- solid )
|
||||||
dup dimension>> [ >= ] curry
|
dup dimension>> [ >= ] curry
|
||||||
[ keep swap ] curry MAX-FACE-PER-CORNER swap
|
[ keep swap ] curry MAX-FACE-PER-CORNER swap
|
||||||
[ [ test-faces-combinaisons ] 2keep 1- ] [ ] while drop ;
|
[ [ test-faces-combinaisons ] 2keep 1- ] while drop ;
|
||||||
|
|
||||||
: find-adjacencies ( solid -- solid )
|
: find-adjacencies ( solid -- solid )
|
||||||
erase-old-adjacencies
|
erase-old-adjacencies
|
||||||
|
|
|
@ -135,7 +135,7 @@ METHOD: collide ( <axion> -- )
|
||||||
0 >>theta-d
|
0 >>theta-d
|
||||||
0 >>theta-dd
|
0 >>theta-dd
|
||||||
|
|
||||||
[ 0.00001 theta-dd-small? ] [ -0.001 0.001 random-theta-dd ] [ ] while
|
[ 0.00001 theta-dd-small? ] [ -0.001 0.001 random-theta-dd ] while
|
||||||
|
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ METHOD: collide ( <hadron> -- )
|
||||||
0 >>theta-d
|
0 >>theta-d
|
||||||
0 >>theta-dd
|
0 >>theta-dd
|
||||||
|
|
||||||
[ 0.00001 theta-dd-small? ] [ -0.001 0.001 random-theta-dd ] [ ] while
|
[ 0.00001 theta-dd-small? ] [ -0.001 0.001 random-theta-dd ] while
|
||||||
|
|
||||||
0 1 0 1 rgba boa >>myc
|
0 1 0 1 rgba boa >>myc
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ METHOD: collide ( <muon> -- )
|
||||||
0 >>theta-d
|
0 >>theta-d
|
||||||
0 >>theta-dd
|
0 >>theta-dd
|
||||||
|
|
||||||
[ 0.001 theta-dd-small? ] [ -0.1 0.1 random-theta-dd ] [ ] while
|
[ 0.001 theta-dd-small? ] [ -0.1 0.1 random-theta-dd ] while
|
||||||
|
|
||||||
set-good-color
|
set-good-color
|
||||||
set-anti-color
|
set-anti-color
|
||||||
|
@ -355,7 +355,7 @@ METHOD: collide ( <quark> -- )
|
||||||
0 >>theta-d
|
0 >>theta-d
|
||||||
0 >>theta-dd
|
0 >>theta-dd
|
||||||
|
|
||||||
[ 0.00001 theta-dd-small? ] [ -0.001 0.001 random-theta-dd ] [ ] while
|
[ 0.00001 theta-dd-small? ] [ -0.001 0.001 random-theta-dd ] while
|
||||||
|
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ PRIVATE>
|
||||||
: full-depth-first ( graph pre post tail -- ? )
|
: full-depth-first ( graph pre post tail -- ? )
|
||||||
'[ [ visited? get [ nip not ] assoc-find ]
|
'[ [ visited? get [ nip not ] assoc-find ]
|
||||||
[ drop _ _ (depth-first) @ ]
|
[ drop _ _ (depth-first) @ ]
|
||||||
[ 2drop ] while ] swap search-wrap ; inline
|
while 2drop ] swap search-wrap ; inline
|
||||||
|
|
||||||
: dag? ( graph -- ? )
|
: dag? ( graph -- ? )
|
||||||
V{ } clone swap [ 2dup swap push dupd
|
V{ } clone swap [ 2dup swap push dupd
|
||||||
|
|
|
@ -20,7 +20,7 @@ IN: id3.tests
|
||||||
"2009"
|
"2009"
|
||||||
"COMMENT"
|
"COMMENT"
|
||||||
"Bluegrass"
|
"Bluegrass"
|
||||||
] [ "resource:extra/id3/tests/blah.mp3" file-id3-tags id3-params ] unit-test
|
] [ "vocab:id3/tests/blah.mp3" file-id3-tags id3-params ] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
"Anthem of the Trinity"
|
"Anthem of the Trinity"
|
||||||
|
@ -29,7 +29,7 @@ IN: id3.tests
|
||||||
f
|
f
|
||||||
f
|
f
|
||||||
"Classical"
|
"Classical"
|
||||||
] [ "resource:extra/id3/tests/blah2.mp3" file-id3-tags id3-params ] unit-test
|
] [ "vocab:id3/tests/blah2.mp3" file-id3-tags id3-params ] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
"Stormy Weather"
|
"Stormy Weather"
|
||||||
|
@ -38,5 +38,5 @@ IN: id3.tests
|
||||||
f
|
f
|
||||||
"eng, AG# 08E1C12E"
|
"eng, AG# 08E1C12E"
|
||||||
"Big Band"
|
"Big Band"
|
||||||
] [ "resource:extra/id3/tests/blah3.mp3" file-id3-tags id3-params ] unit-test
|
] [ "vocab:id3/tests/blah3.mp3" file-id3-tags id3-params ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -4,140 +4,39 @@ USING: sequences io io.encodings.binary io.files io.pathnames
|
||||||
strings kernel math io.mmap io.mmap.uchar accessors syntax
|
strings kernel math io.mmap io.mmap.uchar accessors syntax
|
||||||
combinators math.ranges unicode.categories byte-arrays
|
combinators math.ranges unicode.categories byte-arrays
|
||||||
io.encodings.string io.encodings.utf16 assocs math.parser
|
io.encodings.string io.encodings.utf16 assocs math.parser
|
||||||
combinators.short-circuit fry namespaces multiline
|
combinators.short-circuit fry namespaces combinators.smart
|
||||||
combinators.smart splitting io.encodings.ascii ;
|
splitting io.encodings.ascii arrays ;
|
||||||
IN: id3
|
IN: id3
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
CONSTANT: genres
|
CONSTANT: genres
|
||||||
{
|
{
|
||||||
"Blues"
|
"Blues" "Classic Rock" "Country" "Dance" "Disco" "Funk"
|
||||||
"Classic Rock"
|
"Grunge" "Hip-Hop" "Jazz" "Metal" "New Age" "Oldies" "Other"
|
||||||
"Country"
|
"Pop" "R&B" "Rap" "Reggae" "Rock" "Techno" "Industrial"
|
||||||
"Dance"
|
"Alternative" "Ska" "Death Metal" "Pranks" "Soundtrack"
|
||||||
"Disco"
|
"Euro-Techno" "Ambient" "Trip-Hop" "Vocal" "Jazz+Funk"
|
||||||
"Funk"
|
"Fusion" "Trance" "Classical" "Instrumental" "Acid" "House"
|
||||||
"Grunge"
|
"Game" "Sound Clip" "Gospel" "Noise" "AlternRock" "Bass"
|
||||||
"Hip-Hop"
|
"Soul" "Punk" "Space" "Meditative" "Instrumental Pop"
|
||||||
"Jazz"
|
"Instrumental Rock" "Ethnic" "Gothic" "Darkwave"
|
||||||
"Metal"
|
"Techno-Industrial" "Electronic" "Pop-Folk" "Eurodance"
|
||||||
"New Age"
|
"Dream" "Southern Rock" "Comedy" "Cult" "Gangsta" "Top 40"
|
||||||
"Oldies"
|
"Christian Rap" "Pop/Funk" "Jungle" "Native American"
|
||||||
"Other"
|
"Cabaret" "New Wave" "Psychedelic" "Rave" "Showtunes"
|
||||||
"Pop"
|
"Trailer" "Lo-Fi" "Tribal" "Acid Punk" "Acid Jazz" "Polka"
|
||||||
"R&B"
|
"Retro" "Musical" "Rock & Roll" "Hard Rock" "Folk"
|
||||||
"Rap"
|
"Folk-Rock" "National Folk" "Swing" "Fast Fusion" "Bebop"
|
||||||
"Reggae"
|
"Latin" "Revival" "Celtic" "Bluegrass" "Avantgarde"
|
||||||
"Rock"
|
"Gothic Rock" "Progressive Rock" "Psychedelic Rock"
|
||||||
"Techno"
|
"Symphonic Rock" "Slow Rock" "Big Band" "Chorus"
|
||||||
"Industrial"
|
"Easy Listening" "Acoustic" "Humour" "Speech" "Chanson"
|
||||||
"Alternative"
|
"Opera" "Chamber Music" "Sonata" "Symphony" "Booty Bass"
|
||||||
"Ska"
|
"Primus" "Porn Groove" "Satire" "Slow Jam" "Club" "Tango"
|
||||||
"Death Metal"
|
"Samba" "Folklore" "Ballad" "Power Ballad" "Rhythmic Soul"
|
||||||
"Pranks"
|
"Freestyle" "Duet" "Punk Rock" "Drum Solo" "A capella"
|
||||||
"Soundtrack"
|
"Euro-House" "Dance Hall"
|
||||||
"Euro-Techno"
|
|
||||||
"Ambient"
|
|
||||||
"Trip-Hop"
|
|
||||||
"Vocal"
|
|
||||||
"Jazz+Funk"
|
|
||||||
"Fusion"
|
|
||||||
"Trance"
|
|
||||||
"Classical"
|
|
||||||
"Instrumental"
|
|
||||||
"Acid"
|
|
||||||
"House"
|
|
||||||
"Game"
|
|
||||||
"Sound Clip"
|
|
||||||
"Gospel"
|
|
||||||
"Noise"
|
|
||||||
"AlternRock"
|
|
||||||
"Bass"
|
|
||||||
"Soul"
|
|
||||||
"Punk"
|
|
||||||
"Space"
|
|
||||||
"Meditative"
|
|
||||||
"Instrumental Pop"
|
|
||||||
"Instrumental Rock"
|
|
||||||
"Ethnic"
|
|
||||||
"Gothic"
|
|
||||||
"Darkwave"
|
|
||||||
"Techno-Industrial"
|
|
||||||
"Electronic"
|
|
||||||
"Pop-Folk"
|
|
||||||
"Eurodance"
|
|
||||||
"Dream"
|
|
||||||
"Southern Rock"
|
|
||||||
"Comedy"
|
|
||||||
"Cult"
|
|
||||||
"Gangsta"
|
|
||||||
"Top 40"
|
|
||||||
"Christian Rap"
|
|
||||||
"Pop/Funk"
|
|
||||||
"Jungle"
|
|
||||||
"Native American"
|
|
||||||
"Cabaret"
|
|
||||||
"New Wave"
|
|
||||||
"Psychedelic"
|
|
||||||
"Rave"
|
|
||||||
"Showtunes"
|
|
||||||
"Trailer"
|
|
||||||
"Lo-Fi"
|
|
||||||
"Tribal"
|
|
||||||
"Acid Punk"
|
|
||||||
"Acid Jazz"
|
|
||||||
"Polka"
|
|
||||||
"Retro"
|
|
||||||
"Musical"
|
|
||||||
"Rock & Roll"
|
|
||||||
"Hard Rock"
|
|
||||||
"Folk"
|
|
||||||
"Folk-Rock"
|
|
||||||
"National Folk"
|
|
||||||
"Swing"
|
|
||||||
"Fast Fusion"
|
|
||||||
"Bebop"
|
|
||||||
"Latin"
|
|
||||||
"Revival"
|
|
||||||
"Celtic"
|
|
||||||
"Bluegrass"
|
|
||||||
"Avantgarde"
|
|
||||||
"Gothic Rock"
|
|
||||||
"Progressive Rock"
|
|
||||||
"Psychedelic Rock"
|
|
||||||
"Symphonic Rock"
|
|
||||||
"Slow Rock"
|
|
||||||
"Big Band"
|
|
||||||
"Chorus"
|
|
||||||
"Easy Listening"
|
|
||||||
"Acoustic"
|
|
||||||
"Humour"
|
|
||||||
"Speech"
|
|
||||||
"Chanson"
|
|
||||||
"Opera"
|
|
||||||
"Chamber Music"
|
|
||||||
"Sonata"
|
|
||||||
"Symphony"
|
|
||||||
"Booty Bass"
|
|
||||||
"Primus"
|
|
||||||
"Porn Groove"
|
|
||||||
"Satire"
|
|
||||||
"Slow Jam"
|
|
||||||
"Club"
|
|
||||||
"Tango"
|
|
||||||
"Samba"
|
|
||||||
"Folklore"
|
|
||||||
"Ballad"
|
|
||||||
"Power Ballad"
|
|
||||||
"Rhythmic Soul"
|
|
||||||
"Freestyle"
|
|
||||||
"Duet"
|
|
||||||
"Punk Rock"
|
|
||||||
"Drum Solo"
|
|
||||||
"A capella"
|
|
||||||
"Euro-House"
|
|
||||||
"Dance Hall"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TUPLE: header version flags size ;
|
TUPLE: header version flags size ;
|
||||||
|
@ -146,9 +45,9 @@ TUPLE: frame frame-id flags size data ;
|
||||||
|
|
||||||
TUPLE: id3v2-info header frames ;
|
TUPLE: id3v2-info header frames ;
|
||||||
|
|
||||||
TUPLE: id3-info title artist album year comment genre ;
|
TUPLE: id3v1-info title artist album year comment genre ;
|
||||||
|
|
||||||
: <id3-info> ( -- object ) id3-info new ;
|
: <id3v1-info> ( -- object ) id3v1-info new ;
|
||||||
|
|
||||||
: <id3v2-info> ( header frames -- object )
|
: <id3v2-info> ( header frames -- object )
|
||||||
[ [ frame-id>> ] keep ] H{ } map>assoc
|
[ [ frame-id>> ] keep ] H{ } map>assoc
|
||||||
|
@ -186,25 +85,12 @@ TUPLE: id3-info title artist album year comment genre ;
|
||||||
: filter-text-data ( data -- filtered )
|
: filter-text-data ( data -- filtered )
|
||||||
[ printable? ] filter ; inline
|
[ printable? ] filter ; inline
|
||||||
|
|
||||||
! frame details stuff
|
|
||||||
|
|
||||||
: valid-frame-id? ( id -- ? )
|
: valid-frame-id? ( id -- ? )
|
||||||
[ { [ digit? ] [ LETTER? ] } 1|| ] all? ; inline
|
[ { [ digit? ] [ LETTER? ] } 1|| ] all? ; inline
|
||||||
|
|
||||||
: read-frame-id ( mmap -- id )
|
|
||||||
4 head-slice ; inline
|
|
||||||
|
|
||||||
: read-frame-size ( mmap -- size )
|
|
||||||
[ 4 8 ] dip subseq ; inline
|
|
||||||
|
|
||||||
: read-frame-flags ( mmap -- flags )
|
|
||||||
[ 8 10 ] dip subseq ; inline
|
|
||||||
|
|
||||||
: read-frame-data ( frame mmap -- frame data )
|
: read-frame-data ( frame mmap -- frame data )
|
||||||
[ 10 over size>> 10 + ] dip <slice> filter-text-data ; inline
|
[ 10 over size>> 10 + ] dip <slice> filter-text-data ; inline
|
||||||
|
|
||||||
! read whole frames
|
|
||||||
|
|
||||||
: decode-text ( string -- string' )
|
: decode-text ( string -- string' )
|
||||||
dup 2 short head
|
dup 2 short head
|
||||||
{ { HEX: ff HEX: fe } { HEX: fe HEX: ff } } member?
|
{ { HEX: ff HEX: fe } { HEX: fe HEX: ff } } member?
|
||||||
|
@ -213,14 +99,14 @@ TUPLE: id3-info title artist album year comment genre ;
|
||||||
: (read-frame) ( mmap -- frame )
|
: (read-frame) ( mmap -- frame )
|
||||||
[ <frame> ] dip
|
[ <frame> ] dip
|
||||||
{
|
{
|
||||||
[ read-frame-id decode-text >>frame-id ]
|
[ 4 head-slice decode-text >>frame-id ]
|
||||||
[ read-frame-flags >byte-array >>flags ]
|
[ [ 4 8 ] dip subseq >28bitword >>size ]
|
||||||
[ read-frame-size >28bitword >>size ]
|
[ [ 8 10 ] dip subseq >byte-array >>flags ]
|
||||||
[ read-frame-data decode-text >>data ]
|
[ read-frame-data decode-text >>data ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
: read-frame ( mmap -- frame/f )
|
: read-frame ( mmap -- frame/f )
|
||||||
dup read-frame-id valid-frame-id?
|
dup 4 head-slice valid-frame-id?
|
||||||
[ (read-frame) ] [ drop f ] if ;
|
[ (read-frame) ] [ drop f ] if ;
|
||||||
|
|
||||||
: remove-frame ( mmap frame -- mmap )
|
: remove-frame ( mmap frame -- mmap )
|
||||||
|
@ -229,58 +115,36 @@ TUPLE: id3-info title artist album year comment genre ;
|
||||||
: read-frames ( mmap -- frames )
|
: read-frames ( mmap -- frames )
|
||||||
[ dup read-frame dup ]
|
[ dup read-frame dup ]
|
||||||
[ [ remove-frame ] keep ]
|
[ [ remove-frame ] keep ]
|
||||||
[ drop ] produce nip ;
|
produce 2nip ;
|
||||||
|
|
||||||
! header stuff
|
! header stuff
|
||||||
|
|
||||||
: read-header-supported-version? ( mmap -- ? )
|
: read-v2-header ( seq -- id3header )
|
||||||
3 tail-slice first { 3 4 } member? ; inline
|
|
||||||
|
|
||||||
: read-header-flags ( mmap -- flags ) 5 swap nth ; inline
|
|
||||||
|
|
||||||
: read-header-size ( mmap -- size )
|
|
||||||
[ 6 10 ] dip <slice> >28bitword ; inline
|
|
||||||
|
|
||||||
: read-v2-header ( mmap -- id3header )
|
|
||||||
[ <header> ] dip
|
[ <header> ] dip
|
||||||
{
|
{
|
||||||
[ read-header-supported-version? >>version ]
|
[ [ 3 5 ] dip <slice> >array >>version ]
|
||||||
[ read-header-flags >>flags ]
|
[ [ 5 ] dip nth >>flags ]
|
||||||
[ read-header-size >>size ]
|
[ [ 6 10 ] dip <slice> >28bitword >>size ]
|
||||||
} cleave ; inline
|
} cleave ; inline
|
||||||
|
|
||||||
: drop-header ( mmap -- seq1 seq2 )
|
|
||||||
[ 10 tail-slice ] [ ] bi ; inline
|
|
||||||
|
|
||||||
: read-v2-tag-data ( seq -- id3v2-info )
|
: read-v2-tag-data ( seq -- id3v2-info )
|
||||||
drop-header read-v2-header
|
10 cut-slice
|
||||||
swap read-frames <id3v2-info> ; inline
|
[ read-v2-header ]
|
||||||
|
[ read-frames ] bi* <id3v2-info> ; inline
|
||||||
|
|
||||||
! v1 information
|
! v1 information
|
||||||
|
|
||||||
: skip-to-v1-data ( seq -- seq ) 125 tail-slice* ; inline
|
: skip-to-v1-data ( seq -- seq ) 125 tail-slice* ; inline
|
||||||
|
|
||||||
: read-title ( seq -- title ) 30 head-slice ; inline
|
|
||||||
|
|
||||||
: read-artist ( seq -- title ) [ 30 60 ] dip subseq ; inline
|
|
||||||
|
|
||||||
: read-album ( seq -- album ) [ 60 90 ] dip subseq ; inline
|
|
||||||
|
|
||||||
: read-year ( seq -- year ) [ 90 94 ] dip subseq ; inline
|
|
||||||
|
|
||||||
: read-comment ( seq -- comment ) [ 94 124 ] dip subseq ; inline
|
|
||||||
|
|
||||||
: read-genre ( seq -- genre ) [ 124 ] dip nth ; inline
|
|
||||||
|
|
||||||
: (read-v1-tag-data) ( seq -- mp3-file )
|
: (read-v1-tag-data) ( seq -- mp3-file )
|
||||||
[ <id3-info> ] dip
|
[ <id3v1-info> ] dip
|
||||||
{
|
{
|
||||||
[ read-title decode-text filter-text-data >>title ]
|
[ 30 head-slice decode-text filter-text-data >>title ]
|
||||||
[ read-artist decode-text filter-text-data >>artist ]
|
[ [ 30 60 ] dip subseq decode-text filter-text-data >>artist ]
|
||||||
[ read-album decode-text filter-text-data >>album ]
|
[ [ 60 90 ] dip subseq decode-text filter-text-data >>album ]
|
||||||
[ read-year decode-text filter-text-data >>year ]
|
[ [ 90 94 ] dip subseq decode-text filter-text-data >>year ]
|
||||||
[ read-comment decode-text filter-text-data >>comment ]
|
[ [ 94 124 ] dip subseq decode-text filter-text-data >>comment ]
|
||||||
[ read-genre number>string >>genre ]
|
[ [ 124 ] dip nth number>string >>genre ]
|
||||||
} cleave ; inline
|
} cleave ; inline
|
||||||
|
|
||||||
: read-v1-tag-data ( seq -- mp3-file )
|
: read-v1-tag-data ( seq -- mp3-file )
|
||||||
|
|
|
@ -166,9 +166,7 @@ M: mach-error error.
|
||||||
IOObjectRelease mach-error ;
|
IOObjectRelease mach-error ;
|
||||||
|
|
||||||
: io-objects-from-iterator* ( i -- i array )
|
: io-objects-from-iterator* ( i -- i array )
|
||||||
[ dup IOIteratorNext dup MACH_PORT_NULL = not ]
|
[ dup IOIteratorNext dup MACH_PORT_NULL = not ] [ ] produce nip ;
|
||||||
[ ]
|
|
||||||
[ drop ] produce ;
|
|
||||||
|
|
||||||
: io-objects-from-iterator ( i -- array )
|
: io-objects-from-iterator ( i -- array )
|
||||||
io-objects-from-iterator* [ release-io-object ] dip ;
|
io-objects-from-iterator* [ release-io-object ] dip ;
|
||||||
|
|
|
@ -152,7 +152,7 @@ M: object handle-inbox
|
||||||
: display ( stream tab -- )
|
: display ( stream tab -- )
|
||||||
'[ _ [ [ t ]
|
'[ _ [ [ t ]
|
||||||
[ _ dup chat>> hear handle-inbox ]
|
[ _ dup chat>> hear handle-inbox ]
|
||||||
[ ] while ] with-output-stream ] "ircv" spawn drop ;
|
while ] with-output-stream ] "ircv" spawn drop ;
|
||||||
|
|
||||||
: <irc-pane> ( tab -- tab pane )
|
: <irc-pane> ( tab -- tab pane )
|
||||||
<scrolling-pane>
|
<scrolling-pane>
|
||||||
|
|
|
@ -4,4 +4,4 @@ USING: kernel math sequences ;
|
||||||
IN: math.text.utils
|
IN: math.text.utils
|
||||||
|
|
||||||
: 3digit-groups ( n -- seq )
|
: 3digit-groups ( n -- seq )
|
||||||
[ dup 0 > ] [ 1000 /mod ] [ ] produce nip ;
|
[ dup 0 > ] [ 1000 /mod ] produce nip ;
|
||||||
|
|
|
@ -82,7 +82,7 @@ SYMBOL: total
|
||||||
: topological-sort ( seq quot -- newseq )
|
: topological-sort ( seq quot -- newseq )
|
||||||
[ >vector [ dup empty? not ] ] dip
|
[ >vector [ dup empty? not ] ] dip
|
||||||
[ dupd maximal-element [ over delete-nth ] dip ] curry
|
[ dupd maximal-element [ over delete-nth ] dip ] curry
|
||||||
[ ] produce nip ; inline
|
produce nip ; inline
|
||||||
|
|
||||||
: classes< ( seq1 seq2 -- lt/eq/gt )
|
: classes< ( seq1 seq2 -- lt/eq/gt )
|
||||||
[
|
[
|
||||||
|
|
|
@ -223,7 +223,7 @@ CONSTANT: otug-slides
|
||||||
}
|
}
|
||||||
{ $slide "Modifiers"
|
{ $slide "Modifiers"
|
||||||
{ $code ": bank ( n -- n )" " readln string>number +" " dup \"Balance: $\" write . ;" }
|
{ $code ": bank ( n -- n )" " readln string>number +" " dup \"Balance: $\" write . ;" }
|
||||||
{ $code "0 [ dup 0 > ] [ bank ] [ ] while" }
|
{ $code "0 [ dup 0 > ] [ bank ] while" }
|
||||||
}
|
}
|
||||||
{ $slide "Modifiers"
|
{ $slide "Modifiers"
|
||||||
{ $code "0 [ dup 0 > ] [ bank ] [ ] do while" }
|
{ $code "0 [ dup 0 > ] [ bank ] [ ] do while" }
|
||||||
|
|
|
@ -41,7 +41,7 @@ PRIVATE>
|
||||||
! -------------------
|
! -------------------
|
||||||
|
|
||||||
: fib-upto* ( n -- seq )
|
: fib-upto* ( n -- seq )
|
||||||
0 1 [ pick over >= ] [ tuck + dup ] [ ] produce [ 3drop ] dip
|
0 1 [ pick over >= ] [ tuck + dup ] produce [ 3drop ] dip
|
||||||
but-last-slice { 0 1 } prepend ;
|
but-last-slice { 0 1 } prepend ;
|
||||||
|
|
||||||
: euler002a ( -- answer )
|
: euler002a ( -- answer )
|
||||||
|
|
|
@ -34,7 +34,7 @@ IN: project-euler.012
|
||||||
! --------
|
! --------
|
||||||
|
|
||||||
: euler012 ( -- answer )
|
: euler012 ( -- answer )
|
||||||
8 [ dup nth-triangle tau* 500 < ] [ 1+ ] [ ] while nth-triangle ;
|
8 [ dup nth-triangle tau* 500 < ] [ 1+ ] while nth-triangle ;
|
||||||
|
|
||||||
! [ euler012 ] 10 ave-time
|
! [ euler012 ] 10 ave-time
|
||||||
! 6573 ms ave run time - 346.27 SD (10 trials)
|
! 6573 ms ave run time - 346.27 SD (10 trials)
|
||||||
|
|
|
@ -43,7 +43,7 @@ IN: project-euler.014
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: collatz ( n -- seq )
|
: collatz ( n -- seq )
|
||||||
[ [ dup 1 > ] [ dup , next-collatz ] [ ] while , ] { } make ;
|
[ [ dup 1 > ] [ dup , next-collatz ] while , ] { } make ;
|
||||||
|
|
||||||
: euler014 ( -- answer )
|
: euler014 ( -- answer )
|
||||||
1000000 [1,b] 0 [ collatz longest ] reduce first ;
|
1000000 [1,b] 0 [ collatz longest ] reduce first ;
|
||||||
|
|
|
@ -53,7 +53,7 @@ IN: project-euler.019
|
||||||
: first-days ( end-date start-date -- days )
|
: first-days ( end-date start-date -- days )
|
||||||
[ 2dup after=? ]
|
[ 2dup after=? ]
|
||||||
[ dup 1 months time+ swap day-of-week ]
|
[ dup 1 months time+ swap day-of-week ]
|
||||||
[ ] produce 2nip ;
|
produce 2nip ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ IN: project-euler.071
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: euler071 ( -- answer )
|
: euler071 ( -- answer )
|
||||||
2/5 [ dup denominator 1000000 <= ] [ 3/7 mediant dup ] [ ] produce
|
2/5 [ dup denominator 1000000 <= ] [ 3/7 mediant dup ] produce
|
||||||
nip penultimate numerator ;
|
nip penultimate numerator ;
|
||||||
|
|
||||||
! [ euler071 ] 100 ave-time
|
! [ euler071 ] 100 ave-time
|
||||||
|
|
|
@ -26,7 +26,7 @@ IN: project-euler.100
|
||||||
: euler100 ( -- answer )
|
: euler100 ( -- answer )
|
||||||
1 1
|
1 1
|
||||||
[ dup dup 1- * 2 * 10 24 ^ <= ]
|
[ dup dup 1- * 2 * 10 24 ^ <= ]
|
||||||
[ tuck 6 * swap - 2 - ] [ ] while nip ;
|
[ tuck 6 * swap - 2 - ] while nip ;
|
||||||
|
|
||||||
! TODO: solution needs generalization
|
! TODO: solution needs generalization
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ IN: project-euler.148
|
||||||
dup 1+ * 2/ ; inline
|
dup 1+ * 2/ ; inline
|
||||||
|
|
||||||
: >base7 ( x -- y )
|
: >base7 ( x -- y )
|
||||||
[ dup 0 > ] [ 7 /mod ] [ ] produce nip ;
|
[ dup 0 > ] [ 7 /mod ] produce nip ;
|
||||||
|
|
||||||
: (use-digit) ( prev x index -- next )
|
: (use-digit) ( prev x index -- next )
|
||||||
[ [ 1+ * ] [ sum-1toN 7 sum-1toN ] bi ] dip ^ * + ;
|
[ [ 1+ * ] [ sum-1toN 7 sum-1toN ] bi ] dip ^ * + ;
|
||||||
|
|
|
@ -72,7 +72,7 @@ PRIVATE>
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: number>digits ( n -- seq )
|
: number>digits ( n -- seq )
|
||||||
[ dup 0 = not ] [ 10 /mod ] [ ] produce reverse nip ;
|
[ dup 0 = not ] [ 10 /mod ] produce reverse nip ;
|
||||||
|
|
||||||
: nth-triangle ( n -- n )
|
: nth-triangle ( n -- n )
|
||||||
dup 1+ * 2 / ;
|
dup 1+ * 2 / ;
|
||||||
|
|
|
@ -126,12 +126,9 @@ MACRO: multikeep ( word out-indexes -- ... )
|
||||||
r> [ drop \ r> , ] each
|
r> [ drop \ r> , ] each
|
||||||
] [ ] make ;
|
] [ ] make ;
|
||||||
|
|
||||||
: do-while ( pred body tail -- )
|
|
||||||
[ tuck 2slip ] dip while ; inline
|
|
||||||
|
|
||||||
: generate ( generator predicate -- obj )
|
: generate ( generator predicate -- obj )
|
||||||
'[ dup @ dup [ nip ] unless not ]
|
'[ dup @ dup [ nip ] unless ]
|
||||||
swap [ ] do-while ;
|
swap do until ;
|
||||||
|
|
||||||
MACRO: predicates ( seq -- quot/f )
|
MACRO: predicates ( seq -- quot/f )
|
||||||
dup [ 1quotation [ drop ] prepend ] map
|
dup [ 1quotation [ drop ] prepend ] map
|
||||||
|
|
Loading…
Reference in New Issue