db4
Slava Pestov 2008-10-28 16:18:47 -07:00
parent 19b703abfc
commit 5388945ef0
2 changed files with 54 additions and 2 deletions

52
extra/slides/lib.factor Executable file
View File

@ -0,0 +1,52 @@
USING: arrays assocs kernel vectors sequences namespaces
random math.parser math fry ;
IN: assocs.lib
: set-assoc-stack ( value key seq -- )
dupd [ key? ] with find-last nip set-at ;
: at-default ( key assoc -- value/key )
dupd at [ nip ] when* ;
: replace-at ( assoc value key -- assoc )
>r >r dup r> 1vector r> rot set-at ;
: peek-at* ( assoc key -- obj ? )
swap at* dup [ >r peek r> ] when ;
: peek-at ( assoc key -- obj )
peek-at* drop ;
: >multi-assoc ( assoc -- new-assoc )
[ 1vector ] assoc-map ;
: multi-assoc-each ( assoc quot -- )
[ with each ] curry assoc-each ; inline
: insert ( value variable -- ) namespace push-at ;
: generate-key ( assoc -- str )
>r 32 random-bits >hex r>
2dup key? [ nip generate-key ] [ drop ] if ;
: set-at-unique ( value assoc -- key )
dup generate-key [ swap set-at ] keep ;
: histogram ( assoc quot -- assoc' )
H{ } clone [
swap [ change-at ] 2curry assoc-each
] keep ; inline
: inc-at ( key assoc -- )
[ 0 or 1 + ] change-at ;
: ?at ( obj assoc -- value/obj ? )
dupd at* [ [ nip ] [ drop ] if ] keep ;
: if-at ( obj assoc quot1 quot2 -- )
[ ?at ] 2dip if ; inline
: when-at ( obj assoc quot -- ) [ ] if-at ; inline
: unless-at ( obj assoc quot -- ) [ ] swap if-at ; inline

View File

@ -16,7 +16,7 @@ IN: slides
}
{ default-block-style
H{
{ wrap-margin 1000 }
{ wrap-margin 1100 }
}
}
{ code-style
@ -34,7 +34,7 @@ IN: slides
}
}
{ table-content-style
H{ { wrap-margin 800 } }
H{ { wrap-margin 1000 } }
}
{ list-style
H{ { table-gap { 10 20 } } }