diff options
Diffstat (limited to 'cppawk-cons.1')
-rw-r--r-- | cppawk-cons.1 | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/cppawk-cons.1 b/cppawk-cons.1 index 2c11c4d..4b22827 100644 --- a/cppawk-cons.1 +++ b/cppawk-cons.1 @@ -2310,6 +2310,49 @@ is returned. list_end_atom(\fIbag\fP, 3) -> ("a" 1 2 . 3) .ft R +.SS Macro \fIbags\fP +.bk +Syntax: + +.ft B + bags (\fIb1\fP, \fIb2\fP, ...) \fIstatement\fP + bag (\fIbag\fP, \fIitem\fP) +.ft R + +The +.B bags +macro initializes one or more variables to empty bag values. +Then it executes a statement. After the statement, the bag +variables are converted to lists. + +Within the +.IR statement , +the +.B bag +helper macro is used for collecting items into the bags. +The expression +.BI bag( b ", " item ) +is a shorthand for +.IB b " = list_add(" b ", " item )\fR.\fP + +.B Example: + +.ft B + bags (\fIvals\fP, \fIsquares\fP, \fIsums\fP) { + \fIacc\fP = 0 + for (\fIi\fP = 0; \fIi\fP < 5; \fIi\fP++) { + bag (\fIvals\fP, \fIi\fP) + bag (\fIsquares\fP, \fIi\fP*\fIi\fP) + bag (\fIsums\fP, \fIacc\fP += \fIi\fP) + } + } + + \fI// the bags variables are now\fP + \fIvals\fP -> (0 1 2 3 4) + \fIsquares\fP -> (0 1 4 9 16) + \fIsums\fP -> (0 1 3 6 10) +.ft R + .SH "SEE ALSO" cppawk(1), cppawk-fun(1) |