Native function suggestion

Started by Jeff, November 26, 2007, 08:07:47 AM

Previous topic - Next topic

Jeff

Lutz,



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:


(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.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code