Skip to content

Instantly share code, notes, and snippets.

@OleMchls
Created March 23, 2016 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OleMchls/d3fc5fb0b02965fc6d92 to your computer and use it in GitHub Desktop.
Save OleMchls/d3fc5fb0b02965fc6d92 to your computer and use it in GitHub Desktop.
elixir_string_match
# assign the prefix to a variable
iex(1)> pre = "he"
"he"
# a string match against the prefix works as expected
iex(2)> << "he", rest::binary >> = "hello"
"hello"
# a string match using the pinned prefix variable doesn't
iex(3)> << ^pre, rest::binary >> = "hello"
** (MatchError) no match of right hand side value: "hello"
# why?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment