point-free
point-free copied to clipboard
`cond-proc` and `define/cond-proc`
Point-free definition of predicate-function dispatchers. Using function cond-proc:
(define first-list/vector/string
(cond-proc list? first
vector? vector-first
string? string-first))
> (first-list/vector/string '(a b c))
'a
> (first-list/vector/string #(a b c))
'a
> (first-list/vector/string "abc")
#\a
Using syntax define/cond-proc:
(define/cond-proc first-list/vector/string
[list? first]
[vector? vector-first]
[string? string-first])
Not sure how to handle else cases. Keyword argument for cond-proc and syntax parameter for define/cond-proc sounds reasonable - syntax param can throw reasonable error message if else is used outside define/cond-proc or cond.