case/cond

db4
Doug Coleman 2008-04-11 12:57:43 -05:00
parent acf6132389
commit 484f765566
19 changed files with 48 additions and 58 deletions

View File

@ -30,7 +30,7 @@ MEMO: fn ( n -- x )
{
{ [ dup 2 < ] [ drop 1 ] }
{ [ dup odd? ] [ 2/ fn ] }
{ [ t ] [ 2/ [ fn ] [ 1- fn + ] bi + ] }
[ 2/ [ fn ] [ 1- fn + ] bi + ]
} cond ;
: euler169 ( -- result )

View File

@ -44,7 +44,7 @@ IN: project-euler.175
{
{ [ dup integer? ] [ 1- 0 add-bits ] }
{ [ dup 1 < ] [ 1 over - / dupd compute 1 1 add-bits ] }
{ [ t ] [ [ 1 mod compute ] 2keep >integer 0 add-bits ] }
[ [ 1 mod compute ] 2keep >integer 0 add-bits ]
} cond ;
PRIVATE>

View File

@ -113,7 +113,7 @@ M: array noise [ noise ] map vsum ;
noise first2 {
{ [ over 4 <= ] [ >r drop 0 r> ] }
{ [ over 15 >= ] [ >r 2 * r> ] }
{ [ t ] [ ] }
[ ]
} cond
{
! short words are easier to read
@ -123,7 +123,7 @@ M: array noise [ noise ] map vsum ;
{ [ dup 25 >= ] [ >r 2 * r> 20 max ] }
{ [ dup 20 >= ] [ >r 5/3 * r> ] }
{ [ dup 15 >= ] [ >r 3/2 * r> ] }
{ [ t ] [ ] }
[ ]
} cond noise-factor ;
GENERIC: word-noise-factor ( word -- factor )

View File

@ -9,7 +9,7 @@ IN: rot13
{
{ [ dup letter? ] [ CHAR: a rotate ] }
{ [ dup LETTER? ] [ CHAR: A rotate ] }
{ [ t ] [ ] }
[ ]
} cond ;
: rot13 ( string -- string ) [ rot-letter ] map ;

View File

@ -65,7 +65,7 @@ GENERIC: (serialize) ( obj -- )
read1 {
{ [ dup HEX: ff = ] [ drop deserialize-cell read be> ] }
{ [ dup HEX: 80 >= ] [ HEX: 80 bitxor ] }
{ [ t ] [ read be> ] }
[ read be> ]
} cond ;
: serialize-shared ( obj quot -- )
@ -183,7 +183,7 @@ M: word (serialize) ( obj -- )
{
{ [ dup t eq? ] [ serialize-true ] }
{ [ dup word-vocabulary not ] [ serialize-gensym ] }
{ [ t ] [ serialize-word ] }
[ serialize-word ]
} cond ;
M: wrapper (serialize) ( obj -- )

View File

@ -56,9 +56,9 @@ SYMBOL: data-mode
"220 OK\r\n" write flush t
] }
{ [ data-mode get ] [ dup global [ print ] bind t ] }
{ [ t ] [
[
"500 ERROR\r\n" write flush t
] }
]
} cond nip [ process ] when ;
: mock-smtp-server ( port -- )

View File

@ -70,7 +70,7 @@ LOG: smtp-response DEBUG
{ [ dup "50" head? ] [ smtp-response "syntax error" throw ] }
{ [ dup "53" head? ] [ smtp-response "invalid authentication data" throw ] }
{ [ dup "55" head? ] [ smtp-response "fatal error" throw ] }
{ [ t ] [ "unknown error" throw ] }
[ "unknown error" throw ]
} cond ;
: multiline? ( response -- boolean )

View File

@ -306,7 +306,7 @@ M: invaders-gadget draw-gadget* ( gadget -- )
{ [ dup 184 238 within pick 0 223 within and ] [ 2drop green ] }
{ [ dup 240 247 within pick 16 133 within and ] [ 2drop green ] }
{ [ dup 247 215 - 247 184 - within pick 0 223 within and ] [ 2drop red ] }
{ [ t ] [ 2drop white ] }
[ 2drop white ]
} cond ;
: plot-bitmap-bits ( bitmap point byte bit -- )

View File

