lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

2014-05-03 0:55 GMT+02:00 Petite Abeille <>:

> What about having the math library as the default metatable for number?

I asked my two old friends Pro and Con to discuss it over a beer.

Pro: It saves you typing `math.`.
Con: Personally I locally cache the few math functions I need.
Pro: And prevent me monkey-patching them? It's what I love to do best.
Con: Well, if you are that fond of monkey-patching, you can always
  do `setmetatable(_ENV,{__index=math}) with also saves you typing
Pro: My _ENV is already monkeypatched, thank you very much.
Con: And I get confused when arguments are the wrong way round.
  As in x:log(10) instead of log(x,10).
Pro: Well, I don't get confused. So there.
Con: Besides, most of the math functions have one argument only.
  So you type empty argument lists all the time.
Pro: Do you seriously mean to tell me you have not yet applied
  Thomas Jericke's patch?
Con: And I really think (10):sqrt() is less readable than sqrt(10).
Pro: Have you ever programmed in Lisp? Come on, a couple of
  pairs of parentheses, not even nested, should not scare you.
Con: I suppose you even want me to start typing `(3.14).pi`.
Pro: Ha, ha! That's the coolest part of the whole idea!
Con: Well, you go ahead and put `debug.setmetatable(0,math)`
  at the top of your modules, but don't involve me.
Pro: I want this to be the default. For everybody.
Con: PUC-Rio will never do it.
Pro: [Rant deleted]