PR feedback

This commit is contained in:
Adrián Arroyo Calle
2021-08-21 17:53:20 +02:00
parent dce0c43e26
commit 3cd112b60f

View File

@@ -10,20 +10,17 @@
:- use_module(library('$project_atts')). :- use_module(library('$project_atts')).
:- use_module(library('$atts')). :- use_module(library('$atts')).
:- dynamic(custom_init_file/0). :- dynamic(disabled_init_file/0).
load_scryerrc :- load_scryerrc :-
( '$home_directory'(HomeDir) -> ( '$home_directory'(HomeDir) ->
append(HomeDir, "./scryerrc", ScryerrcFile), append(HomeDir, "/.scryerrc", ScryerrcFile),
( load_init_file(ScryerrcFile) -> true ; true) ( file_exists(ScryerrcFile) ->
; true atom_chars(ScryerrcFileAtom, ScryerrcFile),
). catch(use_module(ScryerrcFileAtom), E, print_exception(E))
; true
load_init_file(ScryerrcFile) :- )
( file_exists(ScryerrcFile) -> ; true
atom_chars(ScryerrcFileAtom, ScryerrcFile),
catch(use_module(ScryerrcFileAtom), E, print_exception(E))
; true
). ).
:- dynamic(argv/1). :- dynamic(argv/1).
@@ -37,7 +34,7 @@ load_init_file(ScryerrcFile) :-
Args = Args0 Args = Args0
), ),
delegate_task(Args, []), delegate_task(Args, []),
(\+ custom_init_file -> load_scryerrc ; true), (\+ disabled_init_file -> load_scryerrc ; true),
repl. repl.
'$repl'(_) :- '$repl'(_) :-
( \+ argv(_) -> asserta('$toplevel':argv([])) ( \+ argv(_) -> asserta('$toplevel':argv([]))
@@ -49,7 +46,7 @@ load_init_file(ScryerrcFile) :-
delegate_task([], []). delegate_task([], []).
delegate_task([], Goals0) :- delegate_task([], Goals0) :-
reverse(Goals0, Goals), reverse(Goals0, Goals),
(\+ custom_init_file -> load_scryerrc ; true), (\+ disabled_init_file -> load_scryerrc ; true),
run_goals(Goals), run_goals(Goals),
repl. repl.
@@ -57,7 +54,7 @@ delegate_task([Arg0|Args], Goals0) :-
( member(Arg0, ["-h", "--help"]) -> print_help ( member(Arg0, ["-h", "--help"]) -> print_help
; member(Arg0, ["-v", "--version"]) -> print_version ; member(Arg0, ["-v", "--version"]) -> print_version
; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0) ; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0)
; member(Arg0, ["-f"]) -> init_file(Args, Goals0) ; member(Arg0, ["-f"]) -> init_file
; atom_chars(Mod, Arg0), ; atom_chars(Mod, Arg0),
catch(use_module(Mod), E, print_exception(E)) catch(use_module(Mod), E, print_exception(E))
), ),
@@ -73,8 +70,8 @@ print_help :-
write('Print version information and exit'), nl, write('Print version information and exit'), nl,
write(' -g, --goal GOAL '), write(' -g, --goal GOAL '),
write('Run the query GOAL'), nl, write('Run the query GOAL'), nl,
write(' -f FILE '), write(' -f '),
write('Run the provided initialization file instead of the default (~/.scryerrc)'),nl, write('Do not load initialization file (~/.scryerrc)'),nl,
% write(' '), % write(' '),
halt. halt.
@@ -92,16 +89,8 @@ gather_goal(Type, Args0, Goals) :-
Gs =.. [Type, Gs1], Gs =.. [Type, Gs1],
delegate_task(Args, [Gs|Goals]). delegate_task(Args, [Gs|Goals]).
init_file(Args0, Goals) :- init_file :-
\+ custom_init_file, asserta('disabled_init_file').
length(Args0, N),
( N < 1 -> print_help, halt
; true
),
[File|Args] = Args0,
load_init_file(File),
asserta('custom_init_file'),
delegate_task(Args, Goals).
arg_type(g). arg_type(g).
arg_type(t). arg_type(t).