interpl

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

commit 2a7eeb651ce966b0c0928ac22c329625f32af87c
parent 69ad1c665bd4f7383a31bb74d8fb16c1a617c49d
Author: Jan Pobrislo <ccx@te2000.cz>
Date:   Fri, 30 May 2025 17:13:10 +0000

tests for primitive functions

Diffstat:
Minterpreter.pl | 2++
Mtests.pl | 30++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/interpreter.pl b/interpreter.pl @@ -3,6 +3,8 @@ [ parse_input_expression/2 , sexp//1 , sexp/4 + , interp_apply/3 + , interp_eval/4 ]). :- use_module(library(debug), [assertion/1]). :- use_module(library(dcg/basics), [blanks//0, number//1]). diff --git a/tests.pl b/tests.pl @@ -50,3 +50,33 @@ test(sexp_qq) :- assertion(Expression =@= [define, proc, [lambda, [e, f, g], [lambda, [], e]]]). :- end_tests(sexp). +:- begin_tests(primitive_apply). + +apply_example(car, [{|sexp||(a b c)|}], {|sexp||a|}). +apply_example(car, [{|sexp||((a b c) x y z)|}], {|sexp||(a b c)|}). +apply_example(car, [{|sexp||(((hotdogs)) (and) (pickle) relish)|}], {|sexp||((hotdogs))|}). +apply_example(car, [{|sexp||((hotdogs))|}], {|sexp||(hotdogs)|}). + +apply_example(cdr, [{|sexp||(a b c)|}], {|sexp||(b c)|}). +apply_example(cdr, [{|sexp||((a b c) x y z)|}], {|sexp||(x y z)|}). +apply_example(cdr, [{|sexp||(hamburger)|}], {|sexp||()|}). +apply_example(cdr, [{|sexp||((x) t r)|}], {|sexp||(t r)|}). + +apply_example(Func, Args, ExpectedResult) :- + apply_example(CallCs, ResultCs), + decode(CallCs, [Func|Args]), + decode(ResultCs, ExpectedResult). + +apply_example(`(cons peanut (butter and jelly))`, + `(peanut butter and jelly)`). + +apply_example(`(cons ((help) this) (is very ((hard) to learn)))`, + `(((help) this) is very ((hard) to learn))`). + +apply_example(`(cons (a b (c)) ())`, `((a b (c)))`). + +test(apply_example, [forall(apply_example(Func, Args, ExpectedResult))]) :- + interp_apply(primitive(Func), Args, Result), + assertion(Result =@= ExpectedResult). + +:- end_tests(primitive_apply).