diff --git a/README.md b/README.md index 700cba0..ba1f83e 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,44 @@ A HCL program is composed of expressions. (printf "%d\n" (+ 10 20)) ``` +## Variadic arguments + +``` +(defun fn-y (t1 t2 va-ctx) + | i | + (set i 0) + (while (< i (va-count va-ctx)) + (printf "fn-y=>Y-VA[%d]=>[%d]\n" i (va-get i va-ctx)) + (set i (+ i 1)) + ) +) + +(defun x(a b ... ::: x y z) + |i| + +; (printf "VA_COUNT(x) = %d\n" (va-count)) + (set x "xxx") + (set y "yyy") + (set z "zzz") + (set z (+ a b)) + + (set i 0) + (while (< i (va-count)) + (printf "VA[%d]=>[%d]\n" i (va-get i)) + (set i (+ i 1)) + ) + (fn-y "hello" "world" (va-context)) + + (return) +) + +(printf "--------------------------\n") +(printf "[%O]\n" (x 10 20 30)) +(printf "--------------------------\n") +(set q (set-r a b c (x 10 20 30 40 50))) +(printf "--------------------------\n") +``` + ## HCL Exchange Protocol The HCL library contains a simple server/client libraries that can exchange diff --git a/t/Makefile.am b/t/Makefile.am index 1a6e0d7..45f3f03 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -5,6 +5,7 @@ check_SCRIPTS = \ insta-02.hcl \ ret-01.hcl \ retvar-01.hcl \ + va-01.hcl \ var-01.hcl ##noinst_SCRIPTS = $(check_SCRIPTS) diff --git a/t/Makefile.in b/t/Makefile.in index 8c4d855..f6446bd 100644 --- a/t/Makefile.in +++ b/t/Makefile.in @@ -466,6 +466,7 @@ check_SCRIPTS = \ insta-02.hcl \ ret-01.hcl \ retvar-01.hcl \ + va-01.hcl \ var-01.hcl EXTRA_DIST = $(check_SCRIPTS) diff --git a/t/va-01.hcl b/t/va-01.hcl new file mode 100644 index 0000000..c3fbbc9 --- /dev/null +++ b/t/va-01.hcl @@ -0,0 +1,41 @@ +(defun fn-y (t1 t2 va-ctx) + | i | + (set i 0) + (while (< i (va-count va-ctx)) + (printf "fn-y=>Y-VA[%d]=>[%d]\n" i (va-get i va-ctx)) + (set i (+ i 1)) + ) +) + +(defun x(a b ... ::: x y z) + |i| + + (set x (va-count)) + (set y (* a b)) + (set z (+ a b)) + + (set i 0) + (while (< i (va-count)) + (printf "VA[%d]=>[%d]\n" i (va-get i)) + (set i (+ i 1)) + ) + (fn-y "hello" "world" (va-context)) + + (return) +) + +(set t (x 10 20 30)) +(if (/= t 1) (printf "ERROR: t is not 1\n") + else (printf "OK: %d\n" t)) + +(set t (set-r a b c (x 10 20 30 40 50))) +(if (/= t 3) (printf "ERROR: t is not 3\n") + else (printf "OK: %d\n" t)) +(if (/= a 3) (printf "ERROR: a is not 3\n") + else (printf "OK: %d\n" a)) +(if (/= b 200) (printf "ERROR: b is not 200\n") + else (printf "OK: %d\n" b)) +(if (/= c 30) (printf "ERROR: c is not 30\n") + else (printf "OK: %d\n" c)) + +