@ -32,7 +32,7 @@ DEFER: search
{ [ 3dup nip row-contains? ] [ 3drop ] }
{ [ 3dup drop col-contains? ] [ 3drop ] }
{ [ 3dup box-contains? ] [ 3drop ] }
{ [ t ] [ assume ] }
[ assume ]
} cond ;
: solve ( x y -- ) 9 [ 1+ 2over attempt ] each 2drop ;
@ -62,7 +62,7 @@ DEFER: search
{ [ over 9 = ] [ >r drop 0 r> 1+ search ] }
{ [ over 0 = over 9 = and ] [ 2drop solution. ] }
{ [ 2dup board> ] [ >r 1+ r> search ] }
{ [ t ] [ solve ] }
[ solve ]
} cond ;
: sudoku ( board -- )

View File

@ -35,7 +35,7 @@ unicode.categories ;
{ [ 2dup length 1- number= ] [ 2drop 4 ] }
{ [ 2dup >r 1- r> nth Letter? not ] [ 2drop 10 ] }
{ [ 2dup >r 1+ r> nth Letter? not ] [ 2drop 4 ] }
{ [ t ] [ 2drop 1 ] }
[ 2drop 1 ]
} cond ;
: score ( full fuzzy -- n )

View File

@ -10,7 +10,7 @@ IN: tools.vocabs.browser
{
{ [ dup not ] [ drop "" ] }
{ [ dup vocab-main ] [ drop "[Runnable]" ] }
{ [ t ] [ drop "[Loaded]" ] }
[ drop "[Loaded]" ]
} cond ;
: write-status ( vocab -- )

View File

@ -216,7 +216,7 @@ MEMO: all-vocabs-seq ( -- seq )
{ [ ".test" ?tail ] [ t ] }
{ [ "raptor" ?head ] [ t ] }
{ [ dup "tools.deploy.app" = ] [ t ] }
{ [ t ] [ f ] }
[ f ]
} cond nip ;
: filter-dangerous ( seq -- seq' )

View File

@ -73,7 +73,7 @@ M: object add-breakpoint ;
{ [ dup "step-into" word-prop ] [ "step-into" word-prop call ] }
{ [ dup standard-generic? ] [ effective-method (step-into-execute) ] }
{ [ dup primitive? ] [ execute break ] }
{ [ t ] [ word-def (step-into-quot) ] }
[ word-def (step-into-quot) ]
} cond ;
\ (step-into-execute) t "step-into?" set-word-prop
@ -153,7 +153,7 @@ SYMBOL: +stopped+
{ [ dup quotation? ] [ add-breakpoint , \ break , ] }
{ [ dup array? ] [ add-breakpoint , \ break , ] }
{ [ dup word? ] [ literalize , \ (step-into-execute) , ] }
{ [ t ] [ , \ break , ] }
[ , \ break , ]
} cond %
] [ ] make
] change-frame ;

View File

@ -29,7 +29,7 @@ TUPLE: avl-node balance ;
avl-node-balance {
{ [ dup zero? ] [ 2drop 0 0 ] }
{ [ over = ] [ neg 0 ] }
{ [ t ] [ 0 swap ] }
[ 0 swap ]
} cond ;
: double-rotate ( node -- node )
@ -89,7 +89,7 @@ M: avl set-at ( value key node -- node )
current-side get over avl-node-balance {
{ [ dup zero? ] [ drop neg over set-avl-node-balance f ] }
{ [ dupd = ] [ drop 0 over set-avl-node-balance t ] }
{ [ t ] [ dupd neg change-balance rebalance-delete ] }
[ dupd neg change-balance rebalance-delete ]
} cond ;
: avl-replace-with-extremity ( to-replace node -- node shorter? )

View File

@ -112,7 +112,7 @@ M: tree set-at ( value key tree -- )
[ 2drop t ] }
{ [ >r 2nip r> [ tree-call ] 2keep rot ]
[ drop [ node-key ] keep node-value t ] }
{ [ t ] [ >r node-right r> find-node ] }
[ >r node-right r> find-node ]
} cond ; inline
M: tree-mixin assoc-find ( tree quot -- key value ? )

View File

