Use keys/values where appropriate

db4
Doug Coleman 2010-05-17 22:20:46 -05:00
parent 6b24617bac
commit bdecd564a3
17 changed files with 23 additions and 23 deletions

View File

@ -75,7 +75,7 @@ PRIVATE>
ERROR: no-slots-named class seq ;
: check-columns ( class columns -- )
[ nip ] [
[ [ first ] map ]
[ keys ]
[ all-slots [ name>> ] map ] bi* diff
] 2bi
[ drop ] [ no-slots-named ] if-empty ;

View File

@ -77,7 +77,7 @@ M: linux x>hid-bit-order
} ; inline
: x-bits>hid-bits ( bit-array -- bit-array )
256 iota [ 2array ] { } 2map-as [ first ] filter [ second ] map
256 iota [ 2array ] { } 2map-as [ first ] filter values
x>hid-bit-order [ nth ] curry map
256 <bit-array> swap [ t swap pick set-nth ] each ;

View File

@ -32,8 +32,8 @@ ARTICLE: "grouping" "Groups and clumps"
"{ 1 2 3 4 } 2 clump ." "{ { 1 2 } { 2 3 } { 3 4 } }"
}
{ $unchecked-example
"USING: grouping ;"
"{ 1 2 3 4 } dup" "2 <clumps> unclip-last [ [ first ] map ] dip append sequence= ." "t"
"USING: grouping assocs sequences ;"
"{ 1 2 3 4 } dup" "2 <clumps> unclip-last [ keys ] dip append sequence= ." "t"
}
}
{ "With circular clumps, collecting the first element of each subsequence yields the original sequence. Collecting the " { $snippet "n" } "th element of each subsequence would rotate the original sequence " { $snippet "n" } " elements rightward:"
@ -42,8 +42,8 @@ ARTICLE: "grouping" "Groups and clumps"
"{ 1 2 3 4 } 2 circular-clump ." "{ { 1 2 } { 2 3 } { 3 4 } { 4 1 } }"
}
{ $unchecked-example
"USING: grouping ;"
"{ 1 2 3 4 } dup" "2 <circular-clumps> [ first ] map sequence= ." "t"
"USING: grouping assocs sequences ;"
"{ 1 2 3 4 } dup" "2 <circular-clumps> keys sequence= ." "t"
}
{ $unchecked-example
"USING: grouping ;"

View File

@ -34,7 +34,7 @@ SYMBOL: vocab-articles
: extract-values ( element -- seq )
\ $values swap elements dup empty? [
first rest [ first ] map
first rest keys
] unless ;
: extract-value-effects ( element -- seq )

View File

@ -22,7 +22,7 @@ PRIVATE>
utf8 file-lines { "" } split [
[ " " split ] map
[ first { "Name:" "Alias:" } member? ] filter
[ second ] map { "None" } diff
values { "None" } diff
] map harvest ;
: make-aliases ( file -- n>e )

View File

@ -1,6 +1,6 @@
! Copyright (C) 2007-2009 Samuel Tardieu.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays combinators kernel make math math.functions
USING: arrays assocs combinators kernel make math math.functions
math.primes math.ranges sequences sequences.product sorting
io math.parser ;
IN: math.primes.factors
@ -32,7 +32,7 @@ PRIVATE>
: group-factors ( n -- seq )
dup prime? [ 1 2array 1array ] [ (group-factors) ] if ; flushable
: unique-factors ( n -- seq ) group-factors [ first ] map ; flushable
: unique-factors ( n -- seq ) group-factors keys ; flushable
: factors ( n -- seq )
group-factors [ first2 swap <array> ] map concat ; flushable

View File

@ -54,7 +54,7 @@ IN: tools.completion
sort-keys <reversed>
[ 0 [ first max ] reduce 3 /f ] keep
[ first < ] with filter
[ second ] map ;
values ;
: complete ( full short -- score )
[ dupd fuzzy score ] 2keep

View File

@ -209,7 +209,7 @@ load-data {
} cleave
: postprocess-class ( -- )
combine-map [ [ second ] map ] map concat
combine-map [ values ] map concat
[ combining-class not ] filter
[ 0 swap class-map set-at ] each ;

View File

@ -118,7 +118,7 @@ unless
] 2map ;
: (make-callbacks) ( implementations -- sequence )
dup [ first ] map (make-iunknown-methods)
dup keys (make-iunknown-methods)
[ [ first2 ] 2dip swap (make-interface-callbacks) ]
curry map-index ;

