Arc Forumnew | comments | leaders | submitlogin
5 points by randallsquared 4249 days ago | link | parent

Seems like it wouldn't be hard to add defaults to the hash referencing (and string referencing), to allow (++ (table k 0)) which seems much nicer than the CL version, in my opinion.

Edit: Actually, not string and array referencing, since defaults don't matter for that, and there's a much more useful meaning for that: slices.



6 points by pg 4249 days ago | link

I might do it that way, but it seems cleaner to do it when hash tables are created.

-----

5 points by randallsquared 4249 days ago | link

Only if every key is a similar type. The default that's most appropriate is often peculiar to how you're using the value or location at the use site.

-----

2 points by lg 4249 days ago | link

speaking of hash tables, I remember in ACL you explained why CL has two return values for gethash, to differentiate between the nil meaning "X is stored as nil in my table" and the nil meaning "X is not stored in my table". So why not in Arc?

-----

2 points by pg 4248 days ago | link

Because it turns out that in practice it's rarely to never an issue. If you have nil as a val in a hash table, you usually don't care whether that's because it was never set, or explicitly set to nil.

-----

1 point by dr_drake 4243 days ago | link

Dear Paul, I can not believe you would make such a statement. Either you're living in a vastly different programming universe than the one I am living in, or you really haven't done that much programming at all. In any case, there are many situations where one stores types of values that may include nil in a hash table, and in most of these there is a very significant difference between 'value is nil' and 'value is not stored'. I understand that Arc isn't trying to all 'enterprisey', but these are fundamental concepts that, I thought, only complete amateurs did not understand. Sincerely, Dr. Drake

-----

2 points by pg 4243 days ago | link

You know, I do actually understand the difference between the two cases. What I'm saying is that in my experience hash tables that actually need to contain nil as a value are many times less common than those that don't.

In situations where the values you're storing might be nil, you just enclose all the values in lists.

My goal in Arc is to have elegant solutions for the cases that actually happen, at the expense of elegance in solutions for rare edge cases.

-----

1 point by mschw 4245 days ago | link

Python's defaultdict takes a factory function at construction time.

http://docs.python.org/lib/defaultdict-objects.html

-----