4
votes

So I run into some troubles while (ab?)using lambda.pl.

I do a "use_module(library(lambda))." in the first lines of a file that I consult via ["a.prolog"]. Then I get an "undefined procedure ()/3" and some gibberish afterwards.

The same happens for any order of use_modules. It happens whether I load a.prolog via [...], consult or as a script from the cmdline. I reduced the script to the currying-example from Rosseta code https://rosettacode.org/wiki/Currying#Prolog

use_module(library(lambda)).

:- initialization(main, main).

main :-
    N = 5, F = \X^Y^(Y is X+N), maplist(F, [1,2,3], L),
    print(L).

It doesn't work.

It works, however, if I a manually load 'lambda' at the swipl-prompt and immeditately consult a.prolog. Then the goal N=5,.... works just fine.

If I, however, first consult a.prolog; then manually use_module and then run the query, I get the error. Reconsulting doesn't help onwards.

Somehow, the first command at the prompt needs to be use_module.

Or do I get the loading mechanism completely wrong? If so, please apologize; but I would love get a hint how to solve this.

1
Minor comment: rather use F_2 in place of F. In this manner you are making clear that F_2 is an incomplete goal that needs two further arguments.false

1 Answers

4
votes

This is a common error when first using modules.

Please have a look at this line:

use_module(library(lambda)).

This is just a fact, saying "use_module(library(lambbda)) holds".

What you want instead is a directive.

A directive is a term with primary functor (:-)/1. That is, you want:

:- use_module(library(lambda)).

EDIT: For the particular case of library(lambda), I would like to add that there is a page with a lot of useful information about it that is a bit hard to find:

http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/ISO-Hiord

"Hiord" stands for higher order.