Created
December 22, 2013 06:48
-
-
Save smosher/8079234 to your computer and use it in GitHub Desktop.
pattern matching demo in Io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Work in progress, code coming soon: | |
Io> match(1) [2: 5, 4: 2, 1: "yay"] | |
==> yay | |
Io> match(2) [2: 5, 4: 2, 1: "yay"] | |
==> 5 | |
Io> a := 10 | |
==> 10 | |
Io> match(a) [2: 5, 4: 2, 10: "yay"] | |
==> yay | |
Io> match(a) [2: 5, 4: 2, a: "yay"] | |
Exception: Object does not respond to 'a:' // <-- probably won't be fixed | |
:( :( :( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
match(a) [2: 5, 4: 2, a : "yay"] // works, note the space between 'a' and ':'
'a:' is a valid slot name, and the slot constructor has to be legal in slot names for it to work at all (without changing the reader anyhow)