Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pattern matching for bitstrings #51

Closed
bryanjos opened this issue May 22, 2015 · 2 comments
Closed

Add pattern matching for bitstrings #51

bryanjos opened this issue May 22, 2015 · 2 comments
Milestone

Comments

@bryanjos
Copy link
Collaborator

Bitstrings are the last data structure without pattern matching support (unless I missed something else). I'm not sure how to handle matching on sizes of parts of the bitstring.

@bryanjos
Copy link
Collaborator Author

bryanjos commented Oct 6, 2015

Pattern matching on bitstrings may be possible using typedarrays and buffers.

example 1

<<"Hello, ", place::binary>> = "Hello, World"
let [place] = Patterns.match(Patterns.BitString("Hello, ", Patterns.BitString.binary()))

example 2

 @png_signature <<137::size(8), 80::size(8), 78::size(8), 71::size(8),
                13::size(8), 10::size(8), 26::size(8), 10::size(8)>>

<<@png_signature, rest::binary>>
const png_signature = BitString(BitString.integer(137), ...)
let [rest] = Patterns.match(Patterns.BitString(png_signature, Patterns.BitString.binary()))

example 3

pixels = <<213, 45, 132, 64, 76, 32, 76, 0, 0, 234, 32, 15>>
for <<r::8, g::8, b::8 <- pixels >>, do: {r, g, b}
let pixels =  BitString(BitString.integer(213), ...)
Kernel.SpecialForms._for([
  Patterns.BitString(Patterns.BitString.integer(), Patterns.BitString.integer(), Patterns.BitString.integer()),         pixels
], 
(r, g, b) => Kernel.SpecialForms.tuple(r, g, b)
)

@bryanjos
Copy link
Collaborator Author

Fixed in master

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

No branches or pull requests

1 participant