pattern matching

created by ksandstr
(idea) by ksandstr (5.9 y) (print)   (I like it!) Sat Jun 16 2001 at 2:39:13

A technique commonly employed by functional languages (such as CAML, Haskell, SML and Miranda), allowing complicated control decisions based on data structure to be expressed in a concise manner. Typically, pattern matching constructs have an "else" clause or a wildcard symbol, so that the default case can be matched. For example, a "sum of all integers in an integer list" function in OCAML, where the ``_'' wildcard is used instead of the empty list:

let rec sum_all lst =
    match lst with
        head :: tail -> head + sum_all tail
        | _ -> 0;;

In a text processing context, pattern matching usually refers to a form of regexping or globbing.

Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.