point-free icon indicating copy to clipboard operation
point-free copied to clipboard

`cond-proc` and `define/cond-proc`

Open jackfirth opened this issue 10 years ago • 0 comments

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.

jackfirth avatar Feb 02 '16 23:02 jackfirth