Quoting from the standard:
7.4.2.7 include/1
If F is an implementation defined ground term designating
a Prolog text unit, then Prolog text P1 which contains
a directive include(F) is identical to a Prolog text P2
obtained by replacing the directive include(F) in P1 by
the Prolog text denoted by F.
Example:
:- include("hello.pl").
This addresses #583 and #634.
The -t flag is not limited to arity 0 predicates - it accepts any
goal including goals with arguments (e.g., -t 'halt(1)'). Updated
the help text to remove the incorrect "(arity 0 predicate)" constraint.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add dynamic directive in toplevel.pl with other module-level directives
- Update test files to reference it as '':g_caused_exception/2
- Remove redundant dynamic directives from test files
- All tests passing
When a goal throws an exception during initialization (-g flag), the
system now asserts g_caused_exception(Goal, Exception) in the user
module. This allows custom toplevels (-t flag) to check if an error
occurred and handle it appropriately.
Example usage:
scryer-prolog -g "throw(error)" -t check_error
Where check_error can be:
:- dynamic(g_caused_exception/2).
check_error :-
( g_caused_exception(_, E) ->
write('Error: '), write(E), nl, halt(1)
; halt(0)
).
This enables scripts to use custom toplevels for sophisticated error
handling and exit code logic.
Addresses: https://github.com/mthom/scryer-prolog/pull/3147#issuecomment-3503875719
Co-Authored-By: J.J.'s Robot <jjtolton@gmail.com>
Fixed issue where `scryer-prolog -t halt` would try to load "halt.pl"
as a file instead of just using halt as the custom toplevel.
The bug was caused by an extra clause `delegate_task([], []).` that
would return control to the calling context instead of continuing to
start_toplevel. This caused the argument processing in delegate_task
to continue and treat the already-consumed toplevel argument as a
filename.
Removing this clause ensures that delegate_task([], Goals0) always
proceeds to load initialization files and start the toplevel, fixing
the double-processing bug.
Co-Authored-By: J.J.'s Robot <jjtolton@gmail.com>
- Add -t FLAG to specify custom toplevel (arity 0 predicate)
- Default toplevel is 'repl' if -t is not specified
- Using `-t halt` achieves original goal of guaranteed termination
- Custom toplevels enable flexible exit strategies (e.g., server mode)
- Update help text to document -t flag
Examples:
scryer-prolog -t halt program.pl # Exits after execution
scryer-prolog -t my_repl program.pl # Custom REPL
scryer-prolog program.pl # Default REPL
Co-Authored-By: J.J.'s Robot <noreply@example.com>
I ran into the same problem today and I figured I'd take a stab at it.
Unfortunately, I'm not certain it is the right approach, but it no
longer errors like it did before.
Fixes#2650.
Signed-off-by: Stephan Renatus <stephan@styra.com>