Merge branch 'master' of git://factorcode.org/git/factor
commit
d647209ca5
|
@ -276,3 +276,9 @@ TUPLE: id obj ;
|
|||
|
||||
[ 4 ] [ 2 [ dup fixnum* ] compile-call ] unit-test
|
||||
[ 7 ] [ 2 [ dup fixnum* 3 fixnum+fast ] compile-call ] unit-test
|
||||
|
||||
SINGLETON: cucumber
|
||||
|
||||
M: cucumber equal? "The cucumber has no equal" throw ;
|
||||
|
||||
[ t ] [ [ cucumber ] compile-call cucumber eq? ] unit-test
|
|
@ -19,6 +19,7 @@ HELP: <mapped-file>
|
|||
HELP: with-mapped-file
|
||||
{ $values { "path" "a pathname string" } { "quot" { $quotation "( mmap -- )" } } }
|
||||
{ $contract "Opens a file and maps its contents into memory, passing the " { $link mapped-file } " instance to the quotation. The mapped file is disposed of when the quotation returns, or if an error is thrown." }
|
||||
{ $notes "This is a low-level word, because " { $link mapped-file } " objects simply expose their base address and length. Most applications should use " { $link "io.mmap.arrays" } " instead." }
|
||||
{ $errors "Throws an error if a memory mapping could not be established." } ;
|
||||
|
||||
HELP: close-mapped-file
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
USING: math.ranges sequences tools.test arrays ;
|
||||
USING: math math.ranges sequences sets tools.test arrays ;
|
||||
IN: math.ranges.tests
|
||||
|
||||
[ { } ] [ 1 1 (a,b) >array ] unit-test
|
||||
|
@ -11,7 +11,7 @@ IN: math.ranges.tests
|
|||
[ { 1 } ] [ 1 2 [a,b) >array ] unit-test
|
||||
[ { 1 2 } ] [ 1 2 [a,b] >array ] unit-test
|
||||
|
||||
[ { } ] [ 2 1 (a,b) >array ] unit-test
|
||||
[ { } ] [ 2 1 (a,b) >array ] unit-test
|
||||
[ { 1 } ] [ 2 1 (a,b] >array ] unit-test
|
||||
[ { 2 } ] [ 2 1 [a,b) >array ] unit-test
|
||||
[ { 2 1 } ] [ 2 1 [a,b] >array ] unit-test
|
||||
|
@ -32,3 +32,7 @@ IN: math.ranges.tests
|
|||
[ 0 ] [ -1 5 [0,b] clamp-to-range ] unit-test
|
||||
[ 5 ] [ 6 5 [0,b] clamp-to-range ] unit-test
|
||||
[ { 0 1 2 3 4 } ] [ 5 sequence-index-range >array ] unit-test
|
||||
|
||||
[ 100 ] [
|
||||
1 100 [a,b] [ 2^ [1,b] ] map prune length
|
||||
] unit-test
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! Copyright (C) 2008, 2009 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel layouts math math.order namespaces sequences
|
||||
sequences.private accessors ;
|
||||
sequences.private accessors classes.tuple arrays ;
|
||||
IN: math.ranges
|
||||
|
||||
TUPLE: range
|
||||
|
@ -18,6 +18,12 @@ M: range length ( seq -- n )
|
|||
M: range nth-unsafe ( n range -- obj )
|
||||
[ step>> * ] keep from>> + ;
|
||||
|
||||
! For ranges with many elements, the default element-wise methods
|
||||
! sequences define are unsuitable because they're O(n)
|
||||
M: range equal? over range? [ tuple= ] [ 2drop f ] if ;
|
||||
|
||||
M: range hashcode* tuple-hashcode ;
|
||||
|
||||
INSTANCE: range immutable-sequence
|
||||
|
||||
: twiddle ( a b -- a b step ) 2dup > -1 1 ? ; inline
|
||||
|
|
|
@ -79,16 +79,16 @@ M: tuple-class slots>tuple
|
|||
|
||||
ERROR: bad-superclass class ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: tuple= ( tuple1 tuple2 -- ? )
|
||||
2dup [ layout-of ] bi@ eq? [
|
||||
[ drop tuple-size ]
|
||||
[ [ [ drop array-nth ] [ nip array-nth ] 3bi = ] 2curry ]
|
||||
2bi all-integers?
|
||||
] [
|
||||
2drop f
|
||||
] if ; inline
|
||||
2dup [ tuple? ] both? [
|
||||
2dup [ layout-of ] bi@ eq? [
|
||||
[ drop tuple-size ]
|
||||
[ [ [ drop array-nth ] [ nip array-nth ] 3bi = ] 2curry ]
|
||||
2bi all-integers?
|
||||
] [ 2drop f ] if
|
||||
] [ 2drop f ] if ; inline
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: tuple-predicate-quot/1 ( class -- quot )
|
||||
#! Fast path for tuples with no superclass
|
||||
|
@ -328,7 +328,9 @@ M: tuple clone (clone) ;
|
|||
|
||||
M: tuple equal? over tuple? [ tuple= ] [ 2drop f ] if ;
|
||||
|
||||
M: tuple hashcode*
|
||||
GENERIC: tuple-hashcode ( n tuple -- x )
|
||||
|
||||
M: tuple tuple-hashcode
|
||||
[
|
||||
[ class hashcode ] [ tuple-size ] [ ] tri
|
||||
[ rot ] dip [
|
||||
|
@ -336,6 +338,8 @@ M: tuple hashcode*
|
|||
] 2curry each
|
||||
] recursive-hashcode ;
|
||||
|
||||
M: tuple hashcode* tuple-hashcode ;
|
||||
|
||||
M: tuple-class new
|
||||
dup "prototype" word-prop
|
||||
[ (clone) ] [ tuple-layout <tuple> ] ?if ;
|
||||
|
|
|
@ -22,16 +22,19 @@ ABOUT: "io.files"
|
|||
HELP: <file-reader>
|
||||
{ $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "stream" "an input stream" } }
|
||||
{ $description "Outputs an input stream for reading from the specified pathname using the given encoding." }
|
||||
{ $notes "Most code should use " { $link with-file-reader } " instead, to ensure the stream is properly disposed of after." }
|
||||
{ $errors "Throws an error if the file is unreadable." } ;
|
||||
|
||||
HELP: <file-writer>
|
||||
{ $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "stream" "an output stream" } }
|
||||
{ $description "Outputs an output stream for writing to the specified pathname using the given encoding. The file's length is truncated to zero." }
|
||||
{ $notes "Most code should use " { $link with-file-writer } " instead, to ensure the stream is properly disposed of after." }
|
||||
{ $errors "Throws an error if the file cannot be opened for writing." } ;
|
||||
|
||||
HELP: <file-appender>
|
||||
{ $values { "path" "a pathname string" } { "encoding" "an encoding descriptor" } { "stream" "an output stream" } }
|
||||
{ $description "Outputs an output stream for writing to the specified pathname using the given encoding. The stream begins writing at the end of the file." }
|
||||
{ $notes "Most code should use " { $link with-file-appender } " instead, to ensure the stream is properly disposed of after." }
|
||||
{ $errors "Throws an error if the file cannot be opened for writing." } ;
|
||||
|
||||
HELP: with-file-reader
|
||||
|
|
Loading…
Reference in New Issue