Slide 28
Slide 28 text
and we can then unparse it back into text.
^ You might be thinking, this is a terrible idea, and you're
mostly right :)
^ But some interesting real world use cases of this. Gem
called "mutant" that does mutation testing, where it
randomly changes your code and makes sure your tests fail
when your code changes. Uses this gem under the hood.
But of course we don't need to resort to this often.
^ Reason: most of the time in Lisp, code manipulation is used
for metaprogramming: code that creates code. In Ruby we
don't need to use this approach because we have a variety
of powerful tools, which come from another language:
Ruby parsing/unparsing
code = "2 + 3 * 4"
ast = Parser::CurrentRuby.parse(code)
# => [s(:send,
# s(:int, 2), :+,
# s(:send,
# s(:int, 3), :*,
# s(:int, 4))), []]
2.1.5 :005 > Unparser.unparse(ast)
# => "2 + (3 * 4)"