-
How can I get the values of command-line arguments in Scryer Prolog? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 18 replies
-
You can access them with $ scryer-prolog -- test ?- '$toplevel':argv(As). As = ["test"]. |
Beta Was this translation helpful? Give feedback.
-
Wondering why an explicit qualified call is required:
As we have: :- module('$toplevel', [argv/1,
copy_term/3]). And the module seems to be loaded automatically at startup. |
Beta Was this translation helpful? Give feedback.
-
This is the first time I've encountered syntax like a $ inside single quotes followed by colon. |
Beta Was this translation helpful? Give feedback.
-
@pmoura is right, the qualification shouldn't be necessary. I don't think the toplevel module is consulted at startup, it's just loaded and the repl predicate is called internally. I'll look at fixing it tomorrow. |
Beta Was this translation helpful? Give feedback.
-
Ideally, a declarative approach should be used to manage command line arguments. There are some very popular libraries for that in Python (argparse) and Rust (clap), but I don't think there's an equivalent Prolog library. I would experiment with that :) |
Beta Was this translation helpful? Give feedback.
-
Does this mean that |
Beta Was this translation helpful? Give feedback.
You can access them with
argv/1
from the module'$toplevel'
. Example: