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

db4
Eduardo Cavazos 2008-04-01 16:23:12 -06:00
commit f3e053c5bc
25 changed files with 127 additions and 136 deletions

View File

@ -1,5 +1,5 @@
USING: help.markup help.syntax kernel words ; USING: help.markup help.syntax kernel words ;
IN: singleton IN: classes.singleton
HELP: SINGLETON: HELP: SINGLETON:
{ $syntax "SINGLETON: class" { $syntax "SINGLETON: class"
@ -12,15 +12,3 @@ HELP: SINGLETON:
} { $see-also } { $see-also
POSTPONE: PREDICATE: POSTPONE: PREDICATE:
} ; } ;
HELP: SINGLETONS:
{ $syntax "SINGLETONS: classes... ;"
} { $values
{ "classes" "new singletons to define" }
} { $description
"Defines a new singleton for each class in the list."
} { $examples
{ $example "USE: singleton" "SINGLETONS: foo bar baz ;" "" }
} { $see-also
POSTPONE: SINGLETON:
} ;

View File

@ -0,0 +1,12 @@
USING: kernel singleton tools.test prettyprint io.streams.string ;
IN: classes.singleton.tests
[ ] [ SINGLETON: bzzt ] unit-test
[ t ] [ bzzt bzzt? ] unit-test
[ t ] [ bzzt bzzt eq? ] unit-test
GENERIC: zammo ( obj -- )
[ ] [ M: bzzt zammo drop "yes!" ; ] unit-test
[ "yes!" ] [ bzzt zammo ] unit-test
[ ] [ SINGLETON: omg ] unit-test
[ t ] [ omg singleton? ] unit-test
[ "USING: singleton ;\nIN: classes.singleton.tests\nSINGLETON: omg\n" ] [ [ omg see ] with-string-writer ] unit-test

View File

@ -0,0 +1,22 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: classes.predicate kernel namespaces parser quotations
sequences words prettyprint prettyprint.backend prettyprint.sections
compiler.units classes ;
IN: classes.singleton
PREDICATE: singleton < predicate-class
[ "predicate-definition" word-prop ]
[ [ eq? ] curry ] bi sequence= ;
: define-singleton ( token -- )
create-class-in
dup save-location
\ singleton
over [ eq? ] curry define-predicate-class ;
: SINGLETON:
scan define-singleton ; parsing
M: singleton see-class* ( class -- )
<colon \ SINGLETON: pprint-word pprint-word ;

View File

@ -4,7 +4,7 @@ USING: arrays assocs db kernel math math.parser
sequences continuations sequences.deep sequences.lib sequences continuations sequences.deep sequences.lib
words namespaces tools.walker slots slots.private classes words namespaces tools.walker slots slots.private classes
mirrors classes.tuple combinators calendar.format symbols mirrors classes.tuple combinators calendar.format symbols
singleton ; classes.singleton ;
IN: db.types IN: db.types
HOOK: modifier-table db ( -- hash ) HOOK: modifier-table db ( -- hash )

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: db db.tuples db.types accessors USING: db db.tuples db.types accessors
http.server.auth.providers kernel continuations http.server.auth.providers kernel continuations
singleton ; classes.singleton ;
IN: http.server.auth.providers.db IN: http.server.auth.providers.db
user "USERS" user "USERS"

View File

@ -1,8 +1,8 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: assocs accessors http.server.sessions.storage USING: assocs accessors http.server.sessions.storage
alarms kernel http.server db.tuples db.types singleton alarms kernel http.server db.tuples db.types math.parser
math.parser ; classes.singleton ;
IN: http.server.sessions.storage.db IN: http.server.sessions.storage.db
SINGLETON: sessions-in-db SINGLETON: sessions-in-db

View File

@ -22,7 +22,7 @@ PRIVATE>
: p= ( p p -- ? ) pextend = ; : p= ( p p -- ? ) pextend = ;
: ptrim ( p -- p ) : ptrim ( p -- p )
dup singleton? [ [ zero? ] right-trim ] unless ; dup length 1 = [ [ zero? ] right-trim ] unless ;
: 2ptrim ( p p -- p p ) [ ptrim ] bi@ ; : 2ptrim ( p p -- p p ) [ ptrim ] bi@ ;
: p+ ( p p -- p ) pextend v+ ; : p+ ( p p -- p ) pextend v+ ;

View File

@ -79,7 +79,7 @@ SYMBOL: and-needed?
] if ; ] if ;
: recombine ( seq -- str ) : recombine ( seq -- str )
dup singleton? [ dup length 1 = [
first 3digits>text first 3digits>text
] [ ] [
dup set-conjunction "" swap dup set-conjunction "" swap

View File

@ -1,5 +1,5 @@
USING: alien.c-types io io.files io.nonblocking kernel USING: alien.c-types io io.files io.nonblocking kernel
namespaces random io.encodings.binary singleton init namespaces random io.encodings.binary init
accessors system ; accessors system ;
IN: random.unix IN: random.unix

View File

@ -46,9 +46,6 @@ IN: sequences.lib.tests
[ { 1 -1 5 2 4 } [ < ] monotonic-split [ >array ] map ] unit-test [ { 1 -1 5 2 4 } [ < ] monotonic-split [ >array ] map ] unit-test
[ { { 1 1 1 1 } { 2 2 } { 3 } { 4 } { 5 } { 6 6 6 } } ] [ { { 1 1 1 1 } { 2 2 } { 3 } { 4 } { 5 } { 6 6 6 } } ]
[ { 1 1 1 1 2 2 3 4 5 6 6 6 } [ = ] monotonic-split [ >array ] map ] unit-test [ { 1 1 1 1 2 2 3 4 5 6 6 6 } [ = ] monotonic-split [ >array ] map ] unit-test
[ f ] [ { } singleton? ] unit-test
[ t ] [ { "asdf" } singleton? ] unit-test
[ f ] [ { "asdf" "bsdf" } singleton? ] unit-test
[ 2 ] [ V{ 10 20 30 } [ delete-random drop ] keep length ] unit-test [ 2 ] [ V{ 10 20 30 } [ delete-random drop ] keep length ] unit-test
[ V{ } [ delete-random drop ] keep length ] must-fail [ V{ } [ delete-random drop ] keep length ] must-fail

View File

@ -98,9 +98,6 @@ MACRO: firstn ( n -- )
v, [ pick ,, call [ v, ] unless ] curry 2each ,v v, [ pick ,, call [ v, ] unless ] curry 2each ,v
] { } make ; ] { } make ;
: singleton? ( seq -- ? )
length 1 = ;
: delete-random ( seq -- value ) : delete-random ( seq -- value )
[ length random ] keep [ nth ] 2keep delete-nth ; [ length random ] keep [ nth ] 2keep delete-nth ;

View File

@ -1,9 +0,0 @@
USING: kernel singleton tools.test ;
IN: singleton.tests
[ ] [ SINGLETON: bzzt ] unit-test
[ t ] [ bzzt bzzt? ] unit-test
[ t ] [ bzzt bzzt eq? ] unit-test
GENERIC: zammo ( obj -- )
[ ] [ M: bzzt zammo drop "yes!" ; ] unit-test
[ "yes!" ] [ bzzt zammo ] unit-test

View File

@ -1,16 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: classes.predicate kernel namespaces parser quotations
sequences words ;
IN: singleton
: define-singleton ( token -- )
create-class-in
\ word
over [ eq? ] curry define-predicate-class ;
: SINGLETON:
scan define-singleton ; parsing
: SINGLETONS:
";" parse-tokens [ define-singleton ] each ; parsing