Live data from Hacker News

Why Fennel?

fennel-lang.org

1–10 of 106 posts

Re: Why Fennel?

#2
> Another common criticism of Lua is that it lacks arity checks; that is, if you call a function without enough arguments, it will simply proceed instead of indicating an error. Fennel allows you to write functions that work this way (fn) when it's needed for speed, but it also lets you write functions which check for the arguments they expect using lambda.

I don't understand this; why is this a speed consideration?

Re: Why Fennel?

#3

> Another common criticism of Lua is that it lacks arity checks; that is, if you call a function without enough arguments, it will simply proceed instead of indicating an error. Fennel allows you to write functions that work this way (fn) when it's needed for speed, but it also lets you write functions which check for the arguments they expect using lambda. I don't understand this; why is this a speed consideration?

I think they meant speed of implementation.

Re: Why Fennel?

#4

> Another common criticism of Lua is that it lacks arity checks; that is, if you call a function without enough arguments, it will simply proceed instead of indicating an error. Fennel allows you to write functions that work this way (fn) when it's needed for speed, but it also lets you write functions which check for the arguments they expect using lambda. I don't understand this; why is this a speed consideration?

I'm not an expert, but my understanding is the Lua has a very limited grammar that is specifically designed to be parsed in a single pass. This precluded Lua from performing arity checks on function calls.

Fennel does support arity checks but it comes with a runtime cost since it's implemented as a separate Lua call after being transpiled from Fennel.

Re: Why Fennel?

#5

> Another common criticism of Lua is that it lacks arity checks; that is, if you call a function without enough arguments, it will simply proceed instead of indicating an error. Fennel allows you to write functions that work this way (fn) when it's needed for speed, but it also lets you write functions which check for the arguments they expect using lambda. I don't understand this; why is this a speed consideration?

Arity explanation: https://en.wikipedia.org/wiki/Arity

From the blurb you quoted, it sounds like Lua doesn't check function argument arity natively, and fennel can. This means that fennel applies a runtime check to validate if a function was called with an expected arity, and if not, propagates an error (however Lua does that, I do not know), hence why arity checked functions are not as performant.

Re: Why Fennel?

#6
post #4

> Another common criticism of Lua is that it lacks arity checks; that is, if you call a function without enough arguments, it will simply proceed instead of indicating an error. Fennel allows you to write functions that work this way (fn) when it's needed for speed, but it also lets you write functions which check for the arguments they expect using lambda. I don't understand this; why is this a speed consideration?

I'm not an expert, but my understanding is the Lua has a very limited grammar that is specifically designed to be parsed in a single pass. This precluded Lua from performing arity checks on function calls. Fennel does support arity checks but it comes with a runtime cost since it's implemented as a separate Lua call after being transpiled from Fennel.

[deleted]

Re: Why Fennel?

#8
post #5

> Another common criticism of Lua is that it lacks arity checks; that is, if you call a function without enough arguments, it will simply proceed instead of indicating an error. Fennel allows you to write functions that work this way (fn) when it's needed for speed, but it also lets you write functions which check for the arguments they expect using lambda. I don't understand this; why is this a speed consideration?

Arity explanation: https://en.wikipedia.org/wiki/Arity From the blurb you quoted, it sounds like Lua doesn't check function argument arity natively, and fennel can. This means that fennel applies a runtime check to validate if a function was called with an expected arity, and if not, propagates an error (however Lua does that, I do not know), hence why arity checked functions are not as performant.

So it basically does

  function M(...)
    if select("#",...)>3 then
      error("failed arity check on M()")
    end
  end

Re: Why Fennel?

#9

> Another common criticism of Lua is that it lacks arity checks; that is, if you call a function without enough arguments, it will simply proceed instead of indicating an error. Fennel allows you to write functions that work this way (fn) when it's needed for speed, but it also lets you write functions which check for the arguments they expect using lambda. I don't understand this; why is this a speed consideration?

My memory of this is hazy, in part because I wasn't a C programmer in those days, but ISTR C used to do this too. I think prototypes were added (and required) only by the time ANSI got involved.

Maybe some other OF can confirm/contradict?

Post reply on HN