Making all of basis and extra unambiguous for sets/namespaces

db4
Daniel Ehrenberg 2010-02-26 16:28:38 -05:00
parent 7074979745
commit 6298203b4c
11 changed files with 9 additions and 159 deletions

View File

@ -3,6 +3,7 @@
USING: accessors kernel sequences sets arrays math strings fry USING: accessors kernel sequences sets arrays math strings fry
namespaces prettyprint compiler.cfg.linear-scan.live-intervals namespaces prettyprint compiler.cfg.linear-scan.live-intervals
compiler.cfg.linear-scan.allocation compiler.cfg assocs ; compiler.cfg.linear-scan.allocation compiler.cfg assocs ;
FROM: namespaces => set ;
IN: compiler.cfg.linear-scan.debugger IN: compiler.cfg.linear-scan.debugger
: check-linear-scan ( live-intervals machine-registers -- ) : check-linear-scan ( live-intervals machine-registers -- )

View File

@ -4,6 +4,7 @@ USING: sequences kernel splitting lists fry accessors assocs math.order
math combinators namespaces urls.encoding xml.syntax xmode.code2html math combinators namespaces urls.encoding xml.syntax xmode.code2html
xml.data arrays strings vectors xml.writer io.streams.string locals xml.data arrays strings vectors xml.writer io.streams.string locals
unicode.categories ; unicode.categories ;
FROM: namespaces => set ;
IN: farkup IN: farkup
SYMBOL: relative-link-prefix SYMBOL: relative-link-prefix

View File

@ -7,6 +7,7 @@ io.encodings.ascii io.timeouts io.sockets io.sockets.secure io.crlf
kernel logging sequences combinators splitting assocs strings kernel logging sequences combinators splitting assocs strings
math.order math.parser random system calendar summary calendar.format math.order math.parser random system calendar summary calendar.format
accessors sets hashtables base64 debugger classes prettyprint words ; accessors sets hashtables base64 debugger classes prettyprint words ;
FROM: namespaces => set ;
IN: smtp IN: smtp
SYMBOL: smtp-domain SYMBOL: smtp-domain

View File

@ -4,6 +4,7 @@ USING: kernel namespaces xml.tokenize xml.state xml.name
xml.data accessors arrays make xml.char-classes fry assocs sequences xml.data accessors arrays make xml.char-classes fry assocs sequences
math xml.errors sets combinators io.encodings io.encodings.iana math xml.errors sets combinators io.encodings io.encodings.iana
unicode.case xml.dtd strings xml.entities unicode.categories ; unicode.case xml.dtd strings xml.entities unicode.categories ;
FROM: namespaces => set ;
IN: xml.elements IN: xml.elements
: take-interpolated ( quot -- interpolated ) : take-interpolated ( quot -- interpolated )

View File

@ -1,53 +0,0 @@
! Copyright (C) 2010 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: new-sets tools.test kernel prettyprint hash-sets sorting ;
IN: new-sets.tests
[ { } ] [ { } { } intersect ] unit-test
[ { 2 3 } ] [ { 1 2 3 } { 2 3 4 } intersect ] unit-test
[ { } ] [ { } { } diff ] unit-test
[ { 1 } ] [ { 1 2 3 } { 2 3 4 } diff ] unit-test
[ { } ] [ { } { } union ] unit-test
[ { 1 2 3 4 } ] [ { 1 2 3 } { 2 3 4 } union ] unit-test
[ t ] [ { 1 2 } { 1 3 } intersects? ] unit-test
[ f ] [ { 4 2 } { 1 3 } intersects? ] unit-test
[ f ] [ { } { 1 } intersects? ] unit-test
[ f ] [ { 1 } { } intersects? ] unit-test
[ t ] [ 4 { 2 4 5 } in? ] unit-test
[ f ] [ 1 { 2 4 5 } in? ] unit-test
[ V{ 1 2 3 } ] [ 3 V{ 1 2 } clone [ adjoin ] keep ] unit-test
[ V{ 1 2 } ] [ 2 V{ 1 2 } clone [ adjoin ] keep ] unit-test
[ V{ 1 2 } ] [ 3 V{ 1 2 } clone [ delete ] keep ] unit-test
[ V{ 2 } ] [ 1 V{ 1 2 } clone [ delete ] keep ] unit-test
[ t ] [ { 1 2 3 } { 2 1 3 } set= ] unit-test
[ f ] [ { 2 3 } { 1 2 3 } set= ] unit-test
[ f ] [ { 1 2 3 } { 2 3 } set= ] unit-test
[ { 1 } ] [ { 1 } members ] unit-test
[ { 1 2 3 } ] [ { 1 1 1 2 2 3 3 3 3 3 } dup set-like natural-sort ] unit-test
[ { 1 2 3 } ] [ HS{ 1 2 3 } { } set-like natural-sort ] unit-test
[ HS{ 1 2 3 } ] [ { 1 2 3 } fast-set ] unit-test
[ { 1 2 3 } ] [ { { 1 } { 2 } { 1 3 } } combine ] unit-test
[ f ] [ { 0 1 1 2 3 5 } all-unique? ] unit-test
[ t ] [ { 0 1 2 3 4 5 } all-unique? ] unit-test
[ { 1 2 3 } ] [ { 1 2 2 3 3 } { } set-like ] unit-test
[ { 3 2 1 } ] [ { 3 3 2 2 1 } { } set-like ] unit-test
[ { 2 1 2 1 } ] [ { 1 2 3 2 1 2 1 } duplicates ] unit-test
[ f ] [ HS{ 1 2 3 1 2 1 } duplicates ] unit-test
[ H{ { 3 HS{ 1 2 } } } ] [ H{ } clone 1 3 pick adjoin-at 2 3 pick adjoin-at ] unit-test

