Slava Pestov 2010-07-26 15:10:50 -04:00
commit 68da8c48d5
3 changed files with 13 additions and 18 deletions

View File

@ -27,7 +27,7 @@ HELP: dispose-statements
{ $description "Disposes an associative list of statements." } ; { $description "Disposes an associative list of statements." } ;
HELP: statement HELP: statement
{ $description "A " { $snippet "statement" } " stores the information about a statemen, such as the SQL statement text, the in/out parameters, and type information." } ; { $description "A " { $snippet "statement" } " stores the information about a statement, such as the SQL statement text, the in/out parameters, and type information." } ;
HELP: result-set HELP: result-set
{ $description "An object encapsulating a raw SQL result object. There are two ways in which a result set can be accessed, but they are specific to the database backend in use." { $description "An object encapsulating a raw SQL result object. There are two ways in which a result set can be accessed, but they are specific to the database backend in use."

View File

@ -78,7 +78,7 @@ IN: math.combinatorics.tests
[ { } ] [ { 1 2 } 0 selections ] unit-test [ { } ] [ { 1 2 } 0 selections ] unit-test
[ { { 1 2 } } ] [ { 1 2 } 1 selections ] unit-test [ { { 1 } { 2 } } ] [ { 1 2 } 1 selections ] unit-test
[ { { 1 1 } { 1 2 } { 2 1 } { 2 2 } } ] [ { { 1 1 } { 1 2 } { 2 1 } { 2 2 } } ]
[ { 1 2 } 2 selections ] unit-test [ { 1 2 } 2 selections ] unit-test

View File

@ -1,8 +1,10 @@
! Copyright (c) 2007-2010 Slava Pestov, Doug Coleman, Aaron Schaefer, John Benediktsson. ! Copyright (c) 2007-2010 Slava Pestov, Doug Coleman, Aaron Schaefer, John Benediktsson.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs binary-search fry kernel locals math math.order
math.ranges namespaces sequences sorting make sequences.deep arrays USING: accessors arrays assocs binary-search fry kernel locals
combinators ; math math.order math.ranges namespaces sequences sequences.deep
sorting ;
IN: math.combinatorics IN: math.combinatorics
<PRIVATE <PRIVATE
@ -129,21 +131,14 @@ PRIVATE>
[ -rot ] dip each-combination ; inline [ -rot ] dip each-combination ; inline
: all-subsets ( seq -- subsets ) : all-subsets ( seq -- subsets )
dup length [0,b] [ dup length [0,b] [ all-combinations ] with map concat ;
[ dupd all-combinations [ , ] each ] each
] { } make nip ;
: (selections) ( seq n -- selections ) : (selections) ( seq n -- selections )
dupd [ dup 1 > ] [ [ [ 1array ] map dup ] [ 1 - ] bi*
swap pick cartesian-product [ [ cartesian-product concat ] with times
[ [ dup length 1 > [ flatten ] when , ] each ] each [ flatten ] map ;
] { } make swap 1 -
] while drop nip ;
: selections ( seq n -- selections ) : selections ( seq n -- selections )
{ dup 0 > [ (selections) ] [ 2drop { } ] if ;
{ 0 [ drop { } ] }
{ 1 [ 1array ] }
[ (selections) ]
} case ;