Eduardo Cavazos 2008-12-02 14:26:16 -06:00
commit b006e00274
38 changed files with 172 additions and 141 deletions

View File

@ -130,7 +130,7 @@ M: register modifier drop BIN: 11 ;
GENERIC# n, 1 ( value n -- )
M: integer n, >le % ;
M: byte n, >r value>> r> n, ;
M: byte n, [ value>> ] dip n, ;
: 1, ( n -- ) 1 n, ; inline
: 4, ( n -- ) 4 n, ; inline
: 2, ( n -- ) 2 n, ; inline
@ -209,7 +209,7 @@ M: object operand-64? drop f ;
: short-operand ( reg rex.w n -- )
#! Some instructions encode their single operand as part of
#! the opcode.
>r dupd prefix-1 reg-code r> + , ;
[ dupd prefix-1 reg-code ] dip + , ;
: opcode, ( opcode -- ) dup array? [ % ] [ , ] if ;
@ -224,7 +224,7 @@ M: object operand-64? drop f ;
: 1-operand ( op reg,rex.w,opcode -- )
#! The 'reg' is not really a register, but a value for the
#! 'reg' field of the mod-r/m byte.
first3 >r >r over r> prefix-1 r> opcode, swap addressing ;
first3 [ [ over ] dip prefix-1 ] dip opcode, swap addressing ;
: immediate-operand-size-bit ( imm dst reg,rex.w,opcode -- imm dst reg,rex.w,opcode )
pick integer? [ first3 BIN: 1 opcode-or 3array ] when ;
@ -250,7 +250,7 @@ M: object operand-64? drop f ;
] if ;
: (2-operand) ( dst src op -- )
>r 2dup t rex-prefix r> opcode,
[ 2dup t rex-prefix ] dip opcode,
reg-code swap addressing ;
: direction-bit ( dst src op -- dst' src' op' )
@ -271,11 +271,11 @@ M: object operand-64? drop f ;
PRIVATE>
: [] ( reg/displacement -- indirect )
dup integer? [ >r f f f r> ] [ f f f ] if <indirect> ;
dup integer? [ [ f f f ] dip ] [ f f f ] if <indirect> ;
: [+] ( reg displacement -- indirect )
dup integer?
[ dup zero? [ drop f ] when >r f f r> ]
[ dup zero? [ drop f ] when [ f f ] dip ]
[ f f ] if
<indirect> ;

View File

@ -4,8 +4,8 @@ USING: kernel words sequences lexer parser fry ;
IN: cpu.x86.assembler.syntax
: define-register ( name num size -- )
>r >r "cpu.x86.assembler" create dup define-symbol r> r>
>r dupd "register" set-word-prop r>
[ "cpu.x86.assembler" create dup define-symbol ] 2dip
[ dupd "register" set-word-prop ] dip
"register-size" set-word-prop ;
: define-registers ( names size -- )

View File

@ -27,6 +27,9 @@ HOOK: (set-os-envs) os ( seq -- )
} cond
[
"FACTOR_ROOTS" os-env os windows? ";" ":" ? split
[ add-vocab-root ] each
"FACTOR_ROOTS" os-env
[
os windows? ";" ":" ? split
[ add-vocab-root ] each
] when*
] "environment" add-init-hook

View File

@ -46,10 +46,10 @@ $nl
"{ 10 20 30 } [ sq ] [ . ] compose each"
"{ 10 20 30 } [ sq . ] each"
}
"The " { $link _ } " and " { $link @ } " specifiers may be freely mixed:"
"The " { $link _ } " and " { $link @ } " specifiers may be freely mixed, and the result is considerably more concise and readable than the version using " { $link curry } " and " { $link compose } " directly:"
{ $code
"{ 8 13 14 27 } [ even? ] 5 '[ @ dup _ ? ] map"
"{ 8 13 14 27 } [ even? ] 5 [ dup ] swap [ ? ] curry 3compose map"
"{ 8 13 14 27 } [ even? ] 5 [ dup ] swap [ ? ] curry compose compose map"
"{ 8 13 14 27 } [ even? dup 5 ? ] map"
}
"The following is a no-op:"

