![]() ![]() The statements following the pattern are then executed. Matching an integer against a variable succeeds, so the system binds 10 to the variable n. The n in the next pattern is an example of a variable. This match fails and the next pattern is evaluated. When you call fact(10) the value 10 is first matched against the first pattern 0. If you look hard enough however, you’ll notice XSLT is basically a thinly disguised functional (declarative) programming language. ![]() Pattern matching might seem like an esoteric functional programming feature, but anyone who has written an XSLT stylesheet has used pattern matching before, through the element. The factorial function can be implemented in ML like so (note that is not an efficient way to calculate factorials, but it serves as a good introduction to pattern matching): fun fact 0 = 1 Pattern matching is a form of conditional branching which allows you to concisely match on data structure patterns and bind variables at the same time (Wikipedia, Conditional Statements, Pattern Matching.) Pattern matching is supported in some functional languages such as ML, Haskell, OCaml, and Erlang. Pattern Matching in JavaScript - Bram Stein
0 Comments
Leave a Reply. |