Re: More extensive (variable) style checking

Nicos Angelopoulos (Univ of York) <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <20130803114433.6d6ed549@naga>
Dear Jan, all,

These all seem very welcome changes and infrastructure.
Just a couple of points:

On Fri, 2 Aug 2013 17:41:02 +0200
Jan Wielemaker <[email protected]> wrote:

> The next one is less clear. A user complained to often initialise
> variables in one branch, forgetting to do so in another one. The check
> verifies that variables introduced in a disjunction and used after it
> are introduced in both branches. Thus,
> 
> 	t :-
> 	    (   hello(X)
> 	    ;   world
> 	    ),
> 	    writeln(X).
> 
> is considered something to warn about. This gives some warnings on the
> SWI-Prolog libraries. Most of them concern indeed ugly code, but not
> errornous. The question is whether this a meaningful warning? And, if

	it probably ought to be controlled by a flag. 
	the default value is debatable. probably false as to not alert inexperienced users?
   
> so, how one can avoid the warning after validating that the code is
> correct? One option for the latter is
> 
> 	t :-
> 	    (   hello(X)
> 	    ;   world,
> 		X=_
> 	    ),
> 	    writeln(X).
> 
> Now, only the compiler will complain that X=_ is pointless, which in
> itself is good because it will replace it with the VM instruction TRUE.
> The open question is how to silence this though ...
> 
	wouldn't a solution be to have a special predicate that does 
	nothing but saying that X is safe to be left out of the branch ?
		{non_}singleton(X)
		var_safe(X)
		true(X)
 
       It Is not ideal, but better than X=_ I think.

	(as mentioned elsewhere in this thread)
	How would your above example/system deal with the following ?

	p(Opts,X) :-
		( memberchk(X,Opts) -> true; X = default ).


Regards,


Nicos Angelopoulos
---
http://bioinformatics.nki.nl/~n.angelopoulos
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.