All Projects → guenchi → match

guenchi / match

Licence: MIT license
Pattern-Matching written by Dan Friedman, Erik Hilsdale and Kent Dybvig

Programming Languages

scheme
763 projects

Projects that are alternatives of or similar to match

Stumpy
STUMPY is a powerful and scalable Python library for modern time series analysis
Stars: ✭ 2,019 (+9995%)
Mutual labels:  pattern-matching
Akar
First-class patterns for Clojure. Made with love, functions, and just the right amount of syntax.
Stars: ✭ 176 (+780%)
Mutual labels:  pattern-matching
Patty
A pattern matching library for Nim
Stars: ✭ 214 (+970%)
Mutual labels:  pattern-matching
Motif
Scala-like pattern matching for Java 8
Stars: ✭ 149 (+645%)
Mutual labels:  pattern-matching
Fpgo
Monad, Functional Programming features for Golang
Stars: ✭ 165 (+725%)
Mutual labels:  pattern-matching
Gradoop
Distributed Graph Analytics with Apache Flink
Stars: ✭ 197 (+885%)
Mutual labels:  pattern-matching
Grape
🍇 Syntax-aware grep-like for Clojure
Stars: ✭ 132 (+560%)
Mutual labels:  pattern-matching
Poica
🧮 A research programming language on top of C macros
Stars: ✭ 231 (+1055%)
Mutual labels:  pattern-matching
Symja android library
☕️ Symja - computer algebra language & symbolic math library. A collection of popular algorithms implemented in pure Java.
Stars: ✭ 170 (+750%)
Mutual labels:  pattern-matching
Trivia
Pattern Matcher Compatible with Optima
Stars: ✭ 210 (+950%)
Mutual labels:  pattern-matching
Eval
Eval is a lightweight interpreter framework written in Swift, evaluating expressions at runtime
Stars: ✭ 157 (+685%)
Mutual labels:  pattern-matching
Egison Ruby
A Ruby gem for non-linear pattern-matching with backtracking
Stars: ✭ 159 (+695%)
Mutual labels:  pattern-matching
Hexraystoolbox
Hexrays Toolbox - Find code patterns within the Hexrays AST
Stars: ✭ 202 (+910%)
Mutual labels:  pattern-matching
Rosie Pattern Language
Rosie Pattern Language (RPL) and the Rosie Pattern Engine have MOVED!
Stars: ✭ 146 (+630%)
Mutual labels:  pattern-matching
Mlstyle.jl
Julia functional programming infrastructures and metaprogramming facilities
Stars: ✭ 223 (+1015%)
Mutual labels:  pattern-matching
Z
Pattern Matching for Javascript
Stars: ✭ 1,693 (+8365%)
Mutual labels:  pattern-matching
Symbolicutils.jl
Expression rewriting and simplification
Stars: ✭ 189 (+845%)
Mutual labels:  pattern-matching
csharp-workshop
NDC London 2019, Workshop: Become a better C# programmer: more Value, more Expressions, no Waiting
Stars: ✭ 21 (+5%)
Mutual labels:  pattern-matching
Actor Framework
An Open Source Implementation of the Actor Model in C++
Stars: ✭ 2,637 (+13085%)
Mutual labels:  pattern-matching
Zeallot
Variable assignment with zeal! (or multiple, unpacking, and destructuring assignment in R)
Stars: ✭ 204 (+920%)
Mutual labels:  pattern-matching

match

This is a pioneering work by Dan Friedman, Erik Hilsdale and Kent Dybvig that brings pattern matching to Scheme.

It runs amazingly, and I think learning how to use it is a must-have for all Scheme users.

Install:

raven install match

How to use:

First of all, you have to know (match) accept a list, and matching it with you set:

You can simply use it like this:

(match '(a 1 2)
    ((a ,x ,y) x))

(a ,x ,y) this phrase means, match the list with a symbol 'a, the car of list must be 'a not 'b or 'c.

you can write (1 ,x ,y) if you want to designation car to 1. or any number, or in place of cadr and caddr.

Just remenber if you use symbol or number or char, that fix there want has to be.

and the ,x ,y means it can be anything. you can call it as the last x in ((a ,x ,y) x), which means it back the value of x if match.

it can also accept ...

(match '(a 1 2 3)
    ((a ,x ...) `(,x ...)))

the ... means accept any number of x, the second mean return all what it got.

so it will return '(1 2 3) and '(1 2 3 4 5) for '(a 1 2 3 4 5).

and maybe you want the x must be symbol, then do this:

(match '(a 1 2)
    ((a ,x ,y) (guard (symbol? x)) y))

(guard) need a boolean, if true this phrase match, and false not. although the list is match, but (guard) have one vote veto power, like the five permanent member in the United Nations.

Notice that the atom in test of (guard) is NOT unquote. like (symbol? x), not (symbol? ,x).

The amazing thing is you can nesting the match: if we define:

(define Expl
    (lambda (x)
        (match x
            ((a ,x) x))))

then we can use it like this: ,(Expr -> e) so:

(match '(a (a 3) 2)
    ((a ,(Expl -> e) ,y)  e))

it will return 3.

,(Expr -> e) test the second element and it can call by ,e.

Notice that in ,(Expr -> e) the e is not unquote and has unquote when we call it.

For more information: Use Match

 Exp    ::= (match              Exp Clause)
         || (trace-match        Exp Clause)
         || (match+       (Id*) Exp Clause*)
         || (trace-match+ (Id*) Exp Clause*)
         || OtherSchemeExp

 Clause ::= (Pat Exp+) || (Pat (guard Exp*) Exp+)

 Pat    ::= (Pat ... . Pat)
         || (Pat . Pat)
         || ()
         || #(Pat* Pat ... Pat*)
         || #(Pat*)
         || ,Id
         || ,[Id*]
         || ,[Cata -> Id*]
         || Id

 Cata   ::= Exp

YOU'RE NOT ALLOWED TO REFER TO CATA VARS IN GUARDS. (reasonable!)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].