-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
order in predicate visibility rules #63
Comments
SWI-Prolog throws an error:
|
On the other hand SWI-Prolog allows this overriding:
But a little annoyingly it gives a warning:
You can switch off the warning, by using use_module/2 with except/1:
Now the warning goes away:
|
Actually I was interested in the behavior of other languages: def foo():
return "a"
def foo():
return "b"
from a import *
from b import *
print(foo())
(if I'm not confused) Python resolves names in LIFO while Ciao does in FIFO. Rather than errors, we show warnings if there are conflicts. Python is silent. SWI gives errors. JavaScript ES6 modules forbid 'import *' to avoid problems. At least for the Ciao toplevel it would make sense to adopt LIFO. |
What does the ISO module standard say? But I agree there are alternatives around, being more C3 linearization You might not see it in the simple example you are dealing with. |
JS ES6, like Logtalk, is the only one in your list above that provides a sensible solution. For Prolog, that means deprecating/killing the |
Thanks @pmoura! I've checked your documentation and everything looks really reasonable. Something that we really miss in Ciao is a Is there any doc/paper that explains it in more detail (e.g., describing other languages with the same decision)? |
As you may have noticed in the documentation, Logtalk's The dangers of directives like the Prolog |
I agree. On the other hand many of those languages are meant only for building large applications, and not for prototyping. Prolog in its original form is really good for prototyping, and in its more modern incarnations (with modules, etc.) it is really great in that it allows traveling a smooth path from prototyping to production-strength code. Ciao in particular provides a lot of things to help this transition. For example you can write:
which exports everything and takes as module name the name of the file. This is as flexible for prototyping as a user file, but it is scoped, i.e., you know all the code for this module is right here, and cannot be loaded in another place (as happens with at least traditional user files). This is very useful for detecting errors (undefined predicates are just an example), so that it actually improves prototyping. Getting back to use_module, being able to 'import everything' is admittedly more dangerous than not allowing it, but also much more flexible, and it is part of this ability to travel the path from prototyping to production-strength. |
Thanks @mherme and @pmoura! Let me summarize:
|
Note that you can always do as in Logtalk: if the |
Note that predicates are never overridden, so the problem may be in the predicate visibility rules.
As @mherme says both
a:foo(X)
andb:foo(X)
work, but module visibility rules in Ciao resolvesfoo(X)
asa:foo(X)
. Perhapsb:foo(X)
would be more natural? Changing it is not trivial but can do it, specially if this is expected in other languages.Originally posted by @jfmc in #61 (comment)
The text was updated successfully, but these errors were encountered: