On 16/12/2007, <b class="gmail_sendername">Dominic Chambers</b> <<a href="mailto:dominic.chambers@gmail.com">dominic.chambers@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Yes, the following gives me a character instead of a number (I put a<br>number in but I got a character out -- which may, as you say, be<br>identical anyway):<br><br> dict:fetch("Key", dict:append("Key", 33, dict:new())).
<br><br>but then the problem I get is that if I try to add 1 to that number I<br>get a badarith error:<br><br> dict:fetch("Key", dict:append("Key", 33, dict:new())) + 1.<br><br>I have just made misunderstood what is happening here?
</blockquote><div><br>As matthias said dict:append and dict:store are different. Dict:store stores the value under the key while dict:append appends the new value to a list of the existing values. If there are no values then the new value is automatically put in a list. So you get:
<br><br>1> dict:fetch("Key", dict:store("Key", 33, dict:new())). <br>33<br>2> dict:fetch("Key", dict:append("Key", 33, dict:new())).<br>"!"<br>3> dict:fetch("Key", dict:append("Key", 35, dict:append("Key", 33, dict:new()))).
<br>"!#"<br>4><br><br>Dict:fetch (and dict:find) always return the whole value which might be a list of values or one value.<br><br>Robert<br><br>P.S. Dict:append will also make a list of value which is already there and not a list. This is probably a mistake, but we were trying to be nice. Better to be consistent than nice.
<br><br>P.P.S. Orddict has exactly the same interface but the dictionary is easier to understand when printed.<br><br><br></div></div>