I used this in my m-expr reader, as a generalisation of do1:
(mac w/res body
" Define the result of this expression by calling the 'result' (captured!)
function inside. Calling result does not change the control flow, like in
Delphi/Pascal."
(w/uniq return
`(withs (,return nil result [= ,return _])
,@body
,return)))
(def call-reader-w/delimiters (port start end fun)
" Reads from port with fun, ensures that given delimiters are read before and
after, otherwise an error is raised"
(w/res (expect port start 'delim)
(result (fun port))
(expect port end 'delim)))
Your odd-number example could be written:
(best (fn (a b) (and odd.a (> a b))) *list-of-numbers*)
Your 'best alternative for my example is extremely clever, but doesn't work:
> (= *list-of-numbers* (6 2 4 5))
> (best (fn (a b) (and odd.a (> a b))) *list-of-numbers*)
6
I knew something was wrong with it, but it took me like half an hour to realize the flaw :)
...it can of course be fixed with extra flagging (well, it'll still fail on only lists of even numbers by not returning nil) but then you'll lose the brevity advantage over my solution.