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

db4
Slava Pestov 2009-06-19 03:31:09 -05:00
commit ca298656e3
14 changed files with 130 additions and 118 deletions

View File

@ -198,7 +198,7 @@ PRIVATE>
windows get empty? not ;
: ?attributes ( gadget title/attributes -- attributes )
dup string? [ world-attributes new swap >>title ] when
dup string? [ world-attributes new swap >>title ] [ clone ] if
swap [ [ [ 1array ] [ f ] if* ] curry unless* ] curry change-gadgets ;
PRIVATE>

View File

@ -20,13 +20,6 @@ $nl
{ $subsection set= }
"A word used to implement the above:"
{ $subsection unique }
"Counting elements in a sequence:"
{ $subsection histogram }
{ $subsection histogram* }
"Combinators for implementing histogram:"
{ $subsection sequence>assoc }
{ $subsection sequence>assoc* }
{ $subsection sequence>hashtable }
"Adding elements to sets:"
{ $subsection adjoin }
{ $subsection conjoin }
@ -134,72 +127,3 @@ HELP: gather
{ "newseq" sequence } }
{ $description "Maps a quotation onto a sequence, concatenates the results of the mapping, and removes duplicates." } ;
HELP: histogram
{ $values
{ "seq" sequence }
{ "hashtable" hashtable }
}
{ $examples
{ $example "! Count the number of times an element appears in a sequence."
"USING: prettyprint sets ;"
"\"aaabc\" histogram ."
"H{ { 97 3 } { 98 1 } { 99 1 } }"
}
}
{ $description "Returns a hashtable where the keys are the elements of the sequence and the values are the number of times they appeared in that sequence." } ;
HELP: histogram*
{ $values
{ "hashtable" hashtable } { "seq" sequence }
{ "hashtable" hashtable }
}
{ $examples
{ $example "! Count the number of times the elements of two sequences appear."
"USING: prettyprint sets ;"
"\"aaabc\" histogram \"aaaaaabc\" histogram* ."
"H{ { 97 9 } { 98 2 } { 99 2 } }"
}
}
{ $description "Takes an existing hashtable and uses " { $link histogram } " to continue counting the number of occurences of each element." } ;
HELP: sequence>assoc
{ $values
{ "seq" sequence } { "quot" quotation } { "exemplar" "an exemplar assoc" }
{ "assoc" assoc }
}
{ $examples
{ $example "! Iterate over a sequence and increment the count at each element"
"USING: assocs prettyprint sets ;"
"\"aaabc\" [ inc-at ] H{ } sequence>assoc ."
"H{ { 97 3 } { 98 1 } { 99 1 } }"
}
}
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to a newly created " { $snippet "assoc" } " according to the passed quotation." } ;
HELP: sequence>assoc*
{ $values
{ "assoc" assoc } { "seq" sequence } { "quot" quotation }
{ "assoc" assoc }
}
{ $examples
{ $example "! Iterate over a sequence and add the counts to an existing assoc"
"USING: assocs prettyprint sets kernel ;"
"H{ { 97 2 } { 98 1 } } clone \"aaabc\" [ inc-at ] sequence>assoc* ."
"H{ { 97 5 } { 98 2 } { 99 1 } }"
}
}
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to an existing " { $snippet "assoc" } " according to the passed quotation." } ;
HELP: sequence>hashtable
{ $values
{ "seq" sequence } { "quot" quotation }
{ "hashtable" hashtable }
}
{ $examples
{ $example "! Count the number of times an element occurs in a sequence"
"USING: assocs prettyprint sets ;"
"\"aaabc\" [ inc-at ] sequence>hashtable ."
"H{ { 97 3 } { 98 1 } { 99 1 } }"
}
}
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to a hashtable according to the passed quotation." } ;

9
core/sets/sets-tests.factor Normal file → Executable file
View File

@ -30,12 +30,3 @@ IN: sets.tests
[ f ] [ { 1 } { } intersects? ] unit-test
[
H{
{ 97 2 }
{ 98 2 }
{ 99 2 }
}
] [
"aabbcc" histogram
] unit-test

View File

@ -54,25 +54,3 @@ PRIVATE>
: set= ( seq1 seq2 -- ? )
[ unique ] bi@ = ;
<PRIVATE
: (sequence>assoc) ( seq quot assoc -- assoc )
[ swap curry each ] keep ; inline
PRIVATE>
: sequence>assoc* ( assoc seq quot: ( obj assoc -- ) -- assoc )
rot (sequence>assoc) ; inline
: sequence>assoc ( seq quot: ( obj assoc -- ) exemplar -- assoc )
clone (sequence>assoc) ; inline
: sequence>hashtable ( seq quot: ( obj hashtable -- ) -- hashtable )
H{ } sequence>assoc ; inline
: histogram* ( hashtable seq -- hashtable )
[ inc-at ] sequence>assoc* ;
: histogram ( seq -- hashtable )
[ inc-at ] sequence>hashtable ;

