Exercises on short swi-prolog command line scripts which executes function defined in library package pac

I wrote three short swi-prolog command line scripts, which works on library pack pac (v 1.9.8).
Here are three query logs

Q1. udg-path-count 'a-d' '[a-b, b-c, a-d, d-c, e-a, e-b, e-c, e-d]'
Q2. udg-path-count-rect 'rect(3,3)'
Q3. perms-count  5

Q1 counts the number of paths of an UDG ‘[a-b, b-c, a-d, d-c, e-a, e-b, e-c, e-d]’ from a to d.
Q2 counts the number of paths of a rectangual grid graphs of width 3 and height 3.
Q3 counts the number of permutations of [1,2,3,4,5] after really generating them all.

These scripts seem lengthy and redundant, and if I were familiar with `initialization(Goal, main)’ they must become much smarter, I expect.

Changing paths appropriately for your configuration, query logs should be reproducible.

Query log
% udg-path-count 'a-d' '[a-b, b-c, a-d, d-c, e-a, e-b, e-c, e-d]'
5
4
3
2
1
done
udg_path_count=8

% udg-path-count-rect 'rect(3,3)'
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
done
udg_path_count_rect=184

% perms-count  5
perms_count=120
% 
shell udg-path-count
#! /bin/sh

PACLIB=${HOME}/.local/share/swi-prolog/pack/pac/prolog
# PACLIB=${HOME}/devel/zdd/prolog

SCRIPTPL=${HOME}/local/bin/udg-path-count.pl
SWIPL=${HOME}/bin/swipl
PAC=${PACLIB}/pac.pl
ZDD=${PACLIB}/zdd/zdd.pl

${SWIPL} -q -l $PAC -l $ZDD -l $SCRIPTPL -g zrun -t halt -- "$1" "$2"
udg-path-count.pl
:- module(zrun, [zrun/0]).

:- use_module(zdd('zdd-array')).
:- use_module(zdd(zdd)).
:- use_module(pac(op)).
:- use_module(zdd('frontier-vector')).

zrun:-current_prolog_flag(argv, X),
	X=[A,B],
	term_string(TA, A),
	term_string(TB, B),
	zdd,
	frtvec:udg_path_count(TA, TB, C),
    writeln(udg_path_count = C).

shell udg-path-count-rect
#! /bin/sh

PACLIB=${HOME}/.local/share/swi-prolog/pack/pac/prolog
# PACLIB=${HOME}/devel/zdd/prolog

COUNTPATH=${HOME}/local/bin/udg-path-count-rect.pl
SWIPL=${HOME}/bin/swipl
PAC=${PACLIB}/pac.pl
ZDD=${PACLIB}/zdd/zdd.pl

${SWIPL} -q -l $PAC -l $ZDD -l $COUNTPATH -g zrun -t halt -- "$1"
udg-path-count-rect.pl
:- module(zrun, [zrun/0]).

:- use_module(zdd('zdd-array')).
:- use_module(zdd(zdd)).
:- use_module(pac(op)).
:- use_module(zdd('frontier-vector')).

zrun:-current_prolog_flag(argv, X),
	X=[A],
	term_string(TA, A),
	zdd,
	frtvec:rect_path_count(TA, C),
    writeln(udg_path_count_rect = C).
shell perms-count
#! /bin/sh

PACLIB=${HOME}/.local/share/swi-prolog/pack/pac/prolog
# PACLIB=${HOME}/devel/zdd/prolog

SCRIPTPL=${HOME}/local/bin/perms-count.pl
SWIPL=${HOME}/bin/swipl
PAC=${PACLIB}/pac.pl
ZDD=${PACLIB}/zdd/zdd.pl

${SWIPL} -q -l $PAC -l $ZDD -l $SCRIPTPL -g zrun -t halt -- "$1"
perms-count.pl
:- module(zrun, [zrun/0]).

:- use_module(zdd('zdd-array')).
:- use_module(zdd(zdd)).
:- use_module(pac(op)).

zrun:-current_prolog_flag(argv, X),
	X=[A],
	term_string(TA, A),
	module(zmod),
	zdd,
	numlist(1, TA, Ns),
	zmod:all_perm(Ns, P),
	card(P, C),
    writeln(perms_count = C).