interpl

Experiments with intepreters in Prolog
git clone https://ccx.te2000.cz/git/interpl
Log | Files | Refs | README

commit bdb00d284bb614ecc44457b6c3ed053305725338
parent 328d8a7717018a6357f6f205242f340de801c2fc
Author: Jan Pobrislo <ccx@te2000.cz>
Date:   Thu,  3 Sep 2026 00:46:00 +0000

Ellide singleton lists on dot left-hand side

Diffstat:
Mdotexp.pl | 9++++++++-
Mdotexp_tests.pl | 18+++++++++++++++---
2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/dotexp.pl b/dotexp.pl @@ -17,11 +17,18 @@ dotexp_lists(multi([A_DE, B_DE | Rest_DE]), [A_L, B_L | Rest_L]) :- % at least dotexp_lists(dot(Infix_DE, LHS_DE, RHS_DE), [Infix_L, LHS_L | RHS_L]) :- dotexp_lists(Infix_DE, Infix_L), - dotexp_lists(LHS_DE, LHS_L), + dotexp_lists_dot_lhs(LHS_DE, LHS_L), dotexp_lists(RHS_DE, RHS_L). dotexp_lists(list(DE), L) :- maplist(dotexp_lists, DE, L). +dotexp_lists_dot_lhs(list([Value]), LHS_L) :- + dotexp_lists(Value, LHS_L). + +dotexp_lists_dot_lhs(LHS_DE, LHS_L) :- + LHS_DE \= list([_]), + dotexp_lists(LHS_DE, LHS_L). + %%% Transformer from AST to IR %%% IR is: %%% multi(List) - parenthesised semicolon-separated sub-lists diff --git a/dotexp_tests.pl b/dotexp_tests.pl @@ -158,11 +158,15 @@ test(de_l_multi_list_two_and_one_atom) :- test(de_l_atom_dot_atom_atom) :- ir_to_sexp(dot(b, list([a]), list([c])), Expression), - assertion(Expression =@= [b, [a], c]). + assertion(Expression =@= [b, a, c]). + +test(de_l_atom_atom_dot_atom_atom) :- + ir_to_sexp(dot(c, list([a, b]), list([d])), Expression), + assertion(Expression =@= [c, [a, b], d]). test(numbers_choose_as_a) :- ir_to_sexp(dot(as, dot(choose, list([numbers]), list([])), list([a])), Expression), - assertion(Expression =@= [as, [choose, [numbers]], a]). + assertion(Expression =@= [as, [choose, numbers], a]). :- end_tests(dotexp_lists). @@ -204,6 +208,10 @@ test(dotexp_atom_dot_atom_atom) :- codes_to_ir(`(a .b c)`, Expression), assertion(Expression =@= dot(b, list([a]), list([c]))). +test(dotexp_atom_atom_dot_atom_atom) :- + codes_to_ir(`(a b .c d)`, Expression), + assertion(Expression =@= dot(c, list([a, b]), list([d]))). + test(dotexp_def) :- codes_to_ir(`(define proc (lambda (e f g) (lambda () e)))`, Expression), assertion(Expression =@= list([define, proc, list([lambda, list([e, f, g]), list([lambda, list([]), e])])])). @@ -214,11 +222,15 @@ test(dotexp_qq) :- test(numbers_choose_as_a) :- codes_to_sexp(`(numbers .choose .as a)`, Expression), + assertion(Expression =@= [as, [choose, numbers], a]). + +test(par_numbers_choose_as_a) :- + codes_to_sexp(`((numbers) .choose .as a)`, Expression), assertion(Expression =@= [as, [choose, [numbers]], a]). test(dotexp_qq2) :- Expression = {|dotexp||(numbers .choose .as a)|}, - assertion(Expression =@= [as, [choose, [numbers]], a]). + assertion(Expression =@= [as, [choose, numbers], a]). :- end_tests(dotexp).