> 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?
Why Fennel?
21–30 of 106 posts
Re: Why Fennel?
#22Earlier 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).
This was also used to implement variadic functions like printf before varargs, see https://retrocomputing.stackexchange.com/a/20517
Re: Why Fennel?
#23Earlier 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).
Re: Why Fennel?
#24Earlier 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).
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?
#25Re: 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?
Unfortunately, I can't find that blog post so take my words with a grain of salt.
Re: Why Fennel?
#27Earlier 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
Re: Why Fennel?
#28Now 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…
A boon is a good thing. I think you meant a problem?
Re: Why Fennel?
#29I moved my Neovim config to fennel and haven't look back. https://github.com/Grazfather/dotfiles/blob/master/nvim/fnl/...
Thanks for sharing your setup, I’ll be stealing some ideas.
Re: Why Fennel?
#30Earlier 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).