@ -10,23 +10,13 @@ IN: unix.stat
: S_IFMT OCT: 170000 ; ! These bits determine file type.
: S_IFDIR OCT: 40000 ; ! Directory.
: S_IFCHR OCT: 20000 ; ! Character device.
: S_IFBLK OCT: 60000 ; ! Block device.
: S_IFREG OCT: 100000 ; ! Regular file.
: S_IFIFO OCT: 010000 ; ! FIFO.
: S_IFLNK OCT: 120000 ; ! Symbolic link.
: S_IFSOCK OCT: 140000 ; ! Socket.
: S_ISTYPE ( mode mask -- val ) >r S_IFMT bitand r> = ;
: S_ISREG ( mode -- value ) S_IFREG S_ISTYPE ;
: S_ISDIR ( mode -- value ) S_IFDIR S_ISTYPE ;
: S_ISCHR ( mode -- value ) S_IFCHR S_ISTYPE ;
: S_ISBLK ( mode -- value ) S_IFBLK S_ISTYPE ;
: S_ISFIFO ( mode -- value ) S_IFIFO S_ISTYPE ;
: S_ISLNK ( mode -- value ) S_IFLNK S_ISTYPE ;
: S_ISSOCK ( mode -- value ) S_IFSOCK S_ISTYPE ;
: S_IFDIR OCT: 40000 ; inline ! Directory.
: S_IFCHR OCT: 20000 ; inline ! Character device.
: S_IFBLK OCT: 60000 ; inline ! Block device.
: S_IFREG OCT: 100000 ; inline ! Regular file.
: S_IFIFO OCT: 010000 ; inline ! FIFO.
: S_IFLNK OCT: 120000 ; inline ! Symbolic link.
: S_IFSOCK OCT: 140000 ; inline ! Socket.
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! File Access Permissions

View File

@ -52,22 +52,22 @@ GENERIC: client-event ( event window -- )
: handle-event ( event window -- )
over XAnyEvent-type {
{ [ dup Expose = ] [ drop expose-event ] }
{ [ dup ConfigureNotify = ] [ drop configure-event ] }
{ [ dup ButtonPress = ] [ drop button-down-event$ ] }
{ [ dup ButtonRelease = ] [ drop button-up-event$ ] }
{ [ dup EnterNotify = ] [ drop enter-event ] }
{ [ dup LeaveNotify = ] [ drop leave-event ] }
{ [ dup MotionNotify = ] [ drop motion-event ] }
{ [ dup KeyPress = ] [ drop key-down-event ] }
{ [ dup KeyRelease = ] [ drop key-up-event ] }
{ [ dup FocusIn = ] [ drop focus-in-event ] }
{ [ dup FocusOut = ] [ drop focus-out-event ] }
{ [ dup SelectionNotify = ] [ drop selection-notify-event ] }
{ [ dup SelectionRequest = ] [ drop selection-request-event ] }
{ [ dup ClientMessage = ] [ drop client-event ] }
{ [ t ] [ 3drop ] }
} cond ;
{ \ Expose [ expose-event ] }
{ \ ConfigureNotify [ configure-event ] }
{ \ ButtonPress [ button-down-event$ ] }
{ \ ButtonRelease [ button-up-event$ ] }
{ \ EnterNotify [ enter-event ] }
{ \ LeaveNotify [ leave-event ] }
{ \ MotionNotify [ motion-event ] }
{ \ KeyPress [ key-down-event ] }
{ \ KeyRelease [ key-up-event ] }
{ \ FocusIn [ focus-in-event ] }
{ \ FocusOut [ focus-out-event ] }
{ \ SelectionNotify [ selection-notify-event ] }
{ \ SelectionRequest [ selection-request-event ] }
{ \ ClientMessage [ client-event ] }
[ 3drop ]
} case ;
: configured-loc ( event -- dim )
dup XConfigureEvent-x swap XConfigureEvent-y 2array ;

View File

@ -111,7 +111,7 @@ TAG: boolean xml>item
dup children>string {
{ [ dup "1" = ] [ 2drop t ] }
{ [ "0" = ] [ drop f ] }
{ [ t ] [ "Bad boolean" server-error ] }
[ "Bad boolean" server-error ]
} cond ;
: unstruct-member ( tag -- )

View File

@ -86,7 +86,7 @@ SYMBOL: ns-stack
{ [ dup not ] [ 2drop ] }
{ [ 2dup = ] [ 2drop next ] }
{ [ dup CHAR: & = ] [ drop parse-entity (parse-char) ] }
{ [ t ] [ , next (parse-char) ] }
[ , next (parse-char) ]
} cond ;
: parse-char ( ch -- string )
@ -194,9 +194,9 @@ SYMBOL: ns-stack
{
{ [ get-char dup CHAR: ! = ] [ drop next direct ] }
{ [ CHAR: ? = ] [ next instruct ] }
{ [ t ] [
[
start-tag [ dup add-ns pop-ns <closer> ]
[ middle-tag end-tag ] if
CHAR: > expect
] }
]
} cond ;