Re: Higher order programming: apply/3 implemented in swi



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

.



Relevant Pages

  • Re: N-QUEENS problem with some differences
    ...     M is K-1, ... little different from Prolog. ... If the syntax for lists and "anonymous variables" ... squares and the position of queens as another ...
    (comp.lang.prolog)
  • Re: This Logo program in Prolog?
    ... Term is the basic data structure of Prolog, ... easily use a compound term for building many of the other data ... including lists (lists are just compound terms ... only other language I've seen with such love for the list type is ...
    (comp.lang.prolog)
  • Re: This Logo program in Prolog?
    ... Term is the basic data structure of Prolog, ... easily use a compound term for building many of the other data ... including lists (lists are just compound terms ... only other language I've seen with such love for the list type is ...
    (comp.lang.prolog)
  • Re: Hilbert-Style proof in propositional calculus
    ... The topic lends itself to Prolog. ... about the representation of formulas as Prolog terms and ... We can then implement a Prolog predicate which succeeds ... Now let's briefly discuss representing proofs as lists ...
    (comp.lang.prolog)
  • Re: N-QUEENS problem with some differences
    ... I confirm you that a "queen" who is on a square, ...     M is K-1, ... little different from Prolog. ... If the syntax for lists and "anonymous variables" ...
    (comp.lang.prolog)