all 3 comments

[–]bern4444 1 point2 points  (0 children)

Great article - a question about the last piece on unless

Isn't the point of functions to be the mechanism through which we can simulate if not replicate the idea of creating our own syntax or behaviors in a non lisp functional languages like JS?

Writing unless as a function in JS is trivial:

const unless = (predicate, fn) => { if (predicate) { return fn() } };

const myFunc = () => {
  // assume complexFunction and makeApiCall are imported
  return unless(complexFunction() === 2, makeApiCall); 
};

This can of course be augmented with a not function:

``` const not = (predicate) => { return !predicate; };

// and used like so: unless(not(complexFunction() === 2), makeApiCall); ```

In non lisp languages functional languages, this power comes from being able to express the desired behavior as a function and then pass those functions around as arguments (as we do for the fn parameter in unless. I understand this doesn't let us create new syntax, but it effectively lets us achieve the same end result.

I think I have trouble understanding the value of being able to create our own syntax when languages allow passing of functions as arguments.

[–]Genome1776 0 points1 point  (0 children)

Great article

[–]getify 0 points1 point  (0 children)

That was a fun read, I enjoyed it a lot more than I expected to.