JohnEarnest/Decker

Inconsistent behaviour of `first` with native functions

Closed this issue · 1 comments

The documentation says

The first of a function is the function's name.

Which is only partially true at the moment. The Lilt interactions below demonstrate what I mean.

The documentation agrees with the behaviour when used on user defined functions: it returns a string with the functions name.

  on my_fun do end
on my_fun do ... end
  typeof my_fun
"function"
  first my_fun
"my_fun"
  (first my_fun) ~ my_fun
0

But for native functions (eg. exit) it behaves as the identity operation:

  exit
on native x do ... end
  typeof exit
"function"
  first exit
on native x do ... end
  (first exit) ~ exit
1

I would argue that for the sake of consistency first used on any function should always return a string value. For user defined ones this would be the function's name. For native functions this could be the proper name (ie. "exit" for exit and "read" for read etc.) or just a generic "native". I think the proper names would be a nice-to-have but returning some generic string value would be fine as well.

Good catch.

"Proper" names (and arglists for keys) would require some extra plumbing, but I entirely agree that the result should at least be a string for consistency.