Discussion:
No permission to modify static procedure
Lumj
2014-01-19 15:05:01 UTC
Permalink
Is it possible to write a module in which there's a predicate write/1?
When I try to do this, I got the 'No permission to modify static procedure' error. What I intend to do is to have a write/1 in my module and the system:write/1 remain where it is.
Module file attached:
:-module(m,[write/1]).
write(x).
Am I missing anything?
-------------- next part --------------
HTML attachment scrubbed and removed
Jan Wielemaker
2014-01-19 16:33:46 UTC
Permalink
Post by Lumj
Is it possible to write a module in which there's a predicate write/1?
When I try to do this, I got the 'No permission to modify static procedure' error. What I intend to do is to have a write/1 in my module and the system:write/1 remain where it is.
:-module(m,[write/1]).
write(x).
Am I missing anything?
ISO doesn't allow for redefining system predicates. There is a good
reason for it: it
would not be able to perform any kind of optimization to ISO predicates.
For example,
several predicates are mapped directly to virtual machine instructions.
If the
definition was not fixed, this would be impossible.

There is a directive redefine_system_predicate/1 that overrules this (if
it still works).
That was mostly added to redefine stuff to gain compatibility to older
versions or
other systems. I doubt you can export such modified versions though.
If you do not
use redefine_system_predicate/1 in the receiving module, you get the
same check and
if you do, I think you'll also running into trouble. At least, there is
no guarantee
for the future.

For short, I think you are on the wrong track for healthy usage of
Prolog. What are you
after?

Cheers --- Jan
Lumj
2014-01-20 01:44:29 UTC
Permalink
Ok..maybe I didn't address my question clearly enough.

I have no intention to redefine the built-in predicate, I just happen to pick 'write' as the name for the display predicate for my custom objects, and expect the system to resolve foo:write(foo). If I am not allowed to use the name used by built-in predicate, I have to name it something like 'foo_write'. Is there any reason for the system not to allow this name-hiding?



------------------ Original ------------------
From: "Jan Wielemaker";<***@vu.nl>;
Date: Mon, Jan 20, 2014 00:33 AM
To: "Lumj"<***@lumjsoft.com>; "SWI-Prolog"<swi-***@lists.iai.uni-bonn.de>;

Subject: Re: [SWIPL] No permission to modify static procedure
Post by Lumj
Is it possible to write a module in which there's a predicate write/1?
When I try to do this, I got the 'No permission to modify static procedure' error. What I intend to do is to have a write/1 in my module and the system:write/1 remain where it is.
:-module(m,[write/1]).
write(x).
Am I missing anything?
ISO doesn't allow for redefining system predicates. There is a good
reason for it: it
would not be able to perform any kind of optimization to ISO predicates.
For example,
several predicates are mapped directly to virtual machine instructions.
If the
definition was not fixed, this would be impossible.

There is a directive redefine_system_predicate/1 that overrules this (if
it still works).
That was mostly added to redefine stuff to gain compatibility to older
versions or
other systems. I doubt you can export such modified versions though.
If you do not
use redefine_system_predicate/1 in the receiving module, you get the
same check and
if you do, I think you'll also running into trouble. At least, there is
no guarantee
for the future.

For short, I think you are on the wrong track for healthy usage of
Prolog. What are you
after?

Cheers --- Jan
-------------- next part --------------
HTML attachment scrubbed and removed
Paulo Moura
2014-01-20 02:15:01 UTC
Permalink
Post by Lumj
Ok..maybe I didn't address my question clearly enough.
I have no intention to redefine the built-in predicate, I just happen to pick 'write' as the name for the display predicate for my custom objects, and expect the system to resolve foo:write(foo). If I am not allowed to use the name used by built-in predicate, I have to name it something like 'foo_write'. Is there any reason for the system not to allow this name-hiding?
One reason may be that allowing redefinition of built-in predicates may make single pass compilation more difficult or impractical as the redefinition may follow its use.

But a lingering problem here is that you can pick a nice predicate name that's not a built-in predicate today but that may become a built-in predicate tomorrow. For example, looking only to the ISO standard, recent revisions add a few more built-in predicates (admittedly, most of them being de facto standard predicates). This means that the code the compiles fine today may fail to compile tomorrow. It's worse if you're writing portable code as the set of built-in predicates varies with Prolog compilers (this, btw, is one of the reasons why Logtalk supports redefinition of built-in predicates within objects and categories). That said, code that's not maintained eventually rots. In the end, it's all about design decisions.

Cheers,

