swipl-devel icon indicating copy to clipboard operation
swipl-devel copied to clipboard

absolute_file_name(library(chr),F) returns path to dir not to chr.pl

Open anionic opened this issue 4 years ago • 1 comments
trafficstars

Hi Jan

Despite "This predicate only returns non-directories" in PlDoc for absolute_file_name/3, I get (updated Windows 10 Pro 64-bit):

Welcome to SWI-Prolog (threaded, 64 bits, version 8.2.4)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- absolute_file_name(library(chr), FilePath).
FilePath = 'c:/swipl-8.x/library/chr'.

?- use_module(library(chr)).
true.

?- absolute_file_name(library(chr), FilePath, [file_type(prolog)]).
FilePath = 'c:/users/paul/appdata/roaming/swi-prolog/lib/chr.pl'.

?- absolute_file_name(library(chr), FilePath, [extensions([pl])]).
FilePath = 'c:/users/paul/appdata/roaming/swi-prolog/lib/chr.pl'.

there being both a chr/ and chr.pl.

My attempted workarounds (explicit options) yield a path to a non-existent file :-/

BTW I am trying to read the sentences of source files as terms without consulting them; I reckon I have to gather all op/3 from a file's module directive and from those of any module they import, apply them to a new (scratch) module M then read its sentences with read_term(S, T, [module(M)])

NB this is not holding me up, as I really oughta be doing something else ;-)

regards - Paul S.

anionic avatar Feb 12 '21 20:02 anionic

Hi Paul, Add an access(read) option and you'll get what you are looking for. For reading Prolog source, look at library(prolog_source). That deals with most of the oddities. See also library(prolog_xref) that uses this and provides some more.

JanWielemaker avatar Feb 13 '21 08:02 JanWielemaker