Live data from Hacker News

Why Fennel?

fennel-lang.org

21–30 of 106 posts

Re: Why Fennel?

#21
post #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?

Fun fact: in C, if you have a signature like “int foo()”, it means any number of arguments can be passed (vs “int foo(void)” which means no args).

Re: Why Fennel?

#22
post #21
post #9

Earlier quoted context omitted.

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?

Fun fact: in C, if you have a signature like “int foo()”, it means any number of arguments can be passed (vs “int foo(void)” which means no args).

Good reference for that: https://jameshfisher.com/2016/11/27/c-k-and-r/

This was also used to implement variadic functions like printf before varargs, see https://retrocomputing.stackexchange.com/a/20517

Re: Why Fennel?

#23
post #21
post #9

Earlier quoted context omitted.

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?

Fun fact: in C, if you have a signature like “int foo()”, it means any number of arguments can be passed (vs “int foo(void)” which means no args).

And there is no way for the callee to check the nr of passed args, unlike in Lua.

Re: Why Fennel?

#24
post #21
post #9

Earlier quoted context omitted.

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?

Fun fact: in C, if you have a signature like “int foo()”, it means any number of arguments can be passed (vs “int foo(void)” which means no args).

that's ... (amazing|C for ya)

  int foo() {
      return 0;
  }
  int main(int argc, char* argv[]) {
      return foo("alpha", "beta", 1);
  }
  $ gcc-13 -Wall -Werror -o foo foo.c
  # oh, sads

  $ clang -o foo ./foo.c
  ./foo.c:5:34: warning: too many arguments in call to 'foo'
      return foo("alpha", "beta", 1);
             ~~~                   ^
  ./foo.c:5:15: warning: passing arguments to 'foo' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
      return foo("alpha", "beta", 1);
                ^
  2 warnings generated.

Re: Why Fennel?

#25
Now I like lua and think single pass is the way to go for interpreted, since you don't have the disadvantage of a slow compile time no matter how big your codebase gets, BUT its not great to write in. some things are (apparently) not possible, which means the only solution is to transpile into it, which has led to some good languages like moonscript[0], and the dynamic nature is a boon as your codebase grows, which has led to teal[1] which offers static type checking.

[0]: https://moonscript.org/

[1]: https://github.com/teal-language/tl

Re: Why Fennel?

#26

> 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?

IIRC (and I remember it quite vaguely from some random blog post on the Internet) the Lua implementation uses some trick that greatly speeds up setting up and tearing down activation frames (and has also something to do with the ability to easily cross-call into C back to Lua again?), but it hinges on that argument-passing/result-returning semantics being "use nils for missing stuff, throw away the extras" so e.g. Python can't use it to speed up its implementation of function calls.

Unfortunately, I can't find that blog post so take my words with a grain of salt.

Re: Why Fennel?

#27
post #8
post #5

Earlier quoted context omitted.

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

pretty much, yeah

Re: Why Fennel?

#28
post #25

Now I like lua and think single pass is the way to go for interpreted, since you don't have the disadvantage of a slow compile time no matter how big your codebase gets, BUT its not great to write in. some things are (apparently) not possible, which means the only solution is to transpile into it, which has led to some good languages like moonscript[0], and the dynamic nature is a boon as your codebase grows, which h…

> is a boon

A boon is a good thing. I think you meant a problem?

Re: Why Fennel?

#29

I moved my Neovim config to fennel and haven't look back. https://github.com/Grazfather/dotfiles/blob/master/nvim/fnl/...

I’ve been thinking about doing this, but then reminding myself that this is not a wise use of my time lol. However, this looks pretty nice. I might have to do it.

Thanks for sharing your setup, I’ll be stealing some ideas.

Re: Why Fennel?

#30
post #21
post #9

Earlier quoted context omitted.

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?

Fun fact: in C, if you have a signature like “int foo()”, it means any number of arguments can be passed (vs “int foo(void)” which means no args).

[deleted]
Post reply on HN