Re: list argument problem
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 19 Apr 2008 11:21:50 GMT
On 2008-04-18, Keenlearner <yingun@xxxxxxxxx> wrote:
May I know specifically which section that causes the design unwise ?
My application is actually combination of perl and prolog, the perl
would call the prolog code and then get the result back from the
prolog, so that's why I need the result to be at the last of the
predicate arguments.
Here is almost like what I am doing,
converter(VALUE,OUT,IN,R) :- perl5_call('convert',[VALUE,OUT,IN],R).
perl5_call(+PerlSubroutineName, +SubArgs, ?Result) this predicate is a
call to external perl program.
OUT and IN can be units name(km,cm,mm) and can also be term that would
finally return units name at the last arguments of the term.
should I separate the converter rules into two ? one for OUT or IN
value that is atom, the other for type term.
Looks like it is the design of the perl interaction that causes the
problem. Its way more natural to express function/predicate + arguments
as name(arg1, ...) instead of the tuple name and [arg1, ...]. Besides
being more natural, this is also easier and faster to handle both in
Prolog as in the C code that is probably used to setup the call.
Here we have a choice whether we include the result argument to the term
or not. Both make sense. Including probably yields the best performance.
Cheers --- Jan
Thank you very much..
On Apr 18, 11:22�pm, Jan Wielemaker <j...@xxxxxxxxxxxxxxxxxxx> wrote:
On 2008-04-18, Keenlearner <yin...@xxxxxxxxx> wrote:
Hello, if I have the predicate which is unknown at first for its
nameand number of arguments. This predicate is bounded to a variable,
so Iwould like to call this predicate and get the result of the call,
theresult variable always appear at the last argument of the
predicate.for instance,
X = plus(1,2). %
X =.. [Function|Args].
/*
Function = plus
Args = [1, 2]
*/
call(Function,Args, Result).
call(Function, Args, Result) :-
� � � � append(Args, [Result], AllArgs),
� � � � Goal =.. [Function|AllArgs],
� � � � Goal.
?- call(plus, [1,2], X).
X = 3.
But if you need this, it is very likely you did something not very
clever at a bit higher level of the design.
� � � � Cheers --- Jan
Thecall/2..6 would append the args of 2,3...and so on to the Function.
Butthe problem is the Args in call predicate is a list and is
unexpectedby call predicate. How can I solve this ? Thanks.
- References:
- list argument problem
- From: Keenlearner
- Re: list argument problem
- From: Jan Wielemaker
- Re: list argument problem
- From: Keenlearner
- list argument problem
- Prev by Date: Re: Questions from my student
- Next by Date: Re: Questions from my student
- Previous by thread: Re: list argument problem
- Next by thread: Questions from my student
- Index(es):