Program Error 1010 Prolog - visual-prolog

PREDICATES
nondeterm male(symbol)
nondeterm female(symbol)
nondeterm wife(symbol,symbol)
nondeterm mother(symbol,symbol)
nondeterm father(symbol,symbol)
nondeterm brother(symbol,symbol)
nondeterm sister(symbol,symbol)
nondeterm sonInLaw(symbol,symbol)
nondeterm brotherInLaw(symbol,symbol)
nondeterm uncle(symbol,symbol)
nondeterm sibling(symbol,symbol)
nondeterm grandson(symbol,symbol)
nondeterm grandfather(symbol,symbol)
Clauses
male(mark).
male(ahmed).
male(zeeshan).
male(summer).
female(sara).
female(sana).
wife(sara,mark).
wife(sana,ahmed).
mother(X,Y):-female(X),father(Z,Y),wife(X,Z),X<>Y.
mother(sara,sana).
father(X,Y):-male(X),mother(Z,Y),wife(Z,X),X<>Y.
brother(X,Y):-male(X),father(Z,X),father(Z,Y),X<>Y.
sister(X,Y):-female(X),father(Z,X),father(Z,Y),X<>Y.
sonInLaw(X,Y):-male(X),father(Y,Z),wife(Z,X) ; male(X),mother(Y,Z),wife(Z,X),X<>Y.
brotherInLaw(X,Y):-male(X),sister(Z,X),wife(Z,Y).
sibling(X,Y):-brother(X,Y);sister(X,Y),X<>Y.
uncle(X,Y):- sibling(X,Z),father(Z,Y),X<>Y.
grandfather(X,Y):- father(X,Z), father(Z,Y);father(X,Z), mother(Z,Y),X<>Y.
grandson(X,Y):- father(Z,X), father(Y,Z);father(Z,X), mother(Y,Z),X<>Y.
Goal
uncle(mark,sana).
My Prolog is giving me Error 1010.

This should work
In WIP7 this works
class predicates
male:(symbol) procedure (x).
female:(symbol) procedure (x).
wife:(symbol,symbol) procedure (x,y).
mother:(symbol,symbol) procedure (x,y).
father:(symbol,symbol) procedure (x,y).
brother:(symbol,symbol) procedure (x,y).
sister:(symbol,symbol) procedure (x,y).
sonInLaw:(symbol,symbol) procedure (x,y).
brotherInLaw:(symbol,symbol) procedure (x,y).
uncle:(symbol,symbol) procedure (x,y).
sibling:(symbol,symbol) procedure (x,y).
grandson:(symbol,symbol) procedure (x,y).
grandfather:(symbol,symbol) procedure (x,y).
clauses
male(mark).
male(ahmed).
male(zeeshan).
male(summer).
female(sara).
female(sana).
wife(sara,mark).
wife(sana,ahmed).
mother(X,Y):-female(X),father(Z,Y),wife(X,Z),X<>Y.
mother(sara,sana).
father(X,Y):-male(X),mother(Z,Y),wife(Z,X),X<>Y.
brother(X,Y):-male(X),father(Z,X),father(Z,Y),X<>Y.
sister(X,Y):-female(X),father(Z,X),father(Z,Y),X<>Y.
sonInLaw(X,Y):-male(X),father(Y,Z),wife(Z,X);male(X),mother(Y,Z), wife(Z,X),X<>Y.
brotherInLaw(X,Y):-male(X),sister(Z,X),wife(Z,Y).
sibling(X,Y):-brother(X,Y);sister(X,Y),X<>Y.
uncle(X,Y):- sibling(X,Z),father(Z,Y),X<>Y.
grandfather(X,Y):-father(X,Z),father(Z,Y);father(X,Z),mother(Z,Y), X<>Y.
grandson(X,Y):- father(Z,X), father(Y,Z);father(Z,X), mother(Y,Z),X<>Y.
clauses
run():-
console::init(),
uncle(mark,sana),
programControl::sleep(1000).
I think that with VIP 5.1 you can put
check_determ

Related

Eiffel: how do I get the type of a particular operand of a procedure

As I can see into the debugger it's possible to get the operands, and name of procedure, is there a way to get it?
PROCEDURE=>operands returns a detachable that seems return the operands only when they have been setted into the agent
Do I have pass through any REFLECTOR class because the PROCEDURE class doesn't have this function and in this case why?
Seems that estudio has access to informations as ROUTINE client don't have, why is he a privileged one? is he cheating?
The following code demonstrates how to retrieve information about open argument types of a routine object:
p: ROUTINE -- Routine object.
t: TYPE [detachable ANY] -- Current open argument type.
do
p := agent (i: INTEGER; s: STRING)
do
end
across
1 |..| p.open_count as i
loop
t := p.generating_type.generic_parameter_type (1).generic_parameter_type (i.item)
io.put_string (t.name)
io.put_new_line
end
For me, the code above prints
INTEGER_32
!STRING_8
Comments:
p.open_count gives the total number of open arguments.
p.generating_type retrieves the type of the routine object.
p.generating_type.generic_parameter_type (1) retrieves the type of the open arguments tuple object.
The final call to generating_type retrieves the type of the open argument with index i.item.

value of callee and caller when using call by references

I encountered a confusion , when i pass a variable x to variable y by reference then both x and y should now point to same location, but the output that i am getting is not same.
Full detail discussion is here: http://gateoverflow.in/94182/programming-output
I have tried my best to explain the stuff to user but i am still unable to convience him fully, maybe i am lacking some concept.
rough code sample:
var b : int;
procedure M (var a, int)
begin
a= a*a;
print(a);
end;
procedure N
begin
b= b+1;
M(b);
end;
begin
b=12;
N;
print(b);
end;
I assume that as in question it is given that variables are static , so the value of a b should not change from 13 , but the value of a should be 13*13=169 , but my reasoning is counter to what call by reference is about.
pascal code from unauthorized book, please throw some insights.
I had to review scoping terminology. I had myself confused between static and dynamic scoping. Static scoping is used in all modern programming languages. I conclude that both a and b should have a value of 169 at the respective print statements.