View File

@ -55,7 +55,7 @@ IN: xml.elements
">" expect ;
: assure-no-extra ( seq -- )
[ first ] map {
keys {
T{ name f "" "version" f }
T{ name f "" "encoding" f }
T{ name f "" "standalone" f }

View File

@ -3,7 +3,7 @@ ui.gadgets ui.gadgets.buttons ui.gadgets.packs ui.gadgets.borders
ui.gadgets.scrollers ui.tools.listener accessors ;
IN: demos
: demo-vocabs ( -- seq ) "demos" tagged [ second ] map concat [ name>> ] map ;
: demo-vocabs ( -- seq ) "demos" tagged values concat [ name>> ] map ;
: <run-vocab-button> ( vocab-name -- button )
dup '[ drop [ _ run ] \ run call-listener ] <border-button> ;

View File

@ -499,7 +499,7 @@ TYPED:: elf-segment-sections ( segment: Elf32/64_Phdr sections: Elf32/64_Shdr-ar
segment [ p_offset>> dup ] [ p_filesz>> + ] bi [a,b) :> segment-interval
sections [ dup [ sh_offset>> dup ] [ sh_size>> + ] bi [a,b) 2array ] { } map-as :> section-intervals
section-intervals [ second segment-interval interval-intersect empty-interval = not ]
filter [ first ] map ;
filter keys ;
TYPED:: virtual-address-segment ( elf: Elf32/64_Ehdr address -- program-header/f )
elf elf-program-headers elf-loadable-segments [

View File

@ -40,7 +40,7 @@ MEMO: ip-db ( -- seq )
: filter-overlaps ( alist -- alist' )
2 clump
[ first2 [ first second ] [ first first ] bi* < ] filter
[ first ] map ;
keys ;
MEMO: ip-intervals ( -- interval-map )
ip-db [ [ [ from>> ] [ to>> ] bi 2array ] keep ] { } map>assoc

View File

@ -552,7 +552,7 @@ SYNTAX: UNIFORM-TUPLE:
[ [ length ] [ >int-array ] bi glDrawBuffers ] if ;
: bind-named-output-attachments ( program-instance framebuffer attachments -- )
rot '[ first _ swap output-index ] sort-with [ second ] map
rot '[ first _ swap output-index ] sort-with values
bind-unnamed-output-attachments ;
: bind-output-attachments ( program-instance framebuffer attachments -- )

View File

@ -198,8 +198,8 @@ DEFER: (d)
: bigraded-betti ( u-generators z-generators -- seq )
[ basis graded ] bi@ tensor bigraded-ker/im-d
[ [ [ first ] map ] map ] keep
[ [ second ] map 2 head* { 0 0 } prepend ] map
[ [ keys ] map ] keep
[ values 2 head* { 0 0 } prepend ] map
rest dup first length 0 <array> suffix
[ v- ] 2map ;

View File

@ -32,7 +32,7 @@ TUPLE: function name alien return params ;
LLVMGetFirstFunction [ (functions) ] { } make [ <function> ] map ;
: function-effect ( function -- effect )
[ params>> [ first ] map ] [ return>> void? 0 1 ? ] bi <effect> ;
[ params>> keys ] [ return>> void? 0 1 ? ] bi <effect> ;
: install-function ( function -- )
dup name>> "alien.llvm" create-vocab drop
@ -53,4 +53,4 @@ TUPLE: function name alien return params ;
[ normalize-path ] [ file-name ] bi
[ load-into-jit ] keep install-module ;
<< "alien.llvm" create-vocab drop >>
<< "alien.llvm" create-vocab drop >>

View File

@ -30,7 +30,7 @@ CONSTANT: lo 1010101030
CONSTANT: hi 1389026570
: form-fitting? ( n -- ? )
number>digits 2 group [ first ] map
number>digits 2 group keys
{ 1 2 3 4 5 6 7 8 9 0 } = ;
: candidates ( -- seq )