Unary + appends zero to lists. Example: acid: +{} {0x00000000} acid: +{1} {0x00000001, 0x00000000} acid: defn x() { return {1} ; } acid: +x() {0x00000001, 0x00000000} Cause: The parser converts '+x' to 'x+0'. Such is reasonable for numeric arguments and has no effect on strings. Unfortunately for lists, it results in a zero being appended. This patch: The parser converts '+x' to 'x+ZN' and oadd() handles the ZN rhs when the expression is evaluated. Patched: acid: +{} acid: +{1} {0x00000001} acid: defn x() { return {1} ; } acid: +x() {0x00000001} Reference: /n/sources/patch/applied/acid.unary-plus-list-fix Date: Tue Feb 6 17:20:47 CET 2007 Signed-off-by: philip.dye@cs.cmu.edu --- /sys/src/cmd/acid/dbg.y Tue Feb 6 17:20:41 2007 +++ /sys/src/cmd/acid/dbg.y Tue Feb 6 17:29:36 2007 @@ -281,8 +281,7 @@ } | '+' monexpr { - $$ = con(0); - $$ = an(OADD, $2, $$); + $$ = an(OADD, $2, ZN); } | '-' monexpr { --- /sys/src/cmd/acid/expr.c Tue Feb 6 17:20:44 2007 +++ /sys/src/cmd/acid/expr.c Tue Feb 6 17:29:36 2007 @@ -202,12 +202,20 @@ oappend(Node *n, Node *res) { Node r, l; + int empty ; expr(n->left, &l); expr(n->right, &r); if(l.type != TLIST) error("must append to list"); + empty = ( l.l == nil && ( n->left->op == ONAME ) ) ; append(res, &l, &r); + if ( empty ) { + Value * v = n->left->sym->v ; + v->type = res->type ; + v->Store = res->Store ; + v->comt = res->comt ; + } } void @@ -325,7 +333,18 @@ Node l, r; expr(n->left, &l); - expr(n->right, &r); + if ( n->right != ZN ) { + expr(n->right, &r) ; + } else { + switch ( l.type ) { + default: + expr(con(0),&r) ; + break; + case TSTRING: + case TLIST: + break; + } + } res->fmt = l.fmt; res->op = OCONST; res->type = TFLOAT; @@ -358,6 +377,10 @@ } break; case TSTRING: + if ( n->right == ZN ) { + *res = l ; + break ; + } if(r.type == TSTRING) { res->type = TSTRING; res->fmt = 's'; @@ -372,6 +395,10 @@ } error("bad rhs for +"); case TLIST: + if ( n->right == ZN ) { + *res = l ; + break ; + } res->type = TLIST; switch(r.type) { case TLIST: