summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-07 21:47:04 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-07 21:47:04 -0700
commit2e10dec26c52850462ffbcdb0fcd32d029f192e4 (patch)
tree1b6f4f254bbb389f87421da2cc44cddac2fbdbb0
parent8b154a579becffc5c973797ff7ac7b162fd86b30 (diff)
downloadtxr-2e10dec26c52850462ffbcdb0fcd32d029f192e4.tar.gz
txr-2e10dec26c52850462ffbcdb0fcd32d029f192e4.tar.bz2
txr-2e10dec26c52850462ffbcdb0fcd32d029f192e4.zip
Adding promisep function.
* eval.c (promisep): New static function. (eval_init): Registered promisep intrinsic. * txr.1: Documented promisep.
-rw-r--r--eval.c12
-rw-r--r--txr.121
2 files changed, 33 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index fa8a8757..7c5da0be 100644
--- a/eval.c
+++ b/eval.c
@@ -3786,6 +3786,17 @@ static val weavev(struct args *args)
return lazy_appendl(generate(whil, gen));
}
+static val promisep(val obj)
+{
+ if (consp(obj)) {
+ val sym = car(obj);
+ if (sym == promise_s || sym == promise_forced_s)
+ return t;
+ }
+
+ return nil;
+}
+
static val force(val promise)
{
loc pstate = car_l(promise);
@@ -4692,6 +4703,7 @@ void eval_init(void)
reg_fun(intern(lit("pad"), user_package), func_n3o(pad, 1));
reg_fun(intern(lit("weave"), user_package), func_n0v(weavev));
reg_fun(force_s, func_n1(force));
+ reg_fun(intern(lit("promisep"), user_package), func_n1(promisep));
reg_fun(intern(lit("rperm"), user_package), func_n2(rperm));
reg_fun(intern(lit("perm"), user_package), func_n2o(perm, 1));
reg_fun(intern(lit("comb"), user_package), func_n2(comb));
diff --git a/txr.1 b/txr.1
index 6e612436..9b6d6490 100644
--- a/txr.1
+++ b/txr.1
@@ -15624,6 +15624,27 @@ the promise will take on the value of
.meta expression
or the assigned value.
+.coNP Function @ promisep
+.synb
+.mets (promisep << object )
+.syne
+.desc
+The
+.code promisep
+function returns
+.code t
+if
+.meta object
+is a promise object: an object created by the
+.code delay
+macro. Otherwise it returns
+.codn nil .
+
+Note: promise objects are conses. The
+.code typeof
+function applied to a promise returns
+.codn cons .
+
.coNP Macro @ mlet
.synb
.mets (mlet >> ({ sym | >> ( sym << init-form )}*) << body-form *)