by Satoshi Egi
World's first language with non-linear pattern-matching against unfree data types.

Egison is a pattern-matching-oriented programming langauge. Its features enable intuitive powerful pattern-matching:

  • Non-linear pattern-matching
  • Pattern modularization
  • Modularization of pattern-matching for each data type
;;;
;;;
;;; Pattern-matching against sequence of natural numbers
;;;
;;;

; first 100 natural numbers
(test (take 100 nats))

; inifinite list of two-combinations of numbers
(define $pairs (match-all nats (list integer)
                 [<join _ (& <cons $m _> <join _ <cons $n _>>)>
                  [m n]]))

; test 'pairs'
(test (take 100 pairs))

; infinite list of pythagoras numbers
(define $pyths (map (lambda [$m $n] (+ (power m 2) (power n 2))) pairs))

; test 'pyths'
(test (take 100 pyths))

; function that enumerates all common elements between two lists
(define $commons
  (lambda [$xs $ys]
    (match-all [xs ys] [(multiset integer) (multiset integer)]
      [[<cons $c _> <cons ,c _>]
       c])))

; test 'commons'
(test (commons (take 100 primes) (take 300 pyths)))
Information updated 01/22/14
View Comments