Loading Logtalk files at runtime with altdirs on

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Post Reply
joerg
Posts: 40
Joined: Fri Dec 21, 2007 9:38 am

Loading Logtalk files at runtime with altdirs on

Post by joerg » Mon Aug 17, 2009 12:42 pm

Hello,

I usually use

:- set_logtalk_flag(altdirs, on).

But this doesn't seem to be compatible with another habit of mine: loading Logtalk files at runtime. Lc, a program of mine stores user information in a hidden directory (~/.lc). Only if the user wants lc to do certain things does it load certain Logtalk files that are in ~/.lc. This works perfectly if altdirs is set to off. If it is set to on, I get an error message of this type:

Code: Select all

$ lc inflect directory p2 german noun Haus
%         ERROR!    existence_error(source_sink, '.lgt_tmp//mounts/Users/cisintern/schuster/.lc/_mounts_Users_cisintern_schuster_lng_0_p2/german_noun.pl')
%                   in context(system:open/4, 'No such file or directory')
ERROR: Prolog initialisation failed:
ERROR: Unknown error term: error(existence_error(source_sink, .lgt_tmp//mounts/Users/cisintern/schuster/.lc/_mounts_Users_cisintern_schuster_lng_0_p2/german_noun.pl), context(system:open/4, No such file or directory))
schuster@lakonia:~/lng/0> 
Do I need to do more configuration for this to work?

Jörg

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Loading Logtalk files at runtime with altdirs on

Post by Paulo Moura » Mon Aug 17, 2009 5:26 pm

From the format of the error messages, I assume that you're using SWI-Prolog. Which Logtalk version are you using? Can you send me a small example that allows me to reproduce the problem? Maybe you can use a more robust setup by defining appropriated clauses for the logtalk_library_path/2 predicate. Something like (assuming a POSIX system):

Code: Select all

logtalk_library_path(home, '$HOME/').
logtalk_library_path(lc, home('.lc/').
and than use a call such as:

Code: Select all

logtalk_load(lc(...)).
when you need to load the files in the .lc directory.
Paulo Moura
Logtalk developer

joerg
Posts: 40
Joined: Fri Dec 21, 2007 9:38 am

Re: Loading Logtalk files at runtime with altdirs on

Post by joerg » Tue Aug 18, 2009 7:12 am

Code: Select all

logtalk_library_path(home, '$HOME/').
logtalk_library_path(lc, home('.lc/').

logtalk_load(lc(...)).
This solution works. Thank you.

Here are two small example files that illustrate the problem. I tested them with Logtalk 2.37.3 and Swi-Prolog.


test.lgt:

Code: Select all

:- object(test).

    :- public(greet/0).

    greet :-
        logtalk_load('/mounts/Users/cisintern/schuster/greeter'),
        greeter::greet.

:- end_object.

greeter.lgt:

Code: Select all

:- object(greeter).

    :- public(greet/0).

    greet :-
        write('Hello'),
        nl.

:- end_object.


Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Loading Logtalk files at runtime with altdirs on

Post by Paulo Moura » Tue Aug 18, 2009 10:49 am

The logtalk_load/1-2 and logtalk_compile/1-2 predicates don't support filename paths. The arguments must be either a filename (without extension) or a filename in "library" notation. Check the reference manual for more details. This limitation results, as you already guessed, from the lack of Prolog standardization of operating-system interfaces, including file path syntax.
Paulo Moura
Logtalk developer

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest