The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
{% for ... %}
initialize value, value, value
where the number of "value"s is the length of the splatted macro argument
private macro make_accessors(*names)
{% for name, i in names %}
def {{name}}
@data[{{i}}]
end
def {{name}}=(value : Float64)
@data[{{i}}] = value
end
{% end %}
end
private macro make_constructors(*names)
def initialize({% for name in names %} {{name}} : Float64, {% end %})
{% for name, i in names %}
@data[{{i}}] = {{name}}
{% end %}
end
def initialize(value : Float64 = 0.0)
initialize({% for name in names %} value, {% end %})
end
end
make_accessors x, y, z
make_constructors x, y, z
_
in place of i
to convey meaning to the reader.
times
method would almost be enough, except need some concise DSL to account for when the count is the length of a sequence, but still don't want to bind any e or i vars
.each
and .map
available
for in
if you wanted to iterate over them and generate code
{% for ... %}
:)