Prolog - Getting syntax error - expected statement

I am starting to learn Prolog, and I am facing a compiler error with my code. I am trying to write code that checks if a family is in poverty if they meet certain conditions. The last line of lines consists of poverty conditions and where I get the error Opertator Expected. I am trying to say that, given the family identifier, if the size of this family is one and the income is less than 11,170, then this family is in poverty. And for a family of size> 8, the poverty level is 38,890 plus 3,960 for each additional family member. How can I fix these errors? family_in_povertymust return trueor false.

family(10392,
       person(tom, fox, born(7, may, 1960), works(cnn, 152000)),
       person(ann, fox, born(19, april, 1961), works(nyu, 65000)),
       % here are the children...
       [person(pat, fox, born(5, october, 1983), unemployed),
        person(jim, fox, born(1, june, 1986), unemployed),
        person(amy, fox, born(17, december, 1990), unemployed)]).

family(38463, 
       person(susan, rothchild, born(13, september, 1972), works(osu, 75000)),
       person(jess, rothchild, born(20, july, 1975), works(nationwide, 123500)),
       % here are the children...
       [person(ace, rothchild, born(2, january, 2010), unemployed)]).

married(FirstName1, LastName1, FirstName2, LastName2) :-
    family(_, person(FirstName1, LastName1, _, _),
           person(FirstName2, LastName2, _, _), _).

married(FirstName1, LastName1, FirstName2, LastName2) :-
    family(_, person(FirstName2, LastName2, _, _),
           person(FirstName1, LastName1, _, _), _).

householdIncome(ID, Income) :-
    family(ID, person(_, _, _, works(_, Income1)),
           person(_, _, _, works(_, Income2)), _),
    Income is Income1 + Income2.

exists(Person) :- family(_, Person, _, _).
exists(Person) :- family(_, _, Person, _).
exists(Person) :- family(_, _, _, Children), member(Person, Children).

householdSize(ID, Size) :-
    family(ID, _, _, Children),
    length(Children, ChildrenCount),
    Size is 2 + ChildrenCount.

:- use_module(library(lists)). % load lists library for sumlist predicate

average(List, Avg) :-
    sumlist(List, Sum),
    length(List, N),
    Avg is Sum / N.

family_in_poverty(FamilyID) :- householdSize(FamilyID, 1), householdIncome(ID, X), X <= 11170.
family_in_poverty(FamilyID) :- householdSize(FamilyID, 2), householdIncome(ID, X), X <= 15130.
........
family_in_poverty(FamilyID) :- householdSize(FamilyID, Y), householdIncome(ID, X), X <= 38890 + (Y - 8)*3960, Y > 8.
+3
source share
4 answers

Prolog is <= , =< .

is, infix is/2, .

+3

, , , .. , :

family_in_poverty(FamilyID) :- 
  householdSize(FamilyID, Y), 
  householdIncome(ID, X), 
  M is 38890 + (Y - 8)*3960,
  X =< M, 
  Y > 8.
+1

:

|: family_in_poverty(FamilyID) :- householdSize(FamilyID, 1), householdIncome(ID, X), X <= 11170.
ERROR: user://1:88:0: Syntax error: Operator expected

, Prolog , current_op/3. , SWI Prolog:

Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.1.3)
Copyright (c) 1990-2011 University of Amsterdam, VU Amsterdam
?- setof(Z,current_op(X,Y,Z),L), write(X-Y-L), nl, fail; true.
1-fx-[$]
200-fy-[+,-,@,\]
200-xfx-[**]
200-xfy-[^]
250-yfx-[?]
400-yfx-[*,/,//,<<,>>,div,mod,rdiv,rem,xor]
500-yfx-[+,-,/\,\/]
600-xfy-[:]
700-xfx-[<,=,=..,=:=,=<,==,=@=,=\=,>,>=,@<,@=<,@>,@>=,\=,\==,\=@=,as,is]
900-fy-[\+]
990-xfx-[:=]
1000-xfy-[,]
1050-xfy-[*->,->]
1100-xfy-[;]
1105-xfy-[|]
1150-fx-[discontiguous,dynamic,initialization,meta_predicate,    
    module_transparent,multifile,public,thread_initialization,thread_local,volatile]
1200-fx-[:-,?-]
1200-xfx-[-->,:-]

, <= defined. Prolog, "term atom...", infix postfix, "Operator Expected" somesuch.

, , , , - . , , = < . ISO. , , .

@= < , . float float. . :

 ?- 1 =< 1.0.
 true
 ?- 1 @=< 1.0.
 false

SWI Prolog: http://www.swi-prolog.org/pldoc/doc_for?object=section%282,%274.26%27,swi%28%27/doc/Manual/arith.html%27%29%29

SWI Prolog Lexical comparison: http://www.swi-prolog.org/pldoc/doc_for?object=section%283,%274.7.1%27,swi%28%27/doc/Manual/compare.html%27% 29% 29

+1
source

A simple rule of thumb in Prolog: an inequality symbol always points to an equal symbol. Examples: = <,> =, @ = <, @> =, etc. This differs from imperative languages, where the symbol of inequality usually appears.

0
source

All Articles