View File

@ -5,7 +5,7 @@ destructors ;
: buffer-set ( string buffer -- )
over >byte-array over ptr>> byte-array>memory
>r length r> buffer-reset ;
[ length ] dip buffer-reset ;
: string>buffer ( string -- buffer )
dup length <buffer> tuck buffer-set ;

View File

@ -25,7 +25,7 @@ ERROR: missing-bom ;
: quad-be ( stream byte -- stream char )
double-be over stream-read1 [
dup -2 shift BIN: 110111 number= [
>r 2 shift r> BIN: 11 bitand bitor
[ 2 shift ] dip BIN: 11 bitand bitor
over stream-read1 swap append-nums HEX: 10000 +
] [ 2drop dup stream-read1 drop replacement-char ] if
] when* ;

View File

@ -53,7 +53,7 @@ SYMBOL: +rename-file-new+
SYMBOL: +rename-file+
: with-monitor ( path recursive? quot -- )
>r <monitor> r> with-disposal ; inline
[ <monitor> ] dip with-disposal ; inline
{
{ [ os macosx? ] [ "io.unix.macosx.monitors" require ] }

View File

@ -3,7 +3,7 @@
USING: accessors sequences assocs arrays continuations
destructors combinators kernel threads concurrency.messaging
concurrency.mailboxes concurrency.promises io.files io.monitors
debugger ;
debugger fry ;
IN: io.monitors.recursive
! Simulate recursive monitors on platforms that don't have them
@ -29,10 +29,10 @@ DEFER: add-child-monitor
qualify-path dup link-info directory? [
[ add-child-monitors ]
[
[
[ f my-mailbox (monitor) ] keep
'[
_ [ f my-mailbox (monitor) ] keep
monitor tget children>> set-at
] curry ignore-errors
] ignore-errors
] bi
] [ drop ] if ;
@ -48,7 +48,7 @@ M: recursive-monitor dispose*
monitor tget children>> [ nip dispose ] assoc-each ;
: pump-step ( msg -- )
first3 path>> swap >r prepend-path r> monitor tget 3array
first3 path>> swap [ prepend-path ] dip monitor tget 3array
monitor tget queue>>
mailbox-put ;
@ -71,9 +71,9 @@ M: recursive-monitor dispose*
: pump-loop ( -- )
receive dup synchronous? [
>r stop-pump t r> reply-synchronous
[ stop-pump t ] dip reply-synchronous
] [
[ [ update-hierarchy ] curry ignore-errors ] [ pump-step ] bi
[ '[ _ update-hierarchy ] ignore-errors ] [ pump-step ] bi
pump-loop
] if ;
@ -88,7 +88,7 @@ M: recursive-monitor dispose*
pump-loop ;
: start-pump-thread ( monitor -- )
dup [ pump-thread ] curry
dup '[ _ pump-thread ]
"Recursive monitor pump" spawn
>>thread drop ;
@ -96,7 +96,7 @@ M: recursive-monitor dispose*
ready>> ?promise ?linked drop ;
: <recursive-monitor> ( path mailbox -- monitor )
>r (normalize-path) r>
[ (normalize-path) ] dip
recursive-monitor new-monitor
H{ } clone >>children
<promise> >>ready

View File

@ -42,7 +42,7 @@ GENERIC: make-connection ( pool -- conn )
[ nip call ] [ drop return-connection ] 3bi ; inline
: with-pooled-connection ( pool quot -- )
>r [ acquire-connection ] keep r>
[ [ acquire-connection ] keep ] dip
[ (with-pooled-connection) ] [ ] [ 2drop dispose ] cleanup ; inline
M: return-connection dispose

View File

@ -27,7 +27,7 @@ M: duplex-stream dispose
] with-destructors ;
: <encoder-duplex> ( stream-in stream-out encoding -- duplex )
tuck re-encode >r re-decode r> <duplex-stream> ;
tuck [ re-decode ] [ re-encode ] 2bi* <duplex-stream> ;
: with-stream* ( stream quot -- )
[ [ in>> ] [ out>> ] bi ] dip with-streams* ; inline

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Slava Pestov, Doug Coleman
! See http://factorcode.org/license.txt for BSD license.
USING: kernel calendar alarms io io.encodings accessors
namespaces ;
namespaces fry ;
IN: io.timeouts
GENERIC: timeout ( obj -- dt/f )
@ -14,14 +14,14 @@ M: encoder set-timeout stream>> set-timeout ;
GENERIC: cancel-operation ( obj -- )
: queue-timeout ( obj timeout -- alarm )
>r [ cancel-operation ] curry r> later ;
[ '[ _ cancel-operation ] ] dip later ;
: with-timeout* ( obj timeout quot -- )
3dup drop queue-timeout >r nip call r> cancel-alarm ;
3dup drop queue-timeout [ nip call ] dip cancel-alarm ;
inline
: with-timeout ( obj quot -- )
over timeout [ >r dup timeout r> with-timeout* ] [ call ] if ;
over timeout [ [ dup timeout ] dip with-timeout* ] [ call ] if ;
inline
: timeouts ( dt -- )

View File

@ -5,7 +5,7 @@ math io.ports sequences strings sbufs threads unix
vectors io.buffers io.backend io.encodings math.parser
continuations system libc qualified namespaces make io.timeouts
io.encodings.utf8 destructors accessors summary combinators
locals unix.time ;
locals unix.time fry ;
QUALIFIED: io
IN: io.unix.backend
@ -88,19 +88,16 @@ M: io-timeout summary drop "I/O operation timed out" ;
: wait-for-fd ( handle event -- )
dup +retry+ eq? [ 2drop ] [
[
>r
swap handle-fd
mx get-global
r> {
'[
swap handle-fd mx get-global _ {
{ +input+ [ add-input-callback ] }
{ +output+ [ add-output-callback ] }
} case
] curry "I/O" suspend nip [ io-timeout ] when
] "I/O" suspend nip [ io-timeout ] when
] if ;
: wait-for-port ( port event -- )
[ >r handle>> r> wait-for-fd ] curry with-timeout ;
'[ handle>> _ wait-for-fd ] with-timeout ;
! Some general stuff
: file-mode OCT: 0666 ;

View File

@ -36,9 +36,7 @@ TUPLE: linux-monitor < monitor wd inotify watches disposed ;
inotify-fd -rot inotify_add_watch dup io-error dup check-existing ;
: add-watch ( path mask mailbox -- monitor )
>r
>r (normalize-path) r>
[ (add-watch) ] [ drop ] 2bi r>
[ [ (normalize-path) ] dip [ (add-watch) ] [ drop ] 2bi ] dip
<linux-monitor> [ ] [ ] [ wd>> ] tri watches get set-at ;
: check-inotify ( -- )
@ -103,12 +101,12 @@ M: linux-monitor dispose* ( monitor -- )
: next-event ( i buffer -- i buffer )
2dup inotify-event@
inotify-event-len "inotify-event" heap-size +
swap >r + r> ;
swap [ + ] dip ;
: parse-file-notifications ( i buffer -- )
2dup events-exhausted? [ 2drop ] [
2dup inotify-event@ dup inotify-event-wd wd>monitor
>r parse-file-notify r> queue-change
[ parse-file-notify ] dip queue-change
next-event parse-file-notifications
] if ;

View File

@ -2,15 +2,13 @@
! See http://factorcode.org/license.txt for BSD license.
USING: io.backend io.monitors
core-foundation.fsevents continuations kernel sequences
namespaces arrays system locals accessors destructors ;
namespaces arrays system locals accessors destructors fry ;
IN: io.unix.macosx.monitors
TUPLE: macosx-monitor < monitor handle ;
: enqueue-notifications ( triples monitor -- )
[
>r first { +modify-file+ } r> queue-change
] curry each ;
'[ first { +modify-file+ } _ queue-change ] each ;
M:: macosx (monitor) ( path recursive? mailbox -- monitor )
[let | path [ path normalize-path ] |

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types kernel io.ports io.unix.backend
bit-arrays sequences assocs unix math namespaces
accessors math.order locals unix.time ;
accessors math.order locals unix.time fry ;
IN: io.unix.select
TUPLE: select-mx < mx read-fdset write-fdset ;
@ -28,7 +28,7 @@ TUPLE: select-mx < mx read-fdset write-fdset ;
[ check-fd ] 3curry each ; inline
: init-fdset ( fds fdset -- )
[ >r t swap munge r> set-nth ] curry each ;
'[ t swap munge _ set-nth ] each ;
: read-fdset/tasks ( mx -- seq fdset )
[ reads>> keys ] [ read-fdset>> ] bi ;

View File

@ -16,18 +16,18 @@ IN: io.unix.sockets
0 socket dup io-error <fd> init-fd |dispose ;
: set-socket-option ( fd level opt -- )
>r >r handle-fd r> r> 1 <int> "int" heap-size setsockopt io-error ;
[ handle-fd ] 2dip 1 <int> "int" heap-size setsockopt io-error ;
M: unix addrinfo-error ( n -- )
dup zero? [ drop ] [ gai_strerror throw ] if ;
! Client sockets - TCP and Unix domain
M: object (get-local-address) ( handle remote -- sockaddr )
>r handle-fd r> empty-sockaddr/size <int>
[ handle-fd ] dip empty-sockaddr/size <int>
[ getsockname io-error ] 2keep drop ;
M: object (get-remote-address) ( handle local -- sockaddr )
>r handle-fd r> empty-sockaddr/size <int>
[ handle-fd ] dip empty-sockaddr/size <int>
[ getpeername io-error ] 2keep drop ;
: init-client-socket ( fd -- )
@ -60,7 +60,7 @@ M: object ((client)) ( addrspec -- fd )
SOL_SOCKET SO_REUSEADDR set-socket-option ;
: server-socket-fd ( addrspec type -- fd )
>r dup protocol-family r> socket-fd
[ dup protocol-family ] dip socket-fd
dup init-server-socket
dup handle-fd rot make-sockaddr/size bind io-error ;
@ -77,7 +77,7 @@ M: object (server) ( addrspec -- handle )
M: object (accept) ( server addrspec -- fd sockaddr )
2dup do-accept
{
{ [ over 0 >= ] [ >r 2nip <fd> init-fd r> ] }
{ [ over 0 >= ] [ [ 2nip <fd> init-fd ] dip ] }
{ [ err_no EINTR = ] [ 2drop (accept) ] }
{ [ err_no EAGAIN = ] [
2drop

View File

@ -46,7 +46,7 @@ yield
"Receive 1" print
"d" get receive >r reverse r>
"d" get receive [ reverse ] dip
"Send 1" print
dup .
@ -55,7 +55,7 @@ yield
"Receive 2" print
"d" get receive >r " world" append r>
"d" get receive [ " world" append ] dip
"Send 1" print
dup .
@ -86,7 +86,7 @@ datagram-client <local> <datagram>
[ "olleh" t ] [
"d" get receive
datagram-server <local> =
>r >string r>
[ >string ] dip
] unit-test
[ ] [
@ -98,7 +98,7 @@ datagram-client <local> <datagram>
[ "hello world" t ] [
"d" get receive
datagram-server <local> =
>r >string r>
[ >string ] dip
] unit-test
[ ] [ "d" get dispose ] unit-test

View File

@ -10,7 +10,7 @@ IN: io.windows.files
: open-file ( path access-mode create-mode flags -- handle )
[
>r >r share-mode default-security-attributes r> r>
[ share-mode default-security-attributes ] 2dip
CreateFile-flags f CreateFile opened-file
] with-destructors ;
@ -46,7 +46,7 @@ IN: io.windows.files
GetLastError ERROR_ALREADY_EXISTS = not ;
: set-file-pointer ( handle length method -- )
>r dupd d>w/w <uint> r> SetFilePointer
[ dupd d>w/w <uint> ] dip SetFilePointer
INVALID_SET_FILE_POINTER = [
CloseHandle "SetFilePointer failed" throw
] when drop ;
@ -348,23 +348,23 @@ M: winnt file-systems ( -- array )
: set-file-times ( path timestamp/f timestamp/f timestamp/f -- )
#! timestamp order: creation access write
[
>r >r >r
[
normalize-path open-existing &dispose handle>>
r> r> r> (set-file-times)
] 3dip (set-file-times)
] with-destructors ;
: set-file-create-time ( path timestamp -- )
f f set-file-times ;
: set-file-access-time ( path timestamp -- )
>r f r> f set-file-times ;
[ f ] dip f set-file-times ;
: set-file-write-time ( path timestamp -- )
>r f f r> set-file-times ;
[ f f ] dip set-file-times ;
M: winnt touch-file ( path -- )
[
normalize-path
maybe-create-file >r &dispose r>
maybe-create-file [ &dispose ] dip
[ drop ] [ handle>> f now dup (set-file-times) ] if
] with-destructors ;

View File

@ -18,8 +18,8 @@ C: <io-callback> io-callback
"OVERLAPPED" malloc-object &free ;
: make-overlapped ( port -- overlapped-ext )
>r (make-overlapped)
r> handle>> ptr>> [ over set-OVERLAPPED-offset ] when* ;
[ (make-overlapped) ] dip
handle>> ptr>> [ over set-OVERLAPPED-offset ] when* ;
: <completion-port> ( handle existing -- handle )
f 1 CreateIoCompletionPort dup win32-error=0/f ;
@ -64,13 +64,9 @@ M: winnt add-completion ( win32-handle -- )
: handle-overlapped ( us -- ? )
wait-for-overlapped [
dup [
>r drop GetLastError 1array r> resume-callback t
] [
2drop f
] if
] [
resume-callback t
] if ;
[ drop GetLastError 1array ] dip resume-callback t
] [ 2drop f ] if
] [ resume-callback t ] if ;
M: win32-handle cancel-operation
[ check-disposed ] [ handle>> CancelIo drop ] bi ;
@ -94,7 +90,7 @@ M: winnt init-io ( -- )
: wait-for-file ( FileArgs n port -- n )
swap file-error?
[ 2drop 0 ] [ >r lpOverlapped>> r> twiddle-thumbs ] if ;
[ 2drop 0 ] [ [ lpOverlapped>> ] dip twiddle-thumbs ] if ;
: update-file-ptr ( n port -- )
handle>> dup ptr>> [ rot + >>ptr drop ] [ 2drop ] if* ;

View File

@ -59,6 +59,6 @@ M: winnt FileArgs-overlapped ( port -- overlapped )
M: winnt open-append
[ dup file-info size>> ] [ drop 0 ] recover
>r (open-append) r> >>ptr ;
[ (open-append) ] dip >>ptr ;
M: winnt home "USERPROFILE" os-env ;

View File

@ -52,7 +52,7 @@ IN: io.windows.nt.launcher
CreateFile dup invalid-handle? <win32-file> &dispose handle>> ;
: redirect-append ( path access-mode create-mode -- handle )
>r >r path>> r> r>
[ path>> ] 2dip
drop OPEN_ALWAYS
redirect-file
dup 0 FILE_END set-file-pointer ;
@ -61,7 +61,7 @@ IN: io.windows.nt.launcher
2drop handle>> duplicate-handle ;
: redirect-stream ( stream access-mode create-mode -- handle )
>r >r underlying-handle handle>> r> r> redirect-handle ;
[ underlying-handle handle>> ] 2dip redirect-handle ;
: redirect ( obj access-mode create-mode -- handle )
{

View File

@ -20,12 +20,12 @@ TYPEDEF: TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES
: with-process-token ( quot -- )
#! quot: ( token-handle -- token-handle )
>r open-process-token r>
[ open-process-token ] dip
[ keep ] curry
[ CloseHandle drop ] [ ] cleanup ; inline
: lookup-privilege ( string -- luid )
>r f r> "LUID" <c-object>
[ f ] dip "LUID" <c-object>
[ LookupPrivilegeValue win32-error=0/f ] keep ;
: make-token-privileges ( name ? -- obj )
@ -39,10 +39,10 @@ TYPEDEF: TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES
set-LUID_AND_ATTRIBUTES-Attributes
] when
>r lookup-privilege r>
[ lookup-privilege ] dip
[
TOKEN_PRIVILEGES-Privileges
>r 0 r> LUID_AND_ATTRIBUTES-nth
[ 0 ] dip LUID_AND_ATTRIBUTES-nth
set-LUID_AND_ATTRIBUTES-Luid
] keep ;

View File

@ -176,8 +176,8 @@ TUPLE: WSASendTo-args port
: make-send-buffer ( packet -- WSABUF )
"WSABUF" malloc-object &free
[ >r malloc-byte-array &free r> set-WSABUF-buf ]
[ >r length r> set-WSABUF-len ]
[ [ malloc-byte-array &free ] dip set-WSABUF-buf ]
[ [ length ] dip set-WSABUF-len ]
[ nip ]
2tri ; inline
@ -186,8 +186,8 @@ TUPLE: WSASendTo-args port
swap >>port
dup port>> handle>> handle>> >>s
swap make-sockaddr/size
>r malloc-byte-array &free
r> [ >>lpTo ] [ >>iToLen ] bi*
[ malloc-byte-array &free ] dip
[ >>lpTo ] [ >>iToLen ] bi*
swap make-send-buffer >>lpBuffers
1 >>dwBufferCount
0 >>dwFlags

View File

@ -20,21 +20,21 @@ M: win32-socket dispose ( stream -- )
<win32-socket> |dispose dup add-completion ;
: open-socket ( addrspec type -- win32-socket )
>r protocol-family r>
[ protocol-family ] dip
0 f 0 WSASocket-flags WSASocket
dup socket-error
opened-socket ;
M: object (get-local-address) ( socket addrspec -- sockaddr )
>r handle>> r> empty-sockaddr/size <int>
[ handle>> ] dip empty-sockaddr/size <int>
[ getsockname socket-error ] 2keep drop ;
M: object (get-remote-address) ( socket addrspec -- sockaddr )
>r handle>> r> empty-sockaddr/size <int>
[ handle>> ] dip empty-sockaddr/size <int>
[ getpeername socket-error ] 2keep drop ;
: bind-socket ( win32-socket sockaddr len -- )
>r >r handle>> r> r> bind socket-error ;
[ handle>> ] 2dip bind socket-error ;
M: object ((client)) ( addrspec -- handle )
[ SOCK_STREAM open-socket ] keep

View File

@ -8,7 +8,8 @@ splitting continuations math.bitwise system accessors ;
IN: io.windows
: set-inherit ( handle ? -- )
>r HANDLE_FLAG_INHERIT r> >BOOLEAN SetHandleInformation win32-error=0/f ;
[ HANDLE_FLAG_INHERIT ] dip
>BOOLEAN SetHandleInformation win32-error=0/f ;
TUPLE: win32-handle handle disposed ;

View File

@ -1 +0,0 @@
Doug Coleman

View File

@ -1,6 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax kernel unix.stat math unix
combinators system io.backend accessors alien.c-types
io.encodings.utf8 alien.strings unix.types unix.statfs io.files ;
IN: unix.statfs.netbsd

View File

@ -8,6 +8,6 @@ os {
{ linux [ "unix.statfs.linux" require ] }
{ macosx [ "unix.statfs.macosx" require ] }
{ freebsd [ "unix.statfs.freebsd" require ] }
{ netbsd [ "unix.statfs.netbsd" require ] }
{ openbsd [ "unix.statfs.openbsd" require ] }
! { netbsd [ "unix.statfs.netbsd" require ] }
! { openbsd [ "unix.statfs.openbsd" require ] }
} case

View File

@ -1,30 +1,30 @@
USING: accessors sequences assocs kernel quotations namespaces
xml.data xml.utilities combinators macros parser lexer words ;
xml.data xml.utilities combinators macros parser lexer words fry ;
IN: xmode.utilities
: implies >r not r> or ; inline
: implies [ not ] dip or ; inline
: child-tags ( tag -- seq ) children>> [ tag? ] filter ;
: map-find ( seq quot -- result elt )
f -rot
[ nip ] swap [ dup ] 3compose find
>r [ drop f ] unless r> ; inline
'[ nip @ dup ] find
[ [ drop f ] unless ] dip ; inline
: tag-init-form ( spec -- quot )
{
{ [ dup quotation? ] [ [ object get tag get ] prepose ] }
{ [ dup length 2 = ] [
first2 [
>r >r tag get children>string
r> [ execute ] when* object get r> execute
] 2curry
first2 '[
tag get children>string
_ [ execute ] when* object get _ execute
]
] }
{ [ dup length 3 = ] [
first3 [
>r >r tag get at
r> [ execute ] when* object get r> execute
] 3curry
first3 '[
_ tag get at
_ [ execute ] when* object get _ execute
]
] }
} cond ;
@ -36,7 +36,7 @@ MACRO: (init-from-tag) ( specs -- )
[ with-tag-initializer ] curry ;
: init-from-tag ( tag tuple specs -- tuple )
over >r (init-from-tag) r> ; inline
over [ (init-from-tag) ] dip ; inline
SYMBOL: tag-handlers
SYMBOL: tag-handler-word

View File

@ -65,7 +65,7 @@ SYMBOL: error-stream
: with-streams ( input output quot -- )
[ [ with-streams* ] 3curry ]
[ [ drop dispose dispose ] 3curry ] 3bi
[ drop [ [ dispose ] bi@ ] 2curry ] 3bi
[ ] cleanup ; inline
: tabular-output ( style quot -- )

View File

@ -578,18 +578,6 @@ HELP: prepose
{ compose prepose } related-words
HELP: 3compose
{ $values { "quot1" callable } { "quot2" callable } { "quot3" callable } { "compose" compose } }
{ $description "Quotation composition. Outputs a " { $link callable } " which calls " { $snippet "quot1" } ", " { $snippet "quot2" } " and then " { $snippet "quot3" } "." }
{ $notes
"The following two lines are equivalent:"
{ $code
"3compose call"
"3append call"
}
"However, " { $link 3compose } " runs in constant time, and the compiler is able to compile code which calls composed quotations."
} ;
HELP: dip
{ $values { "x" object } { "quot" quotation } }
{ $description "Calls " { $snippet "quot" } " with " { $snippet "obj" } " hidden on the retain stack." }
@ -814,7 +802,6 @@ ARTICLE: "compositional-combinators" "Compositional combinators"
{ $subsection 3curry }
{ $subsection with }
{ $subsection compose }
{ $subsection 3compose }
{ $subsection prepose }
"Quotations also implement the sequence protocol, and can be manipulated with sequence words; see " { $link "quotations" } "." ;

View File

@ -179,9 +179,6 @@ GENERIC: boa ( ... class -- tuple )
: prepose ( quot1 quot2 -- compose )
swap compose ; inline
: 3compose ( quot1 quot2 quot3 -- compose )
compose compose ; inline
! Booleans
: not ( obj -- ? ) [ f ] [ t ] if ; inline

View File

@ -0,0 +1,11 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: io.encodings.utf8 io.files kernel sequences xml ;
IN: benchmark.xml
: xml-benchmark ( -- )
"resource:basis/xmode/modes/" [
[ utf8 <file-reader> read-xml drop ] each
] with-directory-files ;
MAIN: xml-benchmark

View File

@ -142,7 +142,7 @@ MACRO: multikeep ( word out-indexes -- ... )
[ tuck 2slip ] dip while ; inline
: generate ( generator predicate -- obj )
[ dup ] swap [ dup [ nip ] unless not ] 3compose
'[ dup @ dup [ nip ] unless not ]
swap [ ] do-while ;
MACRO: predicates ( seq -- quot/f )

View File

@ -5,7 +5,7 @@ sequences assocs math arrays stack-checker effects generalizations
continuations debugger classes.tuple namespaces make vectors
bit-arrays byte-arrays strings sbufs math.functions macros
sequences.private combinators mirrors
combinators.short-circuit ;
combinators.short-circuit fry ;
IN: inverse
TUPLE: fail ;
@ -46,7 +46,7 @@ M: no-inverse summary
dup word? [ "Badly formed math inverse" throw ] when 1quotation ;
: swap-inverse ( math-inverse revquot -- revquot* quot )
next assure-constant rot second [ swap ] swap 3compose ;
next assure-constant rot second '[ @ swap @ ] ;
: pull-inverse ( math-inverse revquot const -- revquot* quot )
assure-constant rot first compose ;
@ -236,8 +236,7 @@ DEFER: _
] recover ; inline
: true-out ( quot effect -- quot' )
out>> [ ndrop ] curry
[ t ] 3compose ;
out>> '[ @ _ ndrop t ] ;
: false-recover ( effect -- quot )
in>> [ ndrop f ] curry [ recover-fail ] curry ;

View File

@ -0,0 +1,55 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: fry irc.client irc.client.private kernel namespaces
sequences threads io.encodings.8-bit io.launcher io splitting
make mason.common mason.updates calendar math alarms ;
IN: irc.gitbot
: bot-profile ( -- obj )
"irc.freenode.org" 6667 "jackass" f <irc-profile> ;
: bot-channel ( -- seq ) "#concatenative" ;
GENERIC: handle-message ( msg -- )
M: object handle-message drop ;
: bot-loop ( chat -- )
dup hear handle-message bot-loop ;
: start-bot ( -- chat )
bot-profile <irc-client>
[ connect-irc ]
[
[ bot-channel <irc-channel-chat> dup ] dip
'[ _ [ _ attach-chat ] [ bot-loop ] bi ]
"GitBot" spawn drop
] bi ;
: git-log ( from to -- lines )
[
"git-log" ,
"--no-merges" ,
"--pretty=format:%h %an: %s" ,
".." swap 3append ,
] { } make
latin1 [ input-stream get lines ] with-process-reader ;
: updates ( from to -- lines )
git-log reverse
dup length 4 > [ 4 head "... and more" suffix ] when ;
: report-updates ( from to chat -- )
[ updates ] dip
[ 1 seconds sleep ] swap
'[ _ speak ] interleave ;
: check-for-updates ( chat -- )
[ git-id git-pull-cmd short-running-process git-id ] dip
report-updates ;
: bot ( -- )
start-bot
'[ _ check-for-updates ] 5 minutes every drop ;
MAIN: bot

View File

@ -5,7 +5,7 @@ USING: combinators.lib kernel sequences math namespaces make
assocs random sequences.private shuffle math.functions arrays
math.parser math.private sorting strings ascii macros assocs.lib
quotations hashtables math.order locals generalizations
math.ranges random ;
math.ranges random fry ;
IN: sequences.lib
: each-withn ( seq quot n -- ) nwith each ; inline
@ -90,12 +90,8 @@ ERROR: element-not-found ;
dupd find over [ element-not-found ] unless
>r cut rest r> swap ; inline
: (map-until) ( quot pred -- quot )
[ dup ] swap 3compose
[ [ drop t ] [ , f ] if ] compose [ find 2drop ] curry ;
: map-until ( seq quot pred -- newseq )
(map-until) { } make ;
'[ [ @ dup @ [ drop t ] [ , f ] if ] find 2drop ] { } make ;
: take-while ( seq quot -- newseq )
[ not ] compose