From VBA to Delphi conversion (Optional arguments issue)

At the moment I'm converting a project written in VBA to Delphi and have stumbled upon a problem with converting some Subs with Optional arguments.
Say, there is a Sub declaration (just an example, actual Subs have up to 10 optional parameters):
Sub SetMark
(x0 As Double, y0 As Double,
Optional TextOffset As Integer =5,
Optional TextBefore As String = "",
Optional Text As String = "",
Optional TextAfter As String = "mm",
Optional Color As String = "FFFFFF",
Optional ArrowPresent As Boolean = True)
That Sub subsequently can be called like this:
Call SetMark (15, 100,,,"135")
Call SetMark (100, 100, 8,, "My text here..", "")
'a lot of calls here
The Optional arguments are very flexible here, you can omit any of them, and you can assign a value to any of them as well. Unlike in Delphi.
Procedure SetMark
(x0: real; y0: real,
TextOffset: Integer =5;
TextBefore: ShortString = '';
Text: ShortString = '';
TextAfter: ShortString = 'mm';
Color: ShortString = 'FFFFFF';
ArrowPresent: Boolean = True);
It seems you cannot just make a copy of VBA call:
SetMark (15, 100,,,'135');// error here
So, the question is: is there any way to convert that Subs to Delphi procedures keeping the same flexibility in parameters?
My first idea was to use default parameters, but it doesn't work.
As for now it seems in Delphi I will have to pass all the parameters in the list with their values directly but that means a lot of work for reviewing and proper porting of VBA calls.
Any ideas?
Is there any way to convert the VBA subroutines to Delphi procedures, still keeping the same flexibility in parameters?
There is no way to achieve that – that flexibility to omit parameters, other than at the end of the list, simply does not exist.
For methods of automation objects, you can use named parameters, as described here: Named/optional parameters in Delphi? However, I very much recommend that you don't implement your classes as automation objects just to get that functionality.
Whenever you switch between languages, you will find differences that are inconvenient. That is inevitable. The best approach is to try to find the best way to solve the problem in the new language, rather than trying to force idioms from the old language into the new language.
In this case you might want to use overloaded functions or parameter objects as ways to alleviate this inconvenience.
Just to expand on the idea of refactoring to use a parameter object, you could declare a record like:
TSetMarkParams = record
x0 : double;
y0 : double;
TextOffset : integer;
TextBefore : string;
Text : string;
TextAfter : string;
Color : string;
ArrowPresent : boolean;
constructor Create(Ax0, Ay0 : double);
end;
And implement the constructor to populate default values as :
constructor TSetMarkParams.Create(Ax0, Ay0 : double);
begin
x0 := Ax0;
y0 := Ay0;
TextOffset := 5;
TextBefore := '';
Text := '';
TextAfter := 'mm';
Color := 'FFFFFF';
AllowPresent := true;
end;
Your procedure would then have signature :
procedure SetMark(ASetMarkParams : TSetMarkParams);
Which you could then, using your example of SetMark (15, 100,,,'135'); call as :
var
LSetMarkParams : TSetMarkParams
begin
LSetMarkParams := TSetMarkParams.Create(15, 100);
LSetMarkParams.Text := '135';
SetMark(LSetMarkParams);
end;
As collateral benefit, the above is much more readable as it saves you from going blind trying to count commas when returning to debug a troublesome method call.

Str in XE7 generates strange warning

Why does this code:
w: word;
s: String;
begin
str(w, s);
generate this warning in XE7:
[dcc32 Warning] Unit1.pas(76): W1057 Implicit string cast from 'ShortString' to 'string'
Tom
System.Str is an intrinsic function that dates from a byegone era. The documentation says this:
procedure Str(const X [: Width [:Decimals]]; var S: String);
....
Notes: However, on using this procedure, the compiler may issue a warning: W1057 Implicit string cast from '%s' to '%s' (Delphi).
If a string with a predefined minimum length is not needed, try using the IntToStr function instead.
Since this is an intrinsic, there is likely something extra going on. Behind the scenes, the intrinsic function is implemented by a call to an RTL support function that yields a ShortString. Compiler magic then turns that into a string. And warns you of the implicit conversion. The compiler magic transforms
Str(w, s);
into
s := _Str0Long(w);
Where _Str0Long is:
function _Str0Long(val: Longint): _ShortStr;
begin
Result := _StrLong(val, 0);
end;
Since _Str0Long returns a ShortString then the compiler has to generate code to perform the implicit converstion from ShortString to string when it assigns to your variable s. And of course it's then natural that you see W1057.
The bottom line is that Str only exists to retain compatibility with legacy Pascal ShortString code. New code should not be calling Str. You should do what the documentation says and call IntToStr:
s := IntToStr(w);
Or perhaps:
s := w.ToString;

Active Unions in Static Scope

Suppose i want to know what unions(referencing environment) are active in the point marked with (*), how do i acknowledge that ? Which unions are in fact active ?
procedure P(A,B ; real)
X: real
procedure Q(B,C : real)
y : real
...
procedure R(A,C : real)
Z:real
........ --(*)
It's basic nesting basically. But you don't specify the full blockstructure (with begin..end pairs) to fully fixate the structure.
Assuming from indentation that the begin end; block of P is at the end, and of Q and R is directly after resp. the y and z declarations, then in Q: Q is searched first, then P, then the scope above P (mainprogram/unit or another procedure), in R R, P,unit etc.

Resources