Paulo

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:***@logtalk.org>
Web: <http://logtalk.org/>
-----------------------------------------------------------------
Lumj
2014-01-20 09:37:15 UTC
Permalink
Fragile module. :(

------------------ Original ------------------
From: "Paulo Moura";<***@logtalk.org>;
Date: Mon, Jan 20, 2014 10:15 AM
To: "SWI-Prolog"<swi-***@lists.iai.uni-bonn.de>;

Subject: Re: [SWIPL] No permission to modify static procedure
Post by Lumj
Ok..maybe I didn't address my question clearly enough.
I have no intention to redefine the built-in predicate, I just happen to pick 'write' as the name for the display predicate for my custom objects, and expect the system to resolve foo:write(foo). If I am not allowed to use the name used by built-in predicate, I have to name it something like 'foo_write'. Is there any reason for the system not to allow this name-hiding?
One reason may be that allowing redefinition of built-in predicates may make single pass compilation more difficult or impractical as the redefinition may follow its use.

But a lingering problem here is that you can pick a nice predicate name that's not a built-in predicate today but that may become a built-in predicate tomorrow. For example, looking only to the ISO standard, recent revisions add a few more built-in predicates (admittedly, most of them being de facto standard predicates). This means that the code the compiles fine today may fail to compile tomorrow. It's worse if you're writing portable code as the set of built-in predicates varies with Prolog compilers (this, btw, is one of the reasons why Logtalk supports redefinition of built-in predicates within objects and categories). That said, code that's not maintained eventually rots. In the end, it's all about design decisions.

Cheers,

Paulo

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:***@logtalk.org>
Web: <http://logtalk.org/>
-----------------------------------------------------------------




_______________________________________________
SWI-Prolog mailing list
SWI-***@lists.iai.uni-bonn.de
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
-------------- next part --------------
HTML attachment scrubbed and removed

Richard A. O'Keefe
2014-01-20 02:26:18 UTC
Permalink
Post by Lumj
I have no intention to redefine the built-in predicate, I just happen to pick 'write' as the name for the display predicate for my custom objects, and expect the system to resolve foo:write(foo). If I am not allowed to use the name used by built-in predicate, I have to name it something like 'foo_write'.
You could use some other language. I've been known to use 'skribu'
(Esperanto for 'write!'). In English, possibilities include
'output', 'describe', 'report', or my big favourite, 'show'.
Post by Lumj
Is there any reason for the system not to allow this name-hiding?
The traditional practice with Prolog modules is *NOT* to use a
module prefix. This means that if your module can define write/1
and export it, it can be *called* as write(foo) in other modules.
That doesn't sound like a good idea.

In fact, for people trying to read Prolog code, it's really
helpful if the names of the ISO predicates are always used for
their ISO semantics; it would be just too confusing if
put_char(X) might delete a file...

If you want to think in terms of "objects", then you should
probably be using LogTalk, where you can do what you want to.
Lumj
2014-01-20 03:12:35 UTC
Permalink
"The traditional practice with Prolog modules is *NOT* to use a module prefix"
Ok this explains. Thanks.

------------------ Original ------------------
From: "Richard A. O'Keefe";<***@cs.otago.ac.nz>;
Date: Mon, Jan 20, 2014 10:26 AM
To: "Lumj"<***@lumjsoft.com>;
Cc: "Jan Wielemaker"<***@vu.nl>; "Paulo Moura"<***@logtalk.org>; "SWI-Prolog"<swi-***@lists.iai.uni-bonn.de>;
Subject: Re: [SWIPL] No permission to modify static procedure
Post by Lumj
I have no intention to redefine the built-in predicate, I just happen to pick 'write' as the name for the display predicate for my custom objects, and expect the system to resolve foo:write(foo). If I am not allowed to use the name used by built-in predicate, I have to name it something like 'foo_write'.
You could use some other language. I've been known to use 'skribu' (Esperanto for 'write!'). In English, possibilities include 'output', 'describe', 'report', or my big favourite, 'show'.
Post by Lumj
Is there any reason for the system not to allow this name-hiding?
The traditional practice with Prolog modules is *NOT* to use a module prefix. This means that if your module can define write/1 and export it, it can be *called* as write(foo) in other modules. That doesn't sound like a good idea.

In fact, for people trying to read Prolog code, it's really
helpful if the names of the ISO predicates are always used for their ISO semantics; it would be just too confusing if
put_char(X) might delete a file...

If you want to think in terms of "objects", then you should probably be using LogTalk, where you can do what you want to.
-------------- next part --------------
HTML attachment scrubbed and removed
Paulo Moura
2014-01-19 19:21:56 UTC
Permalink
This post might be inappropriate. Click to display it.
Loading...