View File

@ -1,5 +1,5 @@
USING: accessors game-input game-loop kernel math ui.gadgets
ui.gadgets.worlds ui.gestures ;
ui.gadgets.worlds ui.gestures threads ;
IN: game-worlds
TUPLE: game-world < world
@ -9,7 +9,7 @@ TUPLE: game-world < world
GENERIC: tick-length ( world -- millis )
M: game-world draw*
swap >>tick-slice draw-world ;
swap >>tick-slice relayout-1 yield ;
M: game-world begin-world
open-game-input

View File

@ -0,0 +1,83 @@
IN: histogram
USING: help.markup help.syntax sequences hashtables quotations assocs ;
HELP: histogram
{ $values
{ "seq" sequence }
{ "hashtable" hashtable }
}
{ $examples
{ $example "! Count the number of times an element appears in a sequence."
"USING: prettyprint sets ;"
"\"aaabc\" histogram ."
"H{ { 97 3 } { 98 1 } { 99 1 } }"
}
}
{ $description "Returns a hashtable where the keys are the elements of the sequence and the values are the number of times they appeared in that sequence." } ;
HELP: histogram*
{ $values
{ "hashtable" hashtable } { "seq" sequence }
{ "hashtable" hashtable }
}
{ $examples
{ $example "! Count the number of times the elements of two sequences appear."
"USING: prettyprint sets ;"
"\"aaabc\" histogram \"aaaaaabc\" histogram* ."
"H{ { 97 9 } { 98 2 } { 99 2 } }"
}
}
{ $description "Takes an existing hashtable and uses " { $link histogram } " to continue counting the number of occurences of each element." } ;
HELP: sequence>assoc
{ $values
{ "seq" sequence } { "quot" quotation } { "exemplar" "an exemplar assoc" }
{ "assoc" assoc }
}
{ $examples
{ $example "! Iterate over a sequence and increment the count at each element"
"USING: assocs prettyprint sets ;"
"\"aaabc\" [ inc-at ] H{ } sequence>assoc ."
"H{ { 97 3 } { 98 1 } { 99 1 } }"
}
}
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to a newly created " { $snippet "assoc" } " according to the passed quotation." } ;
HELP: sequence>assoc*
{ $values
{ "assoc" assoc } { "seq" sequence } { "quot" quotation }
{ "assoc" assoc }
}
{ $examples
{ $example "! Iterate over a sequence and add the counts to an existing assoc"
"USING: assocs prettyprint sets kernel ;"
"H{ { 97 2 } { 98 1 } } clone \"aaabc\" [ inc-at ] sequence>assoc* ."
"H{ { 97 5 } { 98 2 } { 99 1 } }"
}
}
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to an existing " { $snippet "assoc" } " according to the passed quotation." } ;
HELP: sequence>hashtable
{ $values
{ "seq" sequence } { "quot" quotation }
{ "hashtable" hashtable }
}
{ $examples
{ $example "! Count the number of times an element occurs in a sequence"
"USING: assocs prettyprint sets ;"
"\"aaabc\" [ inc-at ] sequence>hashtable ."
"H{ { 97 3 } { 98 1 } { 99 1 } }"
}
}
{ $description "Iterates over a sequence, allowing elements of the sequence to be added to a hashtable according to the passed quotation." } ;
ARTICLE: "histogram" "Computing histograms"
"Counting elements in a sequence:"
{ $subsection histogram }
{ $subsection histogram* }
"Combinators for implementing histogram:"
{ $subsection sequence>assoc }
{ $subsection sequence>assoc* }
{ $subsection sequence>hashtable } ;
ABOUT: "histogram"

View File

@ -0,0 +1,12 @@
IN: histogram.tests
USING: help.markup help.syntax tools.test histogram ;
[
H{
{ 97 2 }
{ 98 2 }
{ 99 2 }
}
] [
"aabbcc" histogram
] unit-test

View File

@ -0,0 +1,26 @@
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences assocs ;
IN: histogram
<PRIVATE
: (sequence>assoc) ( seq quot assoc -- assoc )
[ swap curry each ] keep ; inline
PRIVATE>
: sequence>assoc* ( assoc seq quot: ( obj assoc -- ) -- assoc )
rot (sequence>assoc) ; inline
: sequence>assoc ( seq quot: ( obj assoc -- ) exemplar -- assoc )
clone (sequence>assoc) ; inline
: sequence>hashtable ( seq quot: ( obj hashtable -- ) -- hashtable )
H{ } sequence>assoc ; inline
: histogram* ( hashtable seq -- hashtable )
[ inc-at ] sequence>assoc* ;
: histogram ( seq -- hashtable )
[ inc-at ] sequence>hashtable ;

2
extra/tokyo/alien/tcbdb/tcbdb.factor Normal file → Executable file
View File

@ -116,7 +116,7 @@ FUNCTION: ulonglong tcbdbbnum ( TCBDB* bdb ) ;
FUNCTION: uint tcbdbalign ( TCBDB* bdb ) ;
FUNCTION: uint tcbdbfbpmax ( TCBDB* bdb ) ;
FUNCTION: ulonglong tcbdbinode ( TCBDB* bdb ) ;
FUNCTION: time_t tcbdbmtime ( TCBDB* bdb ) ;
FUNCTION: tokyo_time_t tcbdbmtime ( TCBDB* bdb ) ;
FUNCTION: uchar tcbdbflags ( TCBDB* bdb ) ;
FUNCTION: uchar tcbdbopts ( TCBDB* bdb ) ;
FUNCTION: char* tcbdbopaque ( TCBDB* bdb ) ;

2
extra/tokyo/alien/tcfdb/tcfdb.factor Normal file → Executable file
View File

@ -84,7 +84,7 @@ FUNCTION: uint tcfdbwidth ( TCFDB* fdb ) ;
FUNCTION: ulonglong tcfdblimsiz ( TCFDB* fdb ) ;
FUNCTION: ulonglong tcfdblimid ( TCFDB* fdb ) ;
FUNCTION: ulonglong tcfdbinode ( TCFDB* fdb ) ;
FUNCTION: time_t tcfdbmtime ( TCFDB* fdb ) ;
FUNCTION: tokyo_time_t tcfdbmtime ( TCFDB* fdb ) ;
FUNCTION: int tcfdbomode ( TCFDB* fdb ) ;
FUNCTION: uchar tcfdbtype ( TCFDB* fdb ) ;
FUNCTION: uchar tcfdbflags ( TCFDB* fdb ) ;

2
extra/tokyo/alien/tchdb/tchdb.factor Normal file → Executable file
View File

@ -83,7 +83,7 @@ FUNCTION: uint tchdbalign ( TCHDB* hdb ) ;
FUNCTION: uint tchdbfbpmax ( TCHDB* hdb ) ;
FUNCTION: ulonglong tchdbxmsiz ( TCHDB* hdb ) ;
FUNCTION: ulonglong tchdbinode ( TCHDB* hdb ) ;
FUNCTION: time_t tchdbmtime ( TCHDB* hdb ) ;
FUNCTION: tokyo_time_t tchdbmtime ( TCHDB* hdb ) ;
FUNCTION: int tchdbomode ( TCHDB* hdb ) ;
FUNCTION: uchar tchdbtype ( TCHDB* hdb ) ;
FUNCTION: uchar tchdbflags ( TCHDB* hdb ) ;

2
extra/tokyo/alien/tcrdb/tcrdb.factor Normal file → Executable file
View File

@ -42,8 +42,6 @@ CONSTANT: RDBXOLCKGLB 2
CONSTANT: RDBROCHKCON 1
CONSTANT: RDBMONOULOG 1
TYPEDEF: int bool
FUNCTION: char* tcrdberrmsg ( int ecode ) ;
FUNCTION: TCRDB* tcrdbnew ( ) ;
FUNCTION: void tcrdbdel ( TCRDB* rdb ) ;

2
extra/tokyo/alien/tctdb/tctdb.factor Normal file → Executable file
View File

@ -136,7 +136,7 @@ FUNCTION: ulonglong tctdbbnum ( TCTDB* tdb ) ;
FUNCTION: uint tctdbalign ( TCTDB* tdb ) ;
FUNCTION: uint tctdbfbpmax ( TCTDB* tdb ) ;
FUNCTION: ulonglong tctdbinode ( TCTDB* tdb ) ;
FUNCTION: time_t tctdbmtime ( TCTDB* tdb ) ;
FUNCTION: tokyo_time_t tctdbmtime ( TCTDB* tdb ) ;
FUNCTION: uchar tctdbflags ( TCTDB* tdb ) ;
FUNCTION: uchar tctdbopts ( TCTDB* tdb ) ;
FUNCTION: char* tctdbopaque ( TCTDB* tdb ) ;

4
extra/tokyo/alien/tcutil/tcutil.factor Normal file → Executable file
View File

@ -19,7 +19,7 @@ C-ENUM:
TCDBTTABLE ;
! FIXME: on windows 64bits this isn't correct, because long is 32bits there, and time_t is int64
TYPEDEF: long time_t
TYPEDEF: long tokyo_time_t
TYPEDEF: void* TCLIST*
@ -36,4 +36,4 @@ FUNCTION: void tcfree ( void* ptr ) ;
TYPEDEF: void* TCCMP
TYPEDEF: void* TCCODEC
TYPEDEF: void* TCPDPROC
TYPEDEF: voud* TCITER
TYPEDEF: void* TCITER