From 9e13f184638968da2b2762bb647209eac71deb5a Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sun, 15 Aug 2021 12:28:02 +0200 Subject: [PATCH] ENHANCED: Domain error non_empty_list for empty arguments, addressing #1024. Example: ?- format("~d", []). %@ caught: error(domain_error(non_empty_list,[]),format_//2) --- src/lib/format.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/format.pl b/src/lib/format.pl index f5bb0b05..e8964304 100644 --- a/src/lib/format.pl +++ b/src/lib/format.pl @@ -284,9 +284,11 @@ cells([~|Fs0], Args0, Tab0, Es, VNs) --> { Tab is Tab0 + Num }, cell(Tab0, Tab, Es), cells(Fs, Args, Tab, [], VNs). -cells([~,C|_], _, _, _, _) --> - { atom_chars(A, [~,C]), - domain_error(format_string, A, format_//2) }. +cells([~|Cs], Args, _, _, _) --> + ( { Args == [] } -> + { domain_error(non_empty_list, [], format_//2) } + ; { domain_error(format_string, [~|Cs], format_//2) } + ). cells(Fs0, Args, Tab, Es, VNs) --> { phrase(upto_what(Fs1, ~), Fs0, Fs), Fs1 = [_|_] }, -- 2.54.0