Doing stupid things with ASTs
Session Type | Live |
---|---|
Start time | 12:00 |
End time | 12:30 |
Countdown link | Open timer |
Abstract Syntax Trees are a tool for analysing and manipulating the structure and function of code. They can be used to do about a million different useful and smart things. This talk is not about those things.
Did you ever get an idea that is so stupid you couldn't think about anything else until you'd made it real? In this talk I'll show you how I implemented what I think is probably the worst idea I've ever had: Using genetic programming to write code.
Abstract Syntax Trees allow you to parse code into a tree-like structure, with each node in the tree representing an operation or a variable. They're used for little things like syntax highlighting in your IDE, as well as fundamental things like compiling your code at runtime. Recent releases of Python have included substantial improvements to the core AST library.
Genetic programming is a slightly unfashionable technique from data science which "evolves" solutions to problems by randomly combining and mutating programs until a "fit" solution is found. Typically the programs involve a very tightly-controlled set of mathematical operators in a tree-like structure.
You can see where this is going. Can you use genetic programming techniques to combine and mutate abstract syntax trees? Can you evolve programs that produce working code? Can you actually solve a real-life problem using this approach? The answer to all these questions is "No, don't be stupid." But I gave it a crack anyway.
Simon Carryer is a data analyst in Wellington, New Zealand. He works on other people's dumb ideas all week, and his own dumb ideas in the weekend.