View File

@ -1,106 +0,0 @@
! Copyright (C) 2010 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs hashtables kernel vectors
math sequences ;
IN: new-sets
! Set protocol
MIXIN: set
GENERIC: adjoin ( elt set -- )
GENERIC: in? ( elt set -- ? )
GENERIC: delete ( elt set -- )
GENERIC: set-like ( set exemplar -- set' )
GENERIC: fast-set ( set -- set' )
GENERIC: members ( set -- sequence )
GENERIC: union ( set1 set2 -- set )
GENERIC: intersect ( set1 set2 -- set )
GENERIC: intersects? ( set1 set2 -- ? )
GENERIC: diff ( set1 set2 -- set )
GENERIC: subset? ( set1 set2 -- ? )
GENERIC: set= ( set1 set2 -- ? )
GENERIC: duplicates ( set -- sequence )
GENERIC: all-unique? ( set -- ? )
! Defaults for some methods.
! Override them for efficiency
M: set union
[ [ members ] bi@ append ] keep set-like ;
<PRIVATE
: tester ( set -- quot )
fast-set [ in? ] curry ; inline
: sequence/tester ( set1 set2 -- set1' quot )
[ members ] [ tester ] bi* ; inline
PRIVATE>
M: set intersect
[ sequence/tester filter ] keep set-like ;
M: set diff
[ sequence/tester [ not ] compose filter ] keep set-like ;
M: set intersects?
sequence/tester any? ;
M: set subset?
sequence/tester all? ;
M: set set=
2dup subset? [ swap subset? ] [ 2drop f ] if ;
M: set fast-set ;
M: set duplicates drop f ;
M: set all-unique? drop t ;
<PRIVATE
: (prune) ( elt hash vec -- )
3dup drop in? [ 3drop ] [
[ drop adjoin ] [ nip push ] 3bi
] if ; inline
: prune ( seq -- newseq )
[ f fast-set ] [ length <vector> ] bi
[ [ (prune) ] 2curry each ] keep ;
PRIVATE>
! Sequences are sets
INSTANCE: sequence set
M: sequence in?
member? ; inline
M: sequence adjoin
[ delete ] [ push ] 2bi ;
M: sequence delete
remove! drop ; inline
M: sequence set-like
[ members ] dip like ;
M: sequence members
[ prune ] keep like ;
M: sequence all-unique?
dup prune sequence= ;
! Some sequence methods are defined using hash-sets
USE: vocabs.loader
"hash-sets" require
: combine ( sets -- set )
f [ union ] reduce ;
: gather ( seq quot -- newseq )
map concat members ; inline
: adjoin-at ( value key assoc -- )
[ [ f fast-set ] unless* [ adjoin ] keep ] change-at ;

View File

@ -4,6 +4,7 @@ USING: accessors arrays hashtables assocs io kernel locals math
math.vectors math.matrices math.matrices.elimination namespaces math.vectors math.matrices math.matrices.elimination namespaces
parser prettyprint sequences words combinators math.parser parser prettyprint sequences words combinators math.parser
splitting sorting shuffle sets math.order ; splitting sorting shuffle sets math.order ;
FROM: namespaces => set ;
IN: koszul IN: koszul
! Utilities ! Utilities

View File

@ -5,6 +5,7 @@ destructors fry io io.encodings.utf8 kernel managed-server
namespaces parser sequences sorting splitting strings.parser namespaces parser sequences sorting splitting strings.parser
unicode.case unicode.categories calendar calendar.format unicode.case unicode.categories calendar calendar.format
locals io.encodings.binary io.encodings.string prettyprint ; locals io.encodings.binary io.encodings.string prettyprint ;
FROM: namespaces => set ;
IN: managed-server.chat IN: managed-server.chat
TUPLE: chat-server < managed-server ; TUPLE: chat-server < managed-server ;

View File

@ -5,6 +5,7 @@ io.encodings.binary io.servers.connection io.sockets
io.streams.duplex fry kernel locals math math.ranges multiline io.streams.duplex fry kernel locals math math.ranges multiline
namespaces prettyprint random sequences sets splitting threads namespaces prettyprint random sequences sets splitting threads
tools.continuations ; tools.continuations ;
FROM: namespaces => set ;
IN: managed-server IN: managed-server
TUPLE: managed-server < threaded-server clients ; TUPLE: managed-server < threaded-server clients ;

View File

@ -6,6 +6,7 @@ definitions prettyprint prettyprint.backend prettyprint.custom
quotations generalizations debugger io compiler.units quotations generalizations debugger io compiler.units
kernel.private effects accessors hashtables sorting shuffle kernel.private effects accessors hashtables sorting shuffle
math.order sets see effects.parser ; math.order sets see effects.parser ;
FROM: namespaces => set ;
IN: multi-methods IN: multi-methods
! PART I: Converting hook specializers ! PART I: Converting hook specializers

View File

@ -29,6 +29,7 @@
USING: assocs kernel math math.combinatorics math.functions USING: assocs kernel math math.combinatorics math.functions
math.parser math.primes namespaces project-euler.common math.parser math.primes namespaces project-euler.common
sequences sets strings grouping math.ranges arrays fry math.order ; sequences sets strings grouping math.ranges arrays fry math.order ;
FROM: namespaces => set ;
IN: project-euler.051 IN: project-euler.051
<PRIVATE <PRIVATE
SYMBOL: family-count SYMBOL: family-count