I have a SICStus script like below.
What I need is to print out the Current Working Directory (to be able to save that script in it) and load that file with something like load command. How can I finish that off ?
Last but not least, how can I enable the up-arrow to go through the command history after the prompt | ?-.
sat(Clauses, Vars) :-
problem_setup(Clauses), elim_var(Vars).
elim_var([]).
elim_var([Var | Vars]) :-
elim_var(Vars), (Var = true; Var = false).
problem_setup([]).
problem_setup([Clause | Clauses]) :-
clause_setup(Clause),
problem_setup(Clauses).
clause_setup([Pol-Var | Pairs]) :- set_watch(Pairs, Var, Pol).
set_watch([], Var, Pol) :- Var = Pol.
set_watch([Pol2-Var2 | Pairs], Var1, Pol1):-
watch(Var1, Pol1, Var2, Pol2, Pairs).
:- block watch(-, ?, -, ?, ?).
watch(Var1, Pol1, Var2, Pol2, Pairs) :-
nonvar(Var1) ->
update_watch(Var1, Pol1, Var2, Pol2, Pairs);
update_watch(Var2, Pol2, Var1, Pol1, Pairs).
update_watch(Var1, Pol1, Var2, Pol2, Pairs) :-
Var1 == Pol1 -> true; set_watch(Pairs, Var2, Pol2).
There are several ways to ask SICStus about what it considers the Current Working Directory. The easiest is perhaps to call
absolute_file_name/2with'.'as argument.Often it is more useful to be able to change the working directory, e.g. to where your files are located. This can be done using the
file_systemslibrary.The following transcript shows examples of the above:
$ /usr/local/sicstus4.8.0/bin/sicstus -i -f ... | ?- absolute_file_name('.', CWD). CWD = '/Users/perm' ? yes | ?- use_module(library(file_systems)). ... | ?- current_directory(CWD). CWD = '/Users/perm/' ? yes | ?- current_directory(OldCWD, 'test'). OldCWD = '/Users/perm/' ? yes | ?- current_directory(CWD). CWD = '/Users/perm/test/' ? yes | ?-You do not say what OS you are using, or how you interact with the SICStus toplevel, so it is unclear what your command history refers to.
In the SICStus IDE (SPIDER), which is the recommended way to interact with SICStus, there is a menu in the toplevel view, which also has keyboard shortcuts, for accessing the input history. In the Emacs Prolog toplevel there are also similar commands, and the same is true in the legacy Windows SICStus window.
If you specifically want the up-arrow key to have the effect of showing the previous history, I think you can do this in SPIDER and Emacs, with some effort, by rebinding that key to the corresponding command.
If you are just running the
sicstus(orsicstus.exe) command from the command line, then SICStus itself has no command line editing or history. It is up to your terminal emulator to provide this functionality. An alternative, at least on macOS and Linux, is the rlwrap tool that some users use as a wrapper around thesicstuscommand.I do not think that your code sample is relevant to any of your questions.