Can someone please explain me why the initial call to statistics/0 throws an exception if the module is already loaded?
In Ciao the shell acts as another module: you cannot call predicates of a module unless you import them. So, when you do:
?- ensure_loaded('ciao_aux17.config').
you have a memory image in the shell which contains the prolog_sys module, but you have not imported this module into the shell. This is done with:
?- use_module(library(prolog_sys)).
Think of the shell as another module that you link together with your program in order to build an executable: the fact of linking them together does not make any of them to import the other one. E.g.:
shell -imports-> config -imports-> prolog_sys
You cannot call prolog_sys from shell.
To effectively import one module into another you have to put the use_module. E.g.:
shell -imports-> config -imports-> prolog_sys | ^ |-----------imports----------|
Now you can call prolog_sys from shell.
Paco Bueno