4 ms·
I guess the Elixir "custom sigil" is a generalized version of the Ruby or Perl special quoting styles for things like regexes or shell commands? There are at l
by fanf2 5y ago
I guess the Elixir "custom sigil" is a generalized version of the Ruby or Perl special quoting styles for things like regexes or shell commands?
There are at least a couple of prominent versions of that: a great dynamic language version is JavaScript template literals <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...>; or in the static language world there's C++ user-defined literals <https://en.cppreference.com/w/cpp/language/user_literal https://en.cppreference.com/w/cpp/language/user_literal> (tho if I remember correctly they are horrible for strings unless you are using a recent version of C++)
- derefr 5y agoRight. Elixir's sigils (https://elixir-lang.org/getting-started/sigils.html https://elixir-lang.org/getting-started/sigils.html) are just a macros in the current namespace of name name pattern sigil_[letter], where writing ~x/foo/ or ~x(foo) etc., evaluates the macro sigil_x("foo") at compile-time. The JavaScript equivalent with tagged template literals isn't the same, because it isn't a macro, and so the template function has to run at runtime. As such, these are no longer literals (i.e. pure data) per se. The C++ equivalent is closer, if-and-only-if the user-defined literal operator function call is a constexpr that gets pre-evaluated.