-
Notifications
You must be signed in to change notification settings - Fork 1
GTProgramControl
Bruce Mitchener edited this page Jan 6, 2014
·
1 revision
Docs currently at: http://www.ai.mit.edu/~jrb/goo/manual/goomanual_8.html
Some of these things hopefully no one would actually need, but I'm going for completeness.
If
(if #t 1 2) => 1 (if #f 1 2) => 2
And (Short circuits!)
(dm out-true (da-msg|<str>) (msg out da-msg) #t) (dm out-false (da-msg|<str>) (msg out da-msg) #f) (and (out-true "A") (out-false "B") (out-true "C")) => AB (with result of #f)
Or (Short circuits!)
(or (out-true "A") (out-false "B") (out-true "C")) => A (with result of #t) (or (out-false "A") (out-true "B") (out-true "C")) => AB (with result of #t)
Great for tricks like you'd see in perl and PHP: (or (do_something) (die)) type stuff. I'm not sure whether that's going to get you lynched by the functional programming mob or not, though.
Unless
(unless #t 1) => #f (unless #f 1) => 1
When
(when #t 1) => 1 (when #f 1) => #f
Cond
(dm guess (n|<int>) (cond ((> n 7) (msg out "Too High!\n")) ((< n 7) (msg out "Too Low!\n")) ((== n 7) (msg out "You got it!\n")) ) )
Case
(dm guess (n|<int>) (msg out (case n ((1 2 3 9 10) "Good lord you're far off!") ((4 5) "Getting closer!") ((6 8) "So close!") ((7) "You got it!"))) (msg out "\n"))
Case-By : Case with custom test
(dc <a> (<any>)) (dc <b> (<a>)) (dc <c> (<a>)) (dc <d> (<b> <c>)) ;; Oooooh! (dm ctest (obj|<any>) (msg out (case-by obj isa? ((<d>) "D!\n") ((<c>) "C!\n") ((<b>) "B!\n") ((<a>) "A!\n"))) ) (ctest (new <d>)) => D!
(Eg, precendence happens.)
Someone else do the rest!