Open kchaloux opened 10 years ago
Note to self: program composition should use right-biased union of definition sets, also removing definitions that had referenced redefined definitions.
A warning "Redefining 'greet'." would be nice.
BTW, what happens if a previous definition referred to the redefined function and no longer type checks with the new definition?
Oh, you said it should be removed (whether or not it would still typecheck). Hmm, that could end up removing an unexpectedly large set of definitions, requiring the user to have to retype or repaste them.
We could go more Forthlike, having a dictionary you insert into with def
. So if you redefine f
, then old-f
will be hidden, but definitions pointing to old-f
will continue to work. That ordering restriction can be relaxed in source files. We could add a :redef
command for the case when you have some definition g
that refers to old-f
, which you want to patch to call new-f
instead. This would also retypecheck, of course, and not commit the patch to the dictionary if checking fails.
At the moment, it isn't possible to redefine a function in the REPL.
While this is correct behavior when compiling or running via interpreter, most REPLs allow redefinition of functions in this case. The older definition should be cleared and replaced, so the resulting input should behave as follows: