Skip to content

Instantly share code, notes, and snippets.

@faustinoaq
Created September 26, 2017 23:09
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 faustinoaq/20c12653130282971ba8102d9e60c5c9 to your computer and use it in GitHub Desktop.
Save faustinoaq/20c12653130282971ba8102d9e60c5c9 to your computer and use it in GitHub Desktop.
Compiled time array
A = [] of Nil
{% A << 0 %}
{% A << "Some String" %}
{% p A[0] %} # => 0
{% p A[1] %} # => "Some String"
@faustinoaq
Copy link
Author

@faustinoaq
Copy link
Author

When you don't use a constant it's not typed, so a constant can be used as a placeholder in macros
That is, when you don't use that constant at runtime
Also known has hack #123 (just kidding)
But Elixir does something similar, only with attributes (which only exist at compile-time, I think)

https://gitter.im/crystal-lang/crystal?at=59cac1267b7d98d30d3d2033

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