Did you know ... Search Documentation:
ifprolog.pl -- IF/Prolog compatibility package
PublicShow source

This library realises emulation of IF/Prolog. As with all the emulation layers in the dialect directory, the emulation has been established on `as needed' basis from porting programs. This implies that the emulation is incomplete. Emumated directives, predicates and libraries are often not 100% compatible with the IF/Prolog version.

Note that this emulation layer targets primarily IF/Prolog version 5.

Please help extending this library and submit patches to bugs@swi-prolog.org.

Source ifprolog_goal_expansion(+In, +Out)[multifile]
goal_expansion rules to emulate IF/Prolog behaviour in SWI-Prolog. The expansions below maintain optimization from compilation. Defining them as predicates would loose compilation.
Source context(:Goal, Handler)
Is mapped to catch(Goal, Error, Recover) is Handler is error(_,_) => Recover. Other cases are not covered by the emulation.
Source ifprolog_term_expansion(+In, +Out)[multifile]
term_expansion rules to emulate IF/Prolog behaviour in SWI-Prolog.
Source calling_context(-Context)
Mapped to context_module/1.
Source context(:Goal, +Mapping)
IF/Prolog context/2 construct. This is the true predicate. This is normally mapped by goal-expansion.
bug
- Does not deal with IF/Prolog signal mapping
Source block(:Goal, +Tag, :Recovery)
Source exit_block(+Tag)
Source cut_block(+Tag) is semidet
The control construct block/3 runs Goal in a block labelled Tag. If Goal calls exit_block/1 using a matching Tag, the execution of Goal is abandoned using exception handling and execution continues by running Recovery. Goal can call cut_block/1. If there is a block with matching Tag, all choice points created since the block was started are destroyed.
bug
- The block control structure is implemented on top of catch/3 and throw/1. If catch/3 is used inside Goal, the user must ensure that either (1) the protected goal does not call exit_block/1 or cut_block/1 or (2) the Catcher of the catch/3 call does not unify with a term block(_,_).
Source modify_mode(+PI, -OldMode, +NewMode) is det
Switch between static and dynamic code. Fully supported, but notably changing static to dynamic code is not allowed if the predicate has clauses.
Source debug_mode(:PI, -Old, +New)
Old is not unified. Only New == off is mapped to disable debugging of a predicate.
Source ifprolog_debug(:Goal)
Map IF/Prolog debug(Goal)@Module. This should run Goal in debug mode. We rarely needs this type of measures in SWI-Prolog.
Source debug_config(+Key, -Current, +Value)
Ignored. Prints a message.
Source float_format(-Old, +New)
Ignored. Prints a message. Cannot be emulated. Printing floats with a specified precision can only be done using format/2.
Source program_parameters(-List:atom)
All command-line argument, including the executable,
Source user_parameters(-List:atom)
Parameters after --.
Source match(+Mask, +Atom) is semidet
Same as once(match(Mask, Atom, _Replacements)).
Source match(+Mask, +Atom, ?Replacements) is nondet
Pattern matching. This emulation should be complete. Can be optimized using caching of the pattern-analysis or doing the analysis at compile-time.
Source lower_upper(+Lower, -Upper) is det
lower_upper(-Lower, +Upper) is det
Multi-moded combination of upcase_atom/2 and downcase_atom/2.
Source load File
Mapped to consult. I think that the compatible version should only load .qlf (compiled) code.
Source file_test(+File, +Mode)
Mapped to access_file/2 (which understand more modes). Note that this predicate is defined in the module system to allow for direct calling.
Source filepos(@Stream, -Line)
from the IF/Prolog documentation The predicate filepos/2 determines the current line position of the specified input stream and unifies the result with Line. The current line position is the number of line processed + 1
Source getcwd(-Dir)
The predicate getcwd/1 unifies Dir with the full pathname of the current working directory.
Source filepos(@Stream, -Line, -Column)
from the IF/Prolog documentation The predicate filepos/2 determines the current line position of the specified input stream and unifies the result with Line. The current line position is the number of line processed + 1
Source assign_alias(+Alias, @Stream) is det
Source writeq_atom(+Term, -Atom)
Use writeq/1 to write Term to Atom.
Source write_atom(+Term, -Atom)
Use write/1 to write Term to Atom.
Source current_error(-Stream)
Doesn't exist in SWI-Prolog, but user_error is always an alias to the current error stream.
Source write_formatted_atom(-Atom, +Format, +ArgList) is det
Source write_formatted(+Format, +ArgList) is det
Source write_formatted(@Stream, +Format, +ArgList) is det
Emulation of IF/Prolog formatted write. The emulation is very incomplete. Notable asks for dealing with aligned fields, etc.
bug
- Not all format characters are processed
- Incomplete processing of modifiers, fieldwidth and precision
To be done
- This should become goal-expansion based to process format specifiers at compile-time.
Source get_until(+SearchChar, -Text, -EndChar) is det
Source get_until(@Stream, +SearchChar, -Text, -EndChar) is det
Read input from Stream until SearchChar. Unify EndChar with either SearchChar or the atom end_of_file.
Source atom_part(+Atom, +Pos, +Len, -Sub) is det
True when Sub is part of the atom [Pos,Pos+Len). Unifies Sub with '' if Pos or Len is out of range!?
Source atom_prefix(+Atom, +Len, -Sub) is det
Unifies Sub with the atom formed by the first Len characters in atom.
  • If Len < 1, Sub is unified with the null atom ''.
  • If Len > length of Atom, Sub is unified with Atom.
Source atom_suffix(+Atom, +Len, -Sub) is det
Unifies Sub with the atom formed by the last Len characters in atom.
  • If Len < 1, Sub is unified with the null atom ''.
  • If Len > length of Atom, Sub is unified with Atom.
Source atom_split(+Atom, +Delimiter, ?Subatoms)
Split Atom over Delimiter and unify the parts with Subatoms.
Source if_concat_atom(+List, +Delimiter, -Atom) is det
True when Atom is the concatenation of the lexical form of all elements from List, using Delimiter to delimit the elements.

The behavior of this ifprolog predicate is different w.r.t. SWI-Prolog in two respect: it supports arbitrary terms in List rather than only atomic and it does not work in mode -,+,+.

Source if_concat_atom(+List, -Atom) is det
True when Atom is the concatenation of the lexical form of all elements from List. Same as if_concat_atom/3 using '' as delimiter.
Source getchar(+Atom, +Pos, -Char)
Unifies Char with the Position-th character in Atom If Pos < 1 or Pos > length of Atom, then fail.
Source parse_atom(+Atom, +StartPos, ?EndPos, ?Term, ?VarList, ?Error)
Read from an atom.
Arguments:
StartPos- is 1-based position to start reading
Error- is the 1-based position of a syntax error or 0 if there is no error.
Source index(+Atom, +String, -Position) is semidet
True when Position is the first occurrence of String in Atom. Position is 1-based.
Source list_length(+List, ?Length) is det
Deterministic version of length/2. Current implementation simply calls length/2.
Source for(+Start, ?Count, +End) is nondet
Similar to between/3, but can count down if Start > End.
Source prolog_version(-Version)
Return IF/Prolog simulated version string
Source proroot(-Path)
True when Path is the installation location of the Prolog system.
Source system_name(-SystemName)
True when SystemName identifies the operating system. Note that this returns the SWI-Prolog arch flag, and not the IF/Prolog identifiers.
Source localtime(+Time, ?Year, ?Month, ?Day, ?DoW, ?DoY, ?Hour, ?Min, ?Sec)
Break system time into its components. Deefines components:
YearYear number4 digits
MonthMonth number1..12
DayDay of month1..31
DoWDay of week1..7 (Mon-Sun)
DoYDay in year1..366
HourHours0..23
MinMinutes0..59
SecSeconds0..59

Note that in IF/Prolog V4, Year is 0..99, while it is a four-digit number in IF/Prolog V5. We emulate IF/Prolog V5.

Source current_global(+Name) is semidet
Source get_global(+Name, ?Value) is det
Source set_global(+Name, ?Value) is det
Source unset_global(+Name) is det
IF/Prolog global variables, mapped to SWI-Prolog's nb_* predicates.
Source current_default_module(-Module) is det
Name of the toplevel typein module.
Source set_default_module(+Module) is det
Set the default toplevel module.
Source asserta_with_names(@Clause, +VarNames) is det
Source assertz_with_names(@Clause, +VarNames) is det
Source clause_with_names(?Head, ?Body, -VarNames) is det
Source retract_with_names(?Clause, -VarNames) is det
Predicates that manage the database while keeping track of variable names.
Source predicate_type(:PI, -Type) is det
True when Type describes the type of PI. Note that the value linear seems to mean you can use clause/2 on it, which is true for any SWI-Prolog predicate that is defined. Therefore, we use it for any predicate that is defined.
Source current_visible(@Module, @PredicateIndicator)
FIXME check with documentation
Source current_signal(?Signal, ?Mode) is nondet
True when Mode is the current mode for handling Signal. Modes are on, off, default, ignore. Signals are abort, alarm, interrupt, pipe, quit, termination, user_1 and user_2.
To be done
- Implement
Source digit(+A)
Is the character A a digit [0-9]
Source letter(+A)
Is the character A a letter [A-Za-z]

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

Source write_formatted(Arg1, Arg2, Arg3)
Source retract_with_names(Arg1, Arg2)
Source get_until(Arg1, Arg2, Arg3, Arg4)
Source write_formatted(Arg1, Arg2)
Source get_global(Arg1, Arg2)
Source set_global(Arg1, Arg2)
Source assertz_with_names(Arg1, Arg2)
Source cut_block(Arg1)
Source unset_global(Arg1)
Source clause_with_names(Arg1, Arg2, Arg3)
Source exit_block(Arg1)