# repetition specifies:
# token | description |
# ------+----------------------+
# $(), | each comma delemited |
# $():, | each kwarg delemited |
# $()* | each |
#
# intrinsic macros
# $to_s!
# $to_ivar!
# $to_kwarg!
# $to_sym!
# $local!
def $make_class!($name, $($attr_accessors),*)
class $name
def initialize($($to_kwarg!($attr_accessors)),*)
$(
$to_ivar!($attr_accessors) = $to_s!($attr_accessors)
)*
end
end
end
$make_class!(Person, :first_name, :last_name)
# generates
class Person
def initialize(first_name:, last_name:)
@first_name = first_name
@last_name = last_name
end
end
def $each!($collection, **$($name, $block))
$local!(os) = $collection
$local!(l) = $collection.length
$local!(i) = 0
while $local!(i) < $local!(l)
$name = $local!(os)[i]
$block
$local(i) += 1
end
end
$each!(bullets,
bullet: begin
if Geometry.intersect_rect?(bullet, player)
bullet.killed_at = Kernel.tick_count
end
end)
# generates
__uuid_os__ = bullets
__uuid_l__ = bullets.length
__uuid_i__ = 0
while __uuid_i__ < __uuid_l__
bullet = __uuid_os__[i]
begin
if Geometry.intersect_rect?(bullet, player)
bullet.killed_at = Kernel.tick_count
end
end
__uuid_i__ += 1
end