For Programmers: Free Programming Magazines  


Home > Archive > Prolog > October 2004 > Extraction...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Extraction...
Manuel Winter

2004-10-02, 3:56 pm

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


Matthias Kretschmer

2004-10-02, 3:56 pm

Manuel Winter schrieb:
> 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
>
>


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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com