Code Comments
Programming Forum and web based access to our favorite programming groups.Hello, there are two elements of Prolog syntax that I do not understand: a) =.. and [] What are "=.." and "[]" used for here ? vp(vt,VS,Form) :- mappend(V,SS,VS), word(vt,V,S,Form), member(Type,S), Type =.. [TYPE], Cat =.. [TYPE,SS], Cat. 2) Var-Var What does "G0-G" (and others) mean in this example ? vp(Vform,G0-G) --> v(obj_equi,Vform), np(G0-G1), vp(inf,G1-G). Thanks for your help !
Post Follow-up to this messagemyname wrote: > Hello, > > there are two elements of Prolog syntax that I do not understand: > > a) =.. and [] > > What are "=.." and "[]" used for here ? > > vp(vt,VS,Form) :- > mappend(V,SS,VS), > word(vt,V,S,Form), > member(Type,S), > Type =.. [TYPE], > Cat =.. [TYPE,SS], > Cat. > > 2) Var-Var > > What does "G0-G" (and others) mean in this example ? > > vp(Vform,G0-G) --> > v(obj_equi,Vform), > np(G0-G1), > vp(inf,G1-G). > > Thanks for your help ! > > *) [] is the notation for lists, so [TYPE] is a list of length one containing only the variable TYPE. the predicate append relates two lists to the concatenation of those, so the query (copy & paste from swi prompt): ?- append([a,b],X,[a,b,c]). finds X as the list containing only c: X = [c] ; *) =.. decomposes a term into a list with its first element the predicate name followed by the predicate's arguments. you can also try this on the commandline: ?- pred(p1,p2,X,p4) =.. List. List = [pred, p1, p2, X, p4] ; it also works in the reverse way: ?- P =.. [pred, p1, p2, X, p4] . P = pred(p1, p2, X, p4) ; in your example TYPE contains the predicate name to be called, so Cat becomes the predicate starting with TYPE and a single parameter SS, in the last line "Cat.", the just built predicate is called. *) - is an infix defined function symbol and originally used to build arithmetic expressions (calculation takes place via the "is" predicate). if you don't use "is", you can build expressions of any content: ?- X=5-(3+1). X = 5- (3+1) ; works as well as ?- X = a - b. X = a-b ; so writing G0-G could also be written as pair(G0, G) to denote a pair of variables, but the - is often used to make a predicate more readable (by removing brackets). i hope it's clearer now, but i'm a student and far behind the regular posters here, so corrections and feedback are always welcome :) greetings Martin
Post Follow-up to this message"Martin Riener" <martin.riener@gmail.com> a écrit dans le message de news: 47e6d280$0$11610$3b214f66@tunews.univie.ac.at...¨ [snip] Perfect ! Thanks a lot !
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.