Skip to content

A tutorial on how to implement variable name generation for expressions having both named and nameless variables.

License

Notifications You must be signed in to change notification settings

MartyO256/variable-name-generation-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Variable Name Generation Tutorial

This repository contains the implementation and presentation for a tutorial on variable name generation. The goal for this tutorial is to implement an algorithm for converting expressions from a mixed representation to a named representation. This is solved by formulating sound parameter name generation as a constraint satisfaction problem.

The algorithm supports performing the following conversions:

       Generate names in a natural order
λ. λ. λ. 3 1 (2 1)   =>   λx. λy. λz. x z (y z)

  Keep existing parameter names if possible
        λf. λ. f 1   =>   λf. λx. f x

         Avoid free variable captures
       λ. λ. 2 x 1   =>   λf. λy. f x y

    Mark unused parameters as underscores
           λ. λ. 1   =>   λ_. λx. x

     Rename bound variables if necessary
       λx. λx. 2 1   =>   λx. λy. x y

Formally, the grammar for this language is as follows, where x ranges over alphanumeric strings and i ranges over de Bruijn indices starting at 1:

<mixed-expression> ::= <named-expression> | <nameless-expression>

<named-expression> ::= x | λx. <named-expression> | <named-expression> <named-expression>

<nameless-expression> ::= i | λ. <nameless-expression> | <nameless-expression> <nameless-expression>

This project is split into:

The main files are listed below:

implementation/
├─ src/
│  ├─ expression.rs   Expressions and expression arenas
│  ├─ to_named.rs     Convert expressions to named representation

presentation/
├─ src/
│  ├─ scenes/         Animated slides
│  ├─ project.ts      Motion Canvas project

Watch the Tutorial Video

Watch the tutorial on YouTube

Click the image or watch the tutorial on YouTube to follow along step by step.

About

A tutorial on how to implement variable name generation for expressions having both named and nameless variables.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published