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

db4
Joe Groff 2008-01-13 18:21:12 -08:00
commit a808ce5325
38 changed files with 431 additions and 507 deletions

View File

@ -43,7 +43,7 @@ M: assoc assoc-find
inline inline
: assoc-push-if ( key value quot accum -- ) : assoc-push-if ( key value quot accum -- )
>r 2over 2slip r> roll >r 2keep r> roll
[ >r 2array r> push ] [ 3drop ] if ; inline [ >r 2array r> push ] [ 3drop ] if ; inline
: assoc-pusher ( quot -- quot' accum ) : assoc-pusher ( quot -- quot' accum )
@ -52,12 +52,12 @@ M: assoc assoc-find
: assoc-subset ( assoc quot -- subassoc ) : assoc-subset ( assoc quot -- subassoc )
over >r assoc-pusher >r assoc-each r> r> assoc-like ; inline over >r assoc-pusher >r assoc-each r> r> assoc-like ; inline
: assoc-all? ( assoc quot -- ? )
[ not ] compose assoc-find 2nip not ; inline
: assoc-contains? ( assoc quot -- ? ) : assoc-contains? ( assoc quot -- ? )
assoc-find 2nip ; inline assoc-find 2nip ; inline
: assoc-all? ( assoc quot -- ? )
[ not ] compose assoc-contains? not ; inline
: at ( key assoc -- value/f ) : at ( key assoc -- value/f )
at* drop ; inline at* drop ; inline

View File

