Prolog dependencies: include vs ensure_loaded -


i'm writing program in prolog. have 3 files: class.pl, main.pl, utilities.pl.

class.pl:

:- include('utilities.pl'). 

main.pl:

:- include('utilities.pl'). :- include('class.pl'). 

when compile main.pl warning "clauses ... not together".

however, if switch include ensure_loaded, doesn't give me warning anymore. i'm assuming has circular dependencies , predicates in utilities.pl being rewritten? ensure_loaded work #pragma once in c++?

but i've read somewhere include includes code, while ensure_loaded consults it?

if clear things me , let me know should doing, i'd grateful :)

roughly, directive include/1 means #include , ensure_loaded/1 means #include include guard. #include-once. well, roughly.

you warning because utilities.pl included twice.

here relevant parts standard iso/iec 13211-1:1995:

7.4.2.7 include/1

if f implementation defined ground term designating
prolog text unit, prolog text p1 contains
directive include(f) identical prolog text p2
obtained replacing directive include(f) in p1 by
prolog text denoted f.

whereas

7.4.2.8 ensure_loaded/1

...

when multiple directives ensure_loaded(p_text) exist
same prolog text, prolog text included in
prolog text prepared execution once. the
position included implementation defined.

current prolog systems require included text valid prolog text. not leave open clause or /*-comments. text inclusion not taken literally.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -