Game
Learn Functional Programming
4 years ago

Article: Visualizing Lambda Expressions in LFP


LFP is meant to be a visual simulation of functional programming for educational purposes.

Visual simulations help students observe a system and build an understanding for how it behaves from those visualizations. These visualizations (or Virtual Manipulative in pretentious person speak) are often used in math and computer science education.

Lambdas in the Wild

Lisp is related to lambda calculus. Lambda calculus has these funny looking lambda expressions where you have a variable and then some expression that may contain that variable. It might be written like this, where e is some expression and x is the variable.

visualize_lambdas_2.png

The variable in a lambda expression is replaced by the input expression by “applying” it, which is just putting an expression in front of it. This screenshot from this book (page 33 in PDF) shows an example of application (with fancy math words)

image.png

Other programming languages have things like this. For example, the fancy expression above would look like this in Python.

		
			lambda x: e
		
	

Or like this in Lisp.

		
			(lambda (x) e)
		
	

 Adding Lambdas to LFP

In LFP, I wanted to include lambda expressions with syntax similar to formal notation and programming language notation.

If a player learns the syntax of LFP, then they would (hopefully) have an easier time understanding the concept and syntax in other contexts. This is known as Transfer of Learning or Analogy based Learning.

The expression above might look like this in LFP, if e was (+ 3 x)

visualize_lambdas_1.png

Other expressions (or “tokens” in LFP terminology) can be applied just like it would be applied in formal notation and Lisp-like languages.

image.png

This is analogous to the formal notation,

image.png

Or in a Lisp like programming language

((lambda (x) (+ 3 x)) 2)

 

Evaluating Lambdas in LFP

When evaluating a list with a lambda, the list starting with a lambda token will become a lambda function that represents the function defined by that lambda expression.

When the function is called, it “applies” the input token to where the variable tokens would be.

visuals_devlog_show_applications.png

This behavior is analogous to formal notation and what (I think) happens in programming languages using lambda, only it shows every step from definition, application, and final evaluation.

Takeaway 

Ideally, plaing LFP and learning the system will then give you an easier time when learning about these same concepts in other programming languages.

This idea is supported by Transfer of Learning or Analogy based Learning used in math education and other subjects.

I hope this post was interesting and showed you some of my thinking around LFP’s design.



0 comments

Loading...

Next up

Did you know that today is #InternationalJazzDay? 🎷😎

No? 😯 Well, we couldn't pass up this date!

And what better to celebrate this day than #Pecaminosa #OST? 🎷

Let us know what you think about it and have a great weekend!

Here's a peaceful little forest scene for this #screenshotsaturday, from the beginning of the game.

I have added rewards for quests so that villagers can give you something in return for your hard work helping them. 🥳

I want to know - what's your favourite quest reward?

The whole squad is here!

Interested? Follow me!

Hi everyone! I started to create some environment props for my new video game, here is a cozy house in the forest. I'm planning to switch from Unity to Unreal... Let's see what new challenges I have to face. Made in Blender and Substance Painter.

I worked so hard to get all four of them to the end safely, but then...

Who's is this little cutey👸 here? Thanks🙏 for a gorgeous fanart @WheNa! Feel free to share your arts, screenshots, or videos with #playzelter or #zelter hashtags! #pixelart #animating #unity3d #animated #indiegames #unrealengine #animate #conceptart

Path of Kami, running around the shrine area

OK, this starts to be too tricky puzzle already :D

#platformer #indiegame #puzzle

Our menu, gathered a huge feedback and positive comments among foreign audience, what you say? Game Steam: https://store.steampowered.com/app/1543090/LiBER/