@ -128,7 +128,7 @@ PRIVATE>
: cleanup ( try cleanup-always cleanup-error -- ) : cleanup ( try cleanup-always cleanup-error -- )
over >r compose [ dip rethrow ] curry over >r compose [ dip rethrow ] curry
>r (catch) r> ifcc r> call ; inline recover r> call ; inline
: attempt-all ( seq quot -- obj ) : attempt-all ( seq quot -- obj )
[ [

View File

@ -46,7 +46,7 @@ M: float-regs push-return-reg
: FLD 4 = [ FLDS ] [ FLDL ] if ; : FLD 4 = [ FLDS ] [ FLDL ] if ;
: load/store-float-return reg-size >r stack-reg swap [+] r> ; : load/store-float-return reg-size >r stack@ r> ;
M: float-regs load-return-reg load/store-float-return FLD ; M: float-regs load-return-reg load/store-float-return FLD ;
M: float-regs store-return-reg load/store-float-return FSTP ; M: float-regs store-return-reg load/store-float-return FSTP ;

View File

@ -35,7 +35,11 @@ M: object root-directory? ( path -- ? ) path-separator? ;
: stat ( path -- directory? permissions length modified ) : stat ( path -- directory? permissions length modified )
normalize-pathname (stat) ; normalize-pathname (stat) ;
: exists? ( path -- ? ) stat >r 3drop r> >boolean ; : file-length ( path -- n ) stat 4array third ;
: file-modified ( path -- n ) stat >r 3drop r> ; inline
: exists? ( path -- ? ) file-modified >boolean ;
: directory? ( path -- ? ) stat 3drop ; : directory? ( path -- ? ) stat 3drop ;
@ -52,10 +56,6 @@ M: object root-directory? ( path -- ? ) path-separator? ;
: directory ( path -- seq ) : directory ( path -- seq )
normalize-directory dup (directory) fixup-directory ; normalize-directory dup (directory) fixup-directory ;
: file-length ( path -- n ) stat 4array third ;
: file-modified ( path -- n ) stat >r 3drop r> ;
: last-path-separator ( path -- n ? ) : last-path-separator ( path -- n ? )
[ length 2 [-] ] keep [ path-separator? ] find-last* ; [ length 2 [-] ] keep [ path-separator? ] find-last* ;

View File

@ -68,7 +68,7 @@ C: <interval> interval
: (interval-op) ( p1 p2 quot -- p3 ) : (interval-op) ( p1 p2 quot -- p3 )
2over >r >r 2over >r >r
>r [ first ] 2apply r> call >r [ first ] 2apply r> call
r> r> [ second ] 2apply and 2array ; inline r> r> [ second ] both? 2array ; inline
: interval-op ( i1 i2 quot -- i3 ) : interval-op ( i1 i2 quot -- i3 )
pick interval-from pick interval-from pick (interval-op) >r pick interval-from pick interval-from pick (interval-op) >r

View File

@ -32,7 +32,7 @@ PRIVATE>
: stop ( -- ) : stop ( -- )
walker-hook [ walker-hook [
f swap continue-with continue
] [ ] [
run-queue pop-back dup array? run-queue pop-back dup array?
[ first2 continue-with ] [ continue ] if [ first2 continue-with ] [ continue ] if

View File

@ -15,7 +15,7 @@ M: tuple class class-of-tuple ;
<PRIVATE <PRIVATE
: tuple= ( tuple1 tuple2 -- ? ) : tuple= ( tuple1 tuple2 -- ? )
over array-capacity over array-capacity dup -rot number= [ over array-capacity over array-capacity tuck number= [
-rot -rot
[ >r over r> array-nth >r array-nth r> = ] 2curry [ >r over r> array-nth >r array-nth r> = ] 2curry
all-integers? all-integers?

View File

@ -102,7 +102,7 @@ M: vocab-link vocab-name vocab-link-name ;
UNION: vocab-spec vocab vocab-link ; UNION: vocab-spec vocab vocab-link ;
: forget-vocab ( vocab -- ) : forget-vocab ( vocab -- )
dup vocab-words values forget-all dup words forget-all
vocab-name dictionary get delete-at ; vocab-name dictionary get delete-at ;
M: vocab-spec forget* forget-vocab ; M: vocab-spec forget* forget-vocab ;

View File

@ -4,7 +4,7 @@
USING: arrays hashtables io io.streams.string kernel math USING: arrays hashtables io io.streams.string kernel math
math.vectors math.functions math.parser namespaces sequences math.vectors math.functions math.parser namespaces sequences
strings tuples system debugger combinators vocabs.loader strings tuples system debugger combinators vocabs.loader
calendar.backend structs alien.c-types ; calendar.backend structs alien.c-types math.vectors ;
IN: calendar IN: calendar
TUPLE: timestamp year month day hour minute second gmt-offset ; TUPLE: timestamp year month day hour minute second gmt-offset ;
@ -96,12 +96,12 @@ SYMBOL: m
: zero-dt ( -- <dt> ) 0 0 0 0 0 0 <dt> ; : zero-dt ( -- <dt> ) 0 0 0 0 0 0 <dt> ;
: years ( n -- dt ) zero-dt [ set-dt-year ] keep ; : years ( n -- dt ) zero-dt [ set-dt-year ] keep ;
: months ( n -- dt ) zero-dt [ set-dt-month ] keep ; : months ( n -- dt ) zero-dt [ set-dt-month ] keep ;
: weeks ( n -- dt ) 7 * zero-dt [ set-dt-day ] keep ;
: days ( n -- dt ) zero-dt [ set-dt-day ] keep ; : days ( n -- dt ) zero-dt [ set-dt-day ] keep ;
: weeks ( n -- dt ) 7 * days ;
: hours ( n -- dt ) zero-dt [ set-dt-hour ] keep ; : hours ( n -- dt ) zero-dt [ set-dt-hour ] keep ;
: minutes ( n -- dt ) zero-dt [ set-dt-minute ] keep ; : minutes ( n -- dt ) zero-dt [ set-dt-minute ] keep ;
: seconds ( n -- dt ) zero-dt [ set-dt-second ] keep ; : seconds ( n -- dt ) zero-dt [ set-dt-second ] keep ;
: milliseconds ( n -- dt ) 1000 /f zero-dt [ set-dt-second ] keep ; : milliseconds ( n -- dt ) 1000 /f seconds ;
: julian-day-number>timestamp ( n -- timestamp ) : julian-day-number>timestamp ( n -- timestamp )
julian-day-number>date 0 0 0 0 <timestamp> ; julian-day-number>date 0 0 0 0 <timestamp> ;
@ -186,7 +186,8 @@ M: number +second ( timestamp n -- timestamp )
#! data #! data
tuple-slots tuple-slots
{ 1 12 365.2425 8765.82 525949.2 31556952.0 } { 1 12 365.2425 8765.82 525949.2 31556952.0 }
[ / ] 2map sum ; v/ sum ;
: dt>months ( dt -- x ) dt>years 12 * ; : dt>months ( dt -- x ) dt>years 12 * ;
: dt>days ( dt -- x ) dt>years 365.2425 * ; : dt>days ( dt -- x ) dt>years 365.2425 * ;
: dt>hours ( dt -- x ) dt>years 8765.82 * ; : dt>hours ( dt -- x ) dt>years 8765.82 * ;
@ -235,7 +236,7 @@ M: timestamp <=> ( ts1 ts2 -- n )
unix-1970 millis 1000 /f seconds +dt ; unix-1970 millis 1000 /f seconds +dt ;
: now ( -- timestamp ) gmt >local-time ; : now ( -- timestamp ) gmt >local-time ;
: before ( dt -- -dt ) tuple-slots [ neg ] map array>dt ; : before ( dt -- -dt ) tuple-slots vneg array>dt ;
: from-now ( dt -- timestamp ) now swap +dt ; : from-now ( dt -- timestamp ) now swap +dt ;
: ago ( dt -- timestamp ) before from-now ; : ago ( dt -- timestamp ) before from-now ;
@ -258,10 +259,7 @@ M: timestamp <=> ( ts1 ts2 -- n )
1+ + 7 mod ; 1+ + 7 mod ;
: day-of-week ( timestamp -- n ) : day-of-week ( timestamp -- n )
[ timestamp-year ] keep >date< zeller-congruence ;
[ timestamp-month ] keep
timestamp-day
zeller-congruence ;
: day-of-year ( timestamp -- n ) : day-of-year ( timestamp -- n )
[ [

View File

@ -7,7 +7,7 @@ IN: combinators.cleave
! The cleaver family ! The cleaver family
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: bi ( obj quot quot -- val val ) >r over slip r> call ; inline : bi ( obj quot quot -- val val ) >r keep r> call ; inline
: tri ( obj quot quot quot -- val val val ) : tri ( obj quot quot quot -- val val val )
>r pick >r bi r> r> call ; inline >r pick >r bi r> r> call ; inline
@ -23,7 +23,7 @@ IN: combinators.cleave
! The spread family ! The spread family
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: bi* ( obj obj quot quot -- val val ) >r swap >r call r> r> call ; inline : bi* ( obj obj quot quot -- val val ) >r swap slip r> call ; inline
: tri* ( obj obj obj quot quot quot -- val val val ) : tri* ( obj obj obj quot quot quot -- val val val )
>r rot >r bi* r> r> call ; inline >r rot >r bi* r> r> call ; inline

View File

@ -40,7 +40,7 @@ SYMBOL: big-endian?
] "" make 64 group ; ] "" make 64 group ;
: shift-mod ( n s w -- n ) : shift-mod ( n s w -- n )
>r shift r> 1 swap shift 1 - bitand ; inline >r shift r> 2^ 1- bitand ; inline
: update-old-new ( old new -- ) : update-old-new ( old new -- )
[ get >r get r> ] 2keep >r >r w+ dup r> set r> set ; inline [ get >r get r> ] 2keep >r >r w+ dup r> set r> set ; inline

View File

@ -126,7 +126,7 @@ SYMBOL: K
: string>sha1-bignum ( string -- n ) string>sha1 be> ; : string>sha1-bignum ( string -- n ) string>sha1 be> ;
: file>sha1 ( file -- sha1 ) <file-reader> stream>sha1 ; : file>sha1 ( file -- sha1 ) <file-reader> stream>sha1 ;
: string>sha1-interleave ( string -- ) : string>sha1-interleave ( string -- seq )
[ zero? ] left-trim [ zero? ] left-trim
dup length odd? [ 1 tail ] when dup length odd? [ 1 tail ] when
seq>2seq [ string>sha1 ] 2apply seq>2seq [ string>sha1 ] 2apply

View File

@ -0,0 +1,4 @@
USING: io.backend ;
IN: editors.gvim.backend
HOOK: gvim-path io-backend ( -- path )

View File

@ -1,13 +1,10 @@
USING: io.backend io.files kernel math math.parser USING: io.backend io.files kernel math math.parser
namespaces editors.vim sequences system combinators namespaces sequences system combinators
vocabs.loader ; editors.vim editors.gvim.backend vocabs.loader ;
IN: editors.gvim IN: editors.gvim
TUPLE: gvim ; TUPLE: gvim ;
HOOK: gvim-path io-backend ( -- path )
M: gvim vim-command ( file line -- string ) M: gvim vim-command ( file line -- string )
[ "\"" % gvim-path % "\" \"" % swap % "\" +" % # ] "" make ; [ "\"" % gvim-path % "\" \"" % swap % "\" +" % # ] "" make ;

View File

@ -1,4 +1,4 @@
USING: editors.gvim io.unix.backend kernel namespaces ; USING: io.unix.backend kernel namespaces editors.gvim.backend ;
IN: editors.gvim.unix IN: editors.gvim.unix
M: unix-io gvim-path M: unix-io gvim-path

View File

@ -1,5 +1,6 @@
USING: definitions editors.vim help help.markup help.syntax io io.files USING: definitions help help.markup help.syntax io io.files
editors words ; editors words ;
IN: editors.vim
ARTICLE: { "vim" "vim" } "Vim support" ARTICLE: { "vim" "vim" } "Vim support"
"This module makes the " { $link edit } " word work with Vim by setting the " { $link edit-hook } " global variable to call " { $link vim-location } ". The " { $link vim-path } " variable contains the name of the vim executable. The default " { $link vim-path } " is " { $snippet "\"gvim\"" } "." "This module makes the " { $link edit } " word work with Vim by setting the " { $link edit-hook } " global variable to call " { $link vim-location } ". The " { $link vim-path } " variable contains the name of the vim executable. The default " { $link vim-path } " is " { $snippet "\"gvim\"" } "."

View File

@ -29,7 +29,7 @@ IN: http.client
: crlf "\r\n" write ; : crlf "\r\n" write ;
: http-request ( host resource method -- ) : http-request ( host resource method -- )
write " " write write " HTTP/1.0" write crlf write bl write " HTTP/1.0" write crlf
"Host: " write write crlf ; "Host: " write write crlf ;
: get-request ( host resource -- ) : get-request ( host resource -- )

View File

@ -69,7 +69,7 @@ UNION: explicit-inverse normal-inverse math-inverse pop-inverse ;
} cond ; } cond ;
: math-exp? ( n n word -- ? ) : math-exp? ( n n word -- ? )
{ + - * / ^ } member? -rot [ number? ] 2apply and and ; { + - * / ^ } member? -rot [ number? ] both? and ;
: (fold-constants) ( quot -- ) : (fold-constants) ( quot -- )
dup length 3 < [ % ] [ dup length 3 < [ % ] [

View File

@ -83,7 +83,8 @@ def-hash get-global [
! Remove n m shift defs ! Remove n m shift defs
[ [
drop dup length 3 = [ drop dup length 3 = [
dup first2 [ number? ] 2apply and swap third \ shift = and not dup first2 [ number? ] both?
swap third \ shift = and not
] [ drop t ] if ] [ drop t ] if
] assoc-subset ] assoc-subset
@ -120,7 +121,7 @@ M: word lint ( word -- seq )
: word-path. ( word -- ) : word-path. ( word -- )
[ word-vocabulary ":" ] keep unparse 3append write nl ; [ word-vocabulary ":" ] keep unparse 3append write nl ;
: lint. ( array -- ) : (lint.) ( pair -- )
first2 >r word-path. r> [ first2 >r word-path. r> [
bl bl bl bl bl bl bl bl
dup . dup .
@ -129,31 +130,45 @@ M: word lint ( word -- seq )
nl nl
] each nl nl ; ] each nl nl ;
: lint. ( alist -- )
[ (lint.) ] each ;
GENERIC: run-lint ( obj -- obj ) GENERIC: run-lint ( obj -- obj )
: trim-self ( seq -- newseq ) : (trim-self)
[
first2 [
def-hash get-global at* [ def-hash get-global at* [
dupd remove empty? not dupd remove empty? not
] [ ] [
drop f drop f
] if ] if ;
] subset 2array
] map ; : trim-self ( seq -- newseq )
[ [ (trim-self) ] subset ] assoc-map ;
: filter-symbols ( alist -- alist )
[
nip first dup def-hash get at
[ first ] 2apply literalize = not
] assoc-subset ;
M: sequence run-lint ( seq -- seq ) M: sequence run-lint ( seq -- seq )
[ [
global [ dup . flush ] bind global [ dup . flush ] bind
dup lint 2array dup lint
] map ] { } map>assoc
trim-self trim-self
[ second empty? not ] subset ; [ second empty? not ] subset
filter-symbols ;
M: word run-lint ( word -- seq ) M: word run-lint ( word -- seq )
1array run-lint ; 1array run-lint ;
: lint-all ( -- seq ) : lint-all ( -- seq )
all-words run-lint dup [ lint. ] each ; all-words run-lint dup lint. ;
: lint-vocab ( vocab -- seq )
words run-lint dup lint. ;
: lint-word ( word -- seq )
1array run-lint dup lint. ;

View File

@ -18,24 +18,21 @@ SYMBOL: trials
: next-odd ( m -- n ) : next-odd ( m -- n )
dup even? [ 1+ ] [ 2 + ] if ; dup even? [ 1+ ] [ 2 + ] if ;
: random-bits ( m -- n ) : random-bits ( m -- n ) 2^ random ; foldable
#! Top bit is always set
2^ [ random ] keep -1 shift bitor ; foldable
: (factor-2s) ( s n -- s n ) TUPLE: positive-even-expected n ;
: (factor-2s) ( r s -- r s )
dup even? [ -1 shift >r 1+ r> (factor-2s) ] when ; dup even? [ -1 shift >r 1+ r> (factor-2s) ] when ;
: factor-2s ( n -- r s ) : factor-2s ( n -- r s )
#! factor an even number into 2 ^ s * m #! factor an even number into s * 2 ^ r
dup even? over 0 > and [ dup even? over 0 > and [
"input must be positive and even" throw positive-even-expected construct-boa throw
] unless 0 swap (factor-2s) ; ] unless 0 swap (factor-2s) ;
:: (miller-rabin) | n prime?! | :: (miller-rabin) | n prime?! |
n dup 1 = over even? or [ n 1- factor-2s s set r set
drop f
] [
1- factor-2s s set r set
trials get [ trials get [
n 1- [1,b] random a set n 1- [1,b] random a set
a get s get n ^mod 1 = [ a get s get n ^mod 1 = [
@ -52,9 +49,7 @@ SYMBOL: trials
] when ] when
] unless ] unless
drop drop
] each ] each prime? ;
prime?
] if ;
TUPLE: miller-rabin-bounds ; TUPLE: miller-rabin-bounds ;
@ -62,6 +57,7 @@ TUPLE: miller-rabin-bounds ;
over { over {
{ [ dup 1 <= ] [ 3drop f ] } { [ dup 1 <= ] [ 3drop f ] }
{ [ dup 2 = ] [ 3drop t ] } { [ dup 2 = ] [ 3drop t ] }
{ [ dup even? ] [ 3drop f ] }
{ [ t ] [ [ drop trials set t (miller-rabin) ] with-scope ] } { [ t ] [ [ drop trials set t (miller-rabin) ] with-scope ] }
} cond ; } cond ;
@ -81,10 +77,9 @@ TUPLE: miller-rabin-bounds ;
>odd (find-relative-prime) ; >odd (find-relative-prime) ;
: find-relative-prime ( n -- p ) : find-relative-prime ( n -- p )
dup random >odd (find-relative-prime) ; dup random find-relative-prime* ;
: unique-primes ( numbits n -- seq ) : unique-primes ( numbits n -- seq )
#! generate two primes #! generate two primes
over 5 < [ "not enough primes below 5 bits" throw ] when over 5 < [ "not enough primes below 5 bits" throw ] when
[ [ drop random-prime ] with map ] [ all-unique? ] generate ; [ [ drop random-prime ] with map ] [ all-unique? ] generate ;

View File

@ -2,13 +2,13 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
! !
IN: openal.other IN: openal.other
USING: openal alien.c-types kernel alien alien.syntax shuffle combinators.lib ; USING: openal.backend alien.c-types kernel alien alien.syntax shuffle combinators.lib ;
LIBRARY: alut LIBRARY: alut
FUNCTION: void alutLoadWAVFile ( ALbyte* fileName, ALenum* format, void** data, ALsizei* size, ALsizei* frequency, ALboolean* looping ) ; FUNCTION: void alutLoadWAVFile ( ALbyte* fileName, ALenum* format, void** data, ALsizei* size, ALsizei* frequency, ALboolean* looping ) ;
M: other-openal-impl load-wav-file ( filename -- format data size frequency ) M: other-openal-backend load-wav-file ( filename -- format data size frequency )
0 <int> f <void*> 0 <int> 0 <int> 0 <int> f <void*> 0 <int> 0 <int>
[ 0 <char> alutLoadWAVFile ] 4keep [ 0 <char> alutLoadWAVFile ] 4keep
>r >r >r *int r> *void* r> *int r> *int ; >r >r >r *int r> *void* r> *int r> *int ;

View File

@ -27,7 +27,7 @@ IN: opengl
swap glBegin call glEnd ; inline swap glBegin call glEnd ; inline
: do-enabled ( what quot -- ) : do-enabled ( what quot -- )
over glEnable swap slip glDisable ; inline over glEnable dip glDisable ; inline
: do-matrix ( mode quot -- ) : do-matrix ( mode quot -- )
swap [ glMatrixMode glPushMatrix call ] keep swap [ glMatrixMode glPushMatrix call ] keep

View File

@ -2,7 +2,7 @@ USING: alien alien.c-types arrays assocs byte-arrays inference
inference.transforms io io.binary io.streams.string kernel inference.transforms io io.binary io.streams.string kernel
math math.parser namespaces parser prettyprint math math.parser namespaces parser prettyprint
quotations sequences strings threads vectors quotations sequences strings threads vectors
words macros ; words macros math.functions ;
IN: pack IN: pack
SYMBOL: big-endian SYMBOL: big-endian
@ -10,9 +10,6 @@ SYMBOL: big-endian
: big-endian? ( -- ? ) : big-endian? ( -- ? )
1 <int> *char zero? ; 1 <int> *char zero? ;
: clear-bit ( m n -- o )
2^ bitnot bitand ;
: >endian ( obj n -- str ) : >endian ( obj n -- str )
big-endian get [ >be ] [ >le ] if ; inline big-endian get [ >be ] [ >le ] if ; inline
@ -88,7 +85,7 @@ M: string b, ( n string -- ) heap-size b, ;
"\0" read-until [ drop f ] unless ; "\0" read-until [ drop f ] unless ;
: read-c-string* ( n -- str/f ) : read-c-string* ( n -- str/f )
read [ 0 = ] right-trim dup empty? [ drop f ] when ; read [ zero? ] right-trim dup empty? [ drop f ] when ;
: (read-128-ber) ( n -- n ) : (read-128-ber) ( n -- n )
1 read first 1 read first

View File

@ -170,7 +170,7 @@ DEFER: 'choice'
[ [
get-parser [ get-parser [
swap , \ in , \ get , \ create , swap , \ in , \ get , \ create ,
1quotation , \ define-compound , 1quotation , \ define ,
] [ ] [
drop drop
] if* ] if*

View File

@ -1,6 +1,7 @@
! Copyright (C) 2007 Chris Double. ! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax peg ; USING: help.markup help.syntax ;
IN: peg
HELP: parse HELP: parse
{ $values { $values

View File

@ -22,7 +22,7 @@ TUPLE: random-tester-error ;
datastack clone after set datastack clone after set
clear clear
before get [ ] each before get [ ] each
quot get [ compile-1 ] [ errored on ] recover ; quot get [ compile-call ] [ errored on ] recover ;
: do-test ! ( data... quot -- ) : do-test ! ( data... quot -- )
.s flush test-compiler .s flush test-compiler

View File

@ -4,7 +4,7 @@ USING: kernel namespaces arrays quotations sequences assocs combinators
IN: random-weighted IN: random-weighted
: probabilities ( weights -- probabilities ) dup sum [ / ] curry map ; : probabilities ( weights -- probabilities ) dup sum v/n ;
: layers ( probabilities -- layers ) : layers ( probabilities -- layers )
dup length 1+ [ head ] with map 1 tail [ sum ] map ; dup length 1+ [ head ] with map 1 tail [ sum ] map ;

View File

@ -36,7 +36,7 @@ SYMBOL: mt
: set-mt-ith ( y i-get i-set -- ) : set-mt-ith ( y i-get i-set -- )
>r mt-nth >r >r mt-nth >r
[ -1 shift ] keep odd? mt-a 0 ? r> bitxor bitxor r> [ 2/ ] keep odd? mt-a 0 ? r> bitxor bitxor r>
mt-seq set-nth ; inline mt-seq set-nth ; inline
: mt-y ( y1 y2 -- y ) : mt-y ( y1 y2 -- y )

View File

@ -59,7 +59,7 @@ IN: sequences.lib
] { } make ; ] { } make ;
: singleton? ( seq -- ? ) : singleton? ( seq -- ? )
length 1 = ; length 1 = ; foldable
: delete-random ( seq -- value ) : delete-random ( seq -- value )
[ length random ] keep [ nth ] 2keep delete-nth ; [ length random ] keep [ nth ] 2keep delete-nth ;

View File

@ -35,7 +35,7 @@ linkname magic version uname gname devmajor devminor prefix ;
: header-checksum ( seq -- x ) : header-checksum ( seq -- x )
148 cut-slice 8 tail-slice 148 cut-slice 8 tail-slice
[ 0 [ + ] reduce ] 2apply + 256 + ; [ sum ] 2apply + 256 + ;
TUPLE: checksum-error ; TUPLE: checksum-error ;
TUPLE: malformed-block-error ; TUPLE: malformed-block-error ;
@ -164,7 +164,7 @@ TUPLE: unimplemented-typeflag header ;
! Long file name ! Long file name
: typeflag-L ( header -- ) : typeflag-L ( header -- )
<string-writer> [ read-data-blocks ] keep <string-writer> [ read-data-blocks ] keep
>string [ CHAR: \0 = ] right-trim filename set >string [ zero? ] right-trim filename set
global [ "long filename: " write filename get . flush ] bind global [ "long filename: " write filename get . flush ] bind
filename get tar-path+ make-directories ; filename get tar-path+ make-directories ;
@ -196,7 +196,7 @@ TUPLE: unimplemented-typeflag header ;
! global [ dup tar-header-name [ print flush ] when* ] bind ! global [ dup tar-header-name [ print flush ] when* ] bind
dup tar-header-typeflag dup tar-header-typeflag
{ {
{ CHAR: \0 [ typeflag-0 ] } { 0 [ typeflag-0 ] }
{ CHAR: 0 [ typeflag-0 ] } { CHAR: 0 [ typeflag-0 ] }
{ CHAR: 1 [ typeflag-1 ] } { CHAR: 1 [ typeflag-1 ] }
{ CHAR: 2 [ typeflag-2 ] } { CHAR: 2 [ typeflag-2 ] }

View File

@ -1 +0,0 @@
Daniel Ehrenberg

View File

@ -1 +0,0 @@
Double-dispatch generic words

View File

@ -1 +0,0 @@
extensions

View File

@ -1,18 +0,0 @@
USING: visitor math sequences math.parser strings tools.test kernel ;
VISITOR: ++ ( object object -- object )
! acts like +, coercing string arguments to a number, unless both arguments are strings, in which case it appends them
V: number string ++
string>number + ;
V: string number ++
>r string>number r> + ;
V: number number ++
+ ;
V: string string ++
append ;
[ 3 ] [ 1 2 ++ ] unit-test
[ 3 ] [ "1" 2 ++ ] unit-test
[ 3 ] [ 1 "2" ++ ] unit-test
[ "12" ] [ "1" "2" ++ ] unit-test

View File

@ -1,63 +0,0 @@
USING: kernel generic.standard syntax words parser assocs
generic quotations sequences effects arrays classes definitions
prettyprint sorting prettyprint.backend shuffle ;
IN: visitor
: define-visitor ( word -- )
dup dup reset-word define-simple-generic
dup H{ } clone "visitor-methods" set-word-prop
H{ } clone "visitors" set-word-prop ;
: VISITOR:
CREATE define-visitor ; parsing
: record-visitor ( top-class generic method-word -- )
swap "visitors" word-prop swapd set-at ;
: define-1generic ( word -- )
1 <standard-combination> define-generic ;
: copy-effect ( from to -- )
swap stack-effect "declared-effect" set-word-prop ;
: new-vmethod ( method bottom-class top-class generic -- )
gensym dup define-1generic
2dup copy-effect
3dup 1quotation -rot define-method
[ record-visitor ] keep
define-method ;
: define-visitor-method ( method bottom-class top-class generic -- )
4dup >r 2array r> "visitor-methods" word-prop set-at
2dup "visitors" word-prop at
[ nip define-method ] [ new-vmethod ] ?if ;
: V:
! syntax: V: bottom-class top-class generic body... ;
f set-word scan-word scan-word scan-word
parse-definition -roll define-visitor-method ; parsing
! see instance:
! see must be redone because "methods" doesn't show methods
PREDICATE: standard-generic visitor "visitors" word-prop ;
PREDICATE: array triple length 3 = ;
PREDICATE: triple visitor-spec
first3 visitor? >r [ class? ] 2apply and r> and ;
M: visitor-spec definer drop \ V: \ ; ;
M: visitor definer drop \ VISITOR: f ;
M: visitor-spec synopsis*
! same as method-spec#synopsis*
dup definer drop pprint-word
[ pprint-word ] each ;
M: visitor-spec definition
first3 >r 2array r> "visitor-methods" word-prop at ;
M: visitor see
dup (see)
dup see-class
dup "visitor-methods" word-prop keys natural-sort swap
[ >r first2 r> 3array ] curry map see-all ;