Skip to content

Instantly share code, notes, and snippets.

@sudowork
Created March 26, 2013 07:34
Show Gist options
  • Select an option

  • Save sudowork/5243717 to your computer and use it in GitHub Desktop.

Select an option

Save sudowork/5243717 to your computer and use it in GitHub Desktop.
% Basic bit-wise pattern matching
1> <<Foo,Bar,Baz>> = <<1,2,3>>.
% Some more advanced pattern matching
2> <<R:8,G:8,B:8>> = <<16#BADA55:24>>.
<<"ºÚU">>
% Using the built in bindings command
3> b().
B = 85
Bar = 2
Baz = 3
Foo = 1
G = 218
R = 186
ok
% Pattern matching + list comprehensions on bit data, producing tuples
5> [ {R,G,B} || <<R:8, G:8, B:8>> <= <<1,2,3,4,5,6,7,8,9>> ].
[{1,2,3},{4,5,6},{7,8,9}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment