Reputation: 23
I am trying to implement beta reduction, DCG, and lexicon in Prolog.
When I tried to compile, it gave me a syntax error which is the operator @
.
How can I fix it?
beta(Exp,Exp):- atomic(Exp), !. beta(lbd(V,F_body)@Exp,Result):- !, substitute(V,Exp,F_body,Result1), beta(Result1,Result). beta(Exp,Result):- Exp=..ExpList, maplist(beta,ExpList,ResultList), Result=..ResultList. s(SSem) --> np(NPSem), vp(VPSem),{var_replace(NPSem,NPSem1),beta(NPSem1@VPSem,SSem)}. vp(VPSem) --> v(VSem), np(NPSem),{var_replace(VSem,VSem1),beta(VSem1@NPSem,VPSem)}. np(lbd(p,p@john)) --> [john]. np(lbd(p,p@mary)) --> [mary]. v(lbd(s,lbd(x,s@lbd(y,likes(x,y))))) --> [likes].
Upvotes: 0
Views: 72
Reputation: 40778
You can define @
as a binary operator, using, for example:
:- op(500, xfy, @).
If you add this directive at the top of your program, it compiles without errors and warnings, and you can use (@)/2
as an infix operator from then on.
Example:
?- write_canonical(a@b@c). @(a,@(b,c))
I leave choosing the suitable associativity for this operator as an exercise.
Upvotes: 1