Writing a unit test in Elm

Series: Snake in Elm, Elm makes me happy, Elm Basics, Elm Unit Test

I’ve been having fun with Elm programming recently. Elm is a replacement for JavaScript that is pure functional and highly practical.

Here’s how to go from nothing installed at all to writing a unit test that passes, in just over 10 minutes.

The source code is here: github.com/andybalaam/elm-unit-test-example

How to write a programming language – Part 3, The Evaluator

Series: Lexer, Parser, Evaluator.

Finally, we get onto the actual magic of the little language I wrote (Cell) – the evaluator, which takes in syntax trees and finds their real value, in the context of the “environment”: the symbols that are defined around it.

Slides: How to write a programming language – Part 3, The Evaluator

If you want to, you can Support me on Patreon.

How to write a programming language – Part 2, The Parser

Series: Lexer, Parser, Evaluator

My little programming language, Cell (Cell Elementary Learning Language) is designed to be simple. I want to use it to explain how to write a programming language. The parser is only 81 lines long, so hopefully it’s not too hard to understand.

Here’s the explanation of the parser, which is the second part of a compiler or interpreter.

Slides: How to write a programming language – Part 2, The Parser

If you want to, you can Support me on Patreon.

Mousedown events delayed or sluggish on mobile

I am learning about Elm and web apps by writing a little game called sootl.

It’s all SVGs animated with requestAnimationFrame(), and you control your player by clicking or touch the screen.

Everything seemed good on desktop browsers, but on mobile it took an age for the mousedown event to trigger when you touched.

Update: Thanks to @zatnosk on mastodon.social for letting me know there is a better way: 300ms tap delay, gone away. Short answer: add a <meta name="viewport" content="width=device-width"> tag inside your <head> tag.

It turns out that under certain circumstances, some mobile devices wait after the first touch happens to see whether you are going to swipe before they emit the mousedown event.

So, the short answer was to listen for touchstart events as well as mousedown ones. In Elm that looked like this change: e77e055e470c38489657ecaf5edc54a4e5f85782.

How to write a programming language – Part 1, The Lexer

Series: Lexer, Parser, Evaluator

I wrote a little programming language, Cell which is supposed to be simple enough to help explain how a programming language works.

Here’s the explanation of the lexer, which is the first part of a compiler or interpreter.

Slides: How to write a programming language – Part 1, The Lexer

If you want to, you can Support me on Patreon.