From 746dceff4389dec69ba2c9e4c486a54c88bd1b15 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 7 Apr 2018 15:21:05 +0000 Subject: [PATCH] added lambda? predicate --- README.md | 6 +++++- lib/prim.c | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f1faf11..cd15c62 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Language Syntax -A HCL program is composed of more expressions. +A HCL program is composed of expressions. ## Keywords * nil @@ -64,12 +64,16 @@ A HCL program is composed of more expressions. ## Defining a function +``` (defun function-name (arguments) | local variables | function body ) +``` +``` (set function-name (lambda (arguments) | local variables | function body ) +``` diff --git a/lib/prim.c b/lib/prim.c index e96bfde..6109734 100644 --- a/lib/prim.c +++ b/lib/prim.c @@ -400,6 +400,16 @@ static hcl_pfrc_t pf_is_dictionary (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) HCL_STACK_SETRET (hcl, nargs, rv); return HCL_PF_SUCCESS; } + +static hcl_pfrc_t pf_is_lambda (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) +{ + hcl_oop_t rv, x; + x = HCL_STACK_GETARG(hcl, nargs, 0); + rv = (HCL_IS_CONTEXT(hcl, x))? hcl->_true: hcl->_false; + HCL_STACK_SETRET (hcl, nargs, rv); + return HCL_PF_SUCCESS; +} + /* ------------------------------------------------------------------------- */ static hcl_pfrc_t pf_not (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) @@ -764,6 +774,7 @@ static pf_t builtin_prims[] = { 1, 1, pf_is_array, 6, { 'a','r','r','a','y','?' } }, { 1, 1, pf_is_bytearray, 10, { 'b','y','t','e','a','r','r','a','y','?' } }, { 1, 1, pf_is_dictionary, 11, { 'd','i','c','t','i','o','n','a','r','y','?' } }, + { 1, 1, pf_is_lambda, 7, { 'l','a','m','b','d','a','?' } }, { 1, HCL_TYPE_MAX(hcl_oow_t), pf_number_add, 1, { '+' } },