Skip to content

Instantly share code, notes, and snippets.

@egisatoshi
Last active January 2, 2016 02:28
Show Gist options
  • Save egisatoshi/8236946 to your computer and use it in GitHub Desktop.
Save egisatoshi/8236946 to your computer and use it in GitHub Desktop.
From Egison version 3.2.0, the syntax of loop pattern is changed. The following code is an example.
% egison
Egison Version 3.2.0 (C) 2011-2013 Satoshi Egi
http://www.egison.org
Welcome to Egison Interpreter!
> (match-all {1 2 3 4 5} (list integer) [(loop $i [1 2] <join _ <cons $a_i ...>> _) a])
{[|1 2|] [|1 3|] [|2 3|] [|1 4|] [|2 4|] [|3 4|] [|1 5|] [|2 5|] [|3 5|] [|4 5|]}
> (match-all {1 2 3 4 5} (list integer) [(loop $i [1 $n] <cons $a_i ...> _) [a n]])
{[[||] 0] [[|1|] 1] [[|1 2|] 2] [[|1 2 3|] 3] [[|1 2 3 4|] 4] [[|1 2 3 4 5|] 5]}
> (match-all {1 2 3 4 5} (list integer) [(loop $i [1 $n] <join _ <cons $a_i ...>> _) [a n]])
{[[||] 0] [[|1|] 1] [[|2|] 1] [[|3|] 1] [[|4|] 1] [[|5|] 1] [[|1 2|] 2] [[|1 3|] 2] [[|2 3|] 2] [[|1 4|] 2] [[|2 4|] 2] [[|3 4|] 2] [[|1 5|] 2] [[|2 5|] 2] [[|3 5|] 2] [[|4 5|] 2] [[|1 2 3|] 3] [[|1 2 4|] 3] [[|1 3 4|] 3] [[|2 3 4|] 3] [[|1 2 5|] 3] [[|1 3 5|] 3] [[|1 4 5|] 3] [[|2 3 5|] 3] [[|2 4 5|] 3] [[|3 4 5|] 3] [[|1 2 3 4|] 4] [[|1 2 3 5|] 4] [[|1 2 4 5|] 4] [[|1 3 4 5|] 4] [[|2 3 4 5|] 4] [[|1 2 3 4 5|] 5]}
>
Leaving Egison Interpreter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment