Hi Joe, the core of the question is here what you actually stored in the index.
Perhaps it helps if I try to explain the 'idx' structure. Each node in an 'idx' tree consists either of one (if it is a leaf node) or two (if it is an internal node) cells. The first cell holds the payload data in the CAR, and a pointer to the second cell (if any) in the CDR. The second cell holds pointers to the left and right subtrees. The 'idx' function treats the payload data as a key. It is up to the application what to do with that, like storing data there directly, or storing a (typically transient) symbol as a _key_, while the value of that symbol holds a _value_. > (de Sum () > (zero Amount) > (bench > (for This SL > (let (Key (: CustNum) Amt (: Amount) Idx (idx 'A Key)) In general, 'idx' returns the first cell of a node (which effectively means that it returns the whole subtree). The question is what the cell returned by (idx 'A Key) in your case contains. The line > (ifn (num? (val (car Idx))) (set (car Idx) 0)) makes me believe that the cell's CAR holds a 'var' (symbol or cell), whose value is checked for a number: (num? (val (car Idx))) The same here > (set (car Idx) (+ (val (car Idx)) Amt)) ) ) ) The value of the 'var' in the CAR is taken, and the incremented value stored there. Note that you can write that a bit simpler (inc (car Idx) Amt) So the above assumes that the payload is a 'var' (symbol or cell). The statement > (sum '((X) (car X)) (idx 'A)) ) retrieves all payload items (symbols or cells), takes their values ('car' in this case, so it seems to be cells), and sums them up. This looks all right. Note that the function wrapper is not needed, as ((X) (foo X)) is a tautology (sum car (idx 'A)) (is "tautology" the right term?) > I don't know exactly how to phrase the question. I'm storing the total in > the val of the cell (I think). I would have thought it was in the val of >From the above, you don't store it in the val (i.e. the CAR) of the tree nodes, but in the cells contained therein. This also looks correct. > Here's a simple example that I used to understand the concept: > > : (setq Z "abc") > -> "abc" > : (val Z) > -> "abc" Are you aware that you evaluated twice here? (val 'Z) gives "abc", and then you applied 'val' to it, giving "abc" again because transient symbols point to themselves initially. > : (set Z 0) > -> 0 Now you have set the value of the symbol "abc" to zero. You could test that with : "abc" -> 0 > : (val Z) > -> 0 > : (set Z (+ (val Z) 1)) > -> 1 or simply: (inc Z) > : (val Z) > -> 1 > : Z > -> "abc" OK Concerning the above 'idx' troubles, I suggest that you build a small 'idx' tree, and look at it interactively, perhaps also with (edit 'Idx). Cheers, - Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe