[英]Workaround ensure_loaded/1 B-Prolog?
Is there a workaround to make ensure_loaded/1 work in B-Prolog as it works in many other Prolog systems? 是否有一种解决方法可以确保sure_loaded / 1在B-Prolog中工作,就像在其他许多Prolog系统中一样? The goal is to have a preamble so that the rest of code can use ensure_loaded/1 independent of whether which Prolog system I use. 目的是要有一个序言,以便其余代码可以使用sure_loaded / 1,而与我是否使用哪个Prolog系统无关。
So I tried the following: 所以我尝试了以下方法:
:- set_prolog_flag(redefine_builtin, on).
ensure_loaded(X) :-
atom_concat('<base>\\',X,Y),
consult(Y).
:- set_prolog_flag(redefine_builtin, off).
But when a Prolog text with the following directive is consulted, I wont work: 但是,当使用以下指令查询Prolog文本时,我将无法工作:
:- ensure_loaded('suite.p').
It still doesn't find suite.p. 它仍然找不到suite.p。
What could I do? 我能做什么?
Bye 再见
Regarding the expansion of paths, in the Logtalk adapter file for B-Prolog I (must) use: 关于路径的扩展,在B-Prolog I的Logtalk适配器文件中(必须)使用:
% '$lgt_expand_path'(+nonvar, -atom)
%
% expands a file path to a full path
'$lgt_expand_path'(Path, ExpandedPath) :-
% first expand any environment variable
expand_environment(Path, ExpandedPath0),
( ( sub_atom(ExpandedPath0, 0, 1, _, '/')
% assume POSIX full path
; sub_atom(ExpandedPath0, 1, 1, _, ':')
% assume Windows full Path starting with a drive letter followed by ":"
) ->
% assume full path
ExpandedPath = ExpandedPath0
; % assume path relative to the current directory
working_directory(Current),
atom_concat(Current, '/', Directory),
atom_concat(Directory, ExpandedPath0, ExpandedPath)
).
It's basically an hack (that can be improved by eg trying to find first in which OS you're running) for missing functionality that should be provided by B-Prolog itself. 从本质上来说,这是一种黑客(可以通过尝试首先找到要在其中运行的操作系统来进行改进)来缺少B-Prolog本身应提供的功能。
I could only arrive at the following analysis and workaround. 我只能得出以下分析和解决方法。
The set_prolog_flag(redefine_builtin, on) doesn't work inside a Prolog text for B-Prolog. set_prolog_flag(redefine_builtin,on)在B-Prolog的Prolog文本中不起作用。 I get: 我得到:
B-Prolog Version 8.1
?- consult('<base>\\bprolog.p').
consulting::<base>\bprolog.p
** Error : Trying to redefine built-
in:'<base>\\bprolog.p',18::ensure_loaded/1
*** error(file_not_found,suite.p)
When I do the set_prolog_flag(redefine_builtin, on) in the top-level, things are fine: 当我在顶层执行set_prolog_flag(redefine_builtin,on)时,一切都很好:
?- set_prolog_flag(redefine_builtin, on).
?- consult('<base>\\bprolog.p').
consulting::<base>\bprolog.p
consulting::<base>\suite.p
Etc..
Bye 再见
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.