Re: Higher order programming: apply/3 implemented in swi
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 18 May 2008 09:50:58 GMT
On 2008-05-18, levilista@xxxxxxxxx <levilista@xxxxxxxxx> wrote:
On May 18, 10:55 am, Jan Wielemaker <j...@xxxxxxxxxxxxxxxxxxx> wrote:
<snip>
apply(F,Args,Term) :-
F =.. List,
append(List, Args, All),
Term =.. All.
Cheers --- Jan
When using the lambda notation in functional languages, we can create
semi substituted functions. In prolog its equivalent is a predicate
with incorrect arity. Calling it will give us errors. apply/2 calls it
prematurely, that's the problem.
That is an answer on why you sometimes need apply/3 (true, sometimes you
wish to extend the arguments without making the call; for example DCG
translation does this).
Still, I don't see where your code is different in functionality from
the trivial code above. Ok, my code creates two intermediate lists that
can be avoided at the cost of a bit more programming, but your code
creates even more intermediate datastructures.
--- Jan
.
- Follow-Ups:
- Re: Higher order programming: apply/3 implemented in swi
- From: levilista@xxxxxxxxx
- Re: Higher order programming: apply/3 implemented in swi
- From: levilista@xxxxxxxxx
- Re: Higher order programming: apply/3 implemented in swi
- References:
- Higher order programming: apply/3 implemented in swi
- From: levilista@xxxxxxxxx
- Re: Higher order programming: apply/3 implemented in swi
- From: Jan Wielemaker
- Re: Higher order programming: apply/3 implemented in swi
- From: levilista@xxxxxxxxx
- Higher order programming: apply/3 implemented in swi
- Prev by Date: Re: Higher order programming: apply/3 implemented in swi
- Next by Date: Re: Higher order programming: apply/3 implemented in swi
- Previous by thread: Re: Higher order programming: apply/3 implemented in swi
- Next by thread: Re: Higher order programming: apply/3 implemented in swi
- Index(es):
Relevant Pages
|