Native function suggestion

For the Compleat Fan
Post Reply
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio

Native function suggestion

Post by Jeff »


I was wondering if it would be possible to add a built-in version of cond that uses match/unify to match and then create a local scope for the matched condition's body, such as:

Code: Select all

(define (foo)
  (match-cond (args)
    ((A B C) (do something where A B C are declared as local))
    ((A B) (do something when (args) only has A and B))
    (true (catch-all clause)))
The only thing would be that we would need to add an infix cons symbol that would let it catch run-on lists, such as (A B ... C) or something, which would match/unify A with (list 0), B with (list 1), and C with the rest of the list, no matter what it is. It could probably be fairly simply implemented by breaking the pattern up at the cons symbol, matching against the list using a * operator or something (from the match syntax).

I've worked on this as a macro, but it ended up being so slow that it wasn't worth using. However, this would give us modern functional pattern matching syntax, and allow some really nice, concise coding.
Old programmers don't die. They just parse on...

Artful code

Post Reply