Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, In my programm the user can call a function (I hope that's the correct term in Prolog) "myFunction(X)". He will call this function by using the parameter "fact(x)". So the call looks like this: "myFunction(fact(x))". Within "myFunction" I call another function "anotherFunction", like this: myFunction(X) :- anotherFunction(X). In this example both functions use the same parameter. When the User calls "myFunction(fact(x))" then the parameter for "anotherFunction" is also "fact(x)". But to the "anotherFunction(X)" I want only assign the "x" from "fact(x)". Thus I search for a possibility how I can extract the "x" out of "fact(x)". Is that possible??? Greetings, Manuel
Post Follow-up to this messageManuel Winter schrieb: > Hi, > > In my programm the user can call a function (I hope that's the correct ter m > in Prolog) "myFunction(X)". He will call this function by using the > parameter "fact(x)". > So the call looks like this: "myFunction(fact(x))". > > Within "myFunction" I call another function "anotherFunction", like this: > > myFunction(X) :- anotherFunction(X). > > In this example both functions use the same parameter. When the User calls > "myFunction(fact(x))" then the parameter for "anotherFunction" is also > "fact(x)". > > But to the "anotherFunction(X)" I want only assign the "x" from "fact(x)". > Thus I search for a possibility how I can extract the "x" out of "fact(x)" . > > Is that possible??? > > Greetings, > > Manuel > > well first, you don't have to forget that you just define predicates by horn clauses. You don't have a function, you don't get a result from "calling myFunction(X)". for the other part, how to get x from fact(x), this is easy: myFunction(fact(X)) :- anotherFunction(X). pattern matching allows you to match against any named record. -- Matthias
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.