top | item 37757625

(no title)

dmitry-vsl | 2 years ago

Leporello.js follows a pragmatic functional approach. You can use IO functions and throw exceptions as you typically would, without the need for an IO monad or an Option monad. However, there is one critical limitation – you cannot mutate your data structures. Mutations are not allowed because they would make time-travel debugging impossible. For instance, the following code is forbidden:

  const point = {x: 1, y: 2}
  point.x = 2
And instead you should use this:

  const point = {x: 1, y: 2}
  const another_point = {...point, x : 2}
In Leporello.js, it's vital to avoid mutating data structures; instead, you create new ones. You can watch Rich Hickey's insightful talk [0], where he discusses the advantages of immutability in functional programming.

In many ways, Leporello.js bears a resemblance to Clojure. Clojure served as a source of inspiration for Leporello.js, to the extent that I even contemplated building Leporello.js for Clojure first.

[0] https://www.youtube.com/watch?v=-6BsiVyC1kM

discuss

order

aragonite|2 years ago

The comma operator also seems forbidden. I guess there's never a need to use it in purely function code, but the code can still qualify as pure even allowing its use?

fib(6), fib(7) // scratch:9:6 - unexpected token

dmitry-vsl|2 years ago

Currently, Leporello.js relies on my custom JavaScript parser, which, while functional, is not yet complete and exhibits some quirks. My plan is to replace it with a TypeScript parser, thereby providing full support for both JavaScript and TypeScript within Leporello.js. Additionally, I'm going to develop a VSCode extension, which will offer you all the features available in ts-server.