Skip to content

Instantly share code, notes, and snippets.

@smosher
Created December 22, 2013 06:48
Show Gist options
  • Save smosher/8079234 to your computer and use it in GitHub Desktop.
Save smosher/8079234 to your computer and use it in GitHub Desktop.
pattern matching demo in Io
// 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
:( :( :(
@smosher
Copy link
Author

smosher commented Dec 22, 2013

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment