kitten icon indicating copy to clipboard operation
kitten copied to clipboard

Conflicting definitions in REPL should overwrite oldest with newest

Open kchaloux opened this issue 10 years ago • 4 comments

At the moment, it isn't possible to redefine a function in the REPL.

>>> def greet(->) { "Hello!" say }
>>> def greet(->) { "Welcome!" say }
REPL:1:1: error: duplicate definition of sayHi
REPL:2:1: note: also defined here

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:

>>> def greet(->) { "Hello!" say }
>>> greet
Hello!
>>> def greet(->) { "Welcome!" say }
>>> greet
Welcome!

kchaloux avatar Nov 26 '13 14:11 kchaloux

Note to self: program composition should use right-biased union of definition sets, also removing definitions that had referenced redefined definitions.

evincarofautumn avatar Aug 22 '14 11:08 evincarofautumn

A warning "Redefining 'greet'." would be nice.

daira avatar Oct 07 '14 10:10 daira

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.

daira avatar Oct 07 '14 10:10 daira

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.

evincarofautumn avatar Oct 08 '14 21:10 evincarofautumn