diff options
-rw-r--r-- | cppawk-cons.1 | 9 | ||||
-rw-r--r-- | cppawk-include/cons-priv.h | 5 | ||||
-rw-r--r-- | cppawk-include/cons.h | 1 | ||||
-rw-r--r-- | testcases-cons | 4 |
4 files changed, 18 insertions, 1 deletions
diff --git a/cppawk-cons.1 b/cppawk-cons.1 index bdbbc5b..215d669 100644 --- a/cppawk-cons.1 +++ b/cppawk-cons.1 @@ -59,6 +59,7 @@ cons \- Lisp-like data representation and control flow macros box(av) // convert Awk number or string Lisp value. unbox(lv) // convert Lisp value to Awk number or string. + box_str(av) // create Lisp boxed string from Awk value av box_sym(av) // create Lisp symbol named av cons(a, d) // create cons cell with car = a and cdr = d. @@ -605,13 +606,14 @@ to distinguish numbers from non-numbers. symbolp("Sabc") -> 1 // manually produced symbol abc .ft R -.SS Functions \fIbox\fP, \fIunbox\fP and \fIbox_sym\fP +.SS Functions \fIbox\fP, \fIunbox\fP, \fIbox_str\fP and \fIbox_sym\fP .bk .B Syntax: .ft B box(av) unbox(lv) + box_str(av) box_sym(av) .ft R @@ -666,6 +668,11 @@ For any other value, prints a diagnostic message and terminates the process. The +.B box_str +function boxes an Awk value as a string, regardless of whether or +not it is numeric. + +The .B box_sym function boxes an Awk value .I av diff --git a/cppawk-include/cons-priv.h b/cppawk-include/cons-priv.h index 271d840..dae98c4 100644 --- a/cppawk-include/cons-priv.h +++ b/cppawk-include/cons-priv.h @@ -212,6 +212,11 @@ function __unbox(__obj, } } +function __box_str(__str) +{ + return "T" __str +} + function __box_sym(__name) { return __name == "nil" ? nil : "S" __name diff --git a/cppawk-include/cons.h b/cppawk-include/cons.h index 57e23c6..560784a 100644 --- a/cppawk-include/cons.h +++ b/cppawk-include/cons.h @@ -57,6 +57,7 @@ #define symbolp __symbolp #define box __box #define unbox __unbox +#define box_str __box_str #define box_sym __box_sym #define cons __cons #define car __car diff --git a/testcases-cons b/testcases-cons index b4352ae..99c150b 100644 --- a/testcases-cons +++ b/testcases-cons @@ -216,10 +216,14 @@ $cppawk ' BEGIN { print box_sym(undef), box_sym(1), box_sym("1a"), box_sym(0), box_sym(-1.34) print "A" box_sym("nil") "B", box_sym("abc"), box_sym("()") + print box_str(undef), box_str(1), box_str("1a"), box_str(0), box_str(-1.34) + print "A" box_str("nil") "B", box_str("abc"), box_str("()") }' : S S1 S1a S0 S-1.34 AB Sabc S() +T T1 T1a T0 T-1.34 +ATnilB Tabc T() -- 16: $cppawk ' |