One fundamental consideration is whether the user function will override the builtin, the builtin will override the user function, or there will be no conflict.
And perhaps what happens depends on context.
Consider a user defined div(a,b)
that returns a divided by b
while handling the b=0
case.
There are also companion functions: tim(a,b)
, plu(a,b)
, and min(a,b)
.
What should happen with this new definition of min
?
Or functions could invoke actions by specific dogs: rover(a,b)
, fido(a,b)
, and max(a,b)
.
Is it okay to unintentionally redefine a builtin that does something completely different?
Or is it okay to intentionally redefine a builtin to help with debugging or statistical analysis?
I remember running into a problem in C, where I added for(index=0;…
and got compiler errors.
It turned out that previously someone had helpfully put #define index strchr
into a header file, in anticipation of the renaming of the function in the C standard.
And in the other direction, I once wrote a library that intercepts calls to all the section 2 functions that take filenames.
For example, my open(…)
would check the filename to see if it began with "host:" and if so it would establish a connection with the other computer (where accounts with the same userid were guaranteed to be the same person).
Otherwise it would call .open()
, with a leading ".", to get the standard function from libc.
With that, anyone could reload their own programs using my library, and they would instantly get access to the remote filename mechanism, with no changes to their own code.
This leading dot convention was provided by the writers of libc in order both to allow functions to be overridden (e.g. open
could be redefined as ++call_count_open; return .open(args)
), and to prevent new definitions from affecting the libc library, which made all internal calls with the leading dot.
The important point here is that whatever the language does, it needs to be well defined and advertised.
min
using the<
test. E.g I can think of objects wherea>b
anda<b
can both be true. $\endgroup$