The Artima Developer Community
Sponsored Link

Agile Buzz Forum
The Nil Set

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
The Nil Set Posted: Aug 13, 2004 5:39 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: The Nil Set
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement
While the VisualWorks Development list is hot with the parcels topic and comp.lang.smalltalk and various blogs rage with the "type war", there's an interesting discussion about Sets and nil over in the Squeak list. I've never really thought about it, but I'm inclined to say that Set's should be able to contain nil. The expression (Set withAll: (Array new: 5)) size ought to return 1. Not 0. And the expression (Bag withAll: (Array new: 5)) size should return 5. Not 0.

VisualWorks and some of the other mainstream Smalltalks don't allow nil to be used in Sets or Dictionaries. It's not that allowing/disallowing nil is necessarily right, it's that its the easy thing.

When an object that contains other objects is created, all of its slots are populated by default with nil. The VM does this quickly and efficiently. Behind the scenes, a Set is just an Array with some of its slots populated. So to begin with, it's some arbitrary sized array with nil slots. As objects are added, their hash index is computed, and they are placed in the array. When they're removed, the slot is set back to nil. To avoid using nil, we'd have to create another arbitrary object to use to indicate "the empty slot". Then nil could be used as a first class element of a Set. Or as a first class key for a Dictionary which subclasses Set.

I thought I'd look at what it would take to switch VisualWorks. But a report of how that goes, can be its own blog. I find that long blogs are.... well.... long.

Read: The Nil Set

Topic: Engineering in Software? Previous Topic   Next Topic Topic: VM implementations

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use