You are browsing as a guest. Sign up (or log in) to start making projects!

6h 54m 18s logged

So my idea for this project is that it’s a JavaScript puzzle site which forces you to use pure functional programming, which means that you aren’t allowed to use let or anything else with mutable state.

Basically, pure functional programming says that you should never ever reassign variables after you declare them. Ever. Because you can’t reassign variables, you also can’t increment counters, which means that it’s impossible to use for loops. The same logic applies to while loops, and to a few other things. These extremely restrictive self-imposed limitations force you to do things the functional programming way, which involves lambda calculus, recursive functions, currying, etc.

I think that this project will have four main parts. I’ve been working on it for about 7 hours and I’ve made some good progress, but there’s still a lot to do.

  1. Running the user’s code and reading the result. I can just wrap quickjs-emscripten and remove a few built-in methods like Math.random() that are considered “impure” by functional programming because they’re non-deterministic.
  2. Linting the user’s code to check if it uses any banned syntax like let. I can use acornjs to parse the code into an AST, then applying a bunch of custom rules to it.
  3. Allowing the user to write their code. The conventional choice would be to use Monaco or CodeMirror, but they’re extremely heavy and I don’t like VSCode anyways, so I’m going with Prism code editor, which is much lighter and in my opinion nicer.
  4. Having puzzles for the user to complete. Each puzzle should have a test function that can check if the code logic is correct, and also should have some initial code that has correct logic but fails the linting because it uses let and whatnot.

Right now I have minimal versions of parts 1, 2, and 3. They do work (mostly), but they’re missing features and don’t integrate well with each other.

0
4

Comments 1

@zach

I really like your concept for this! So cool