help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Dictionary>>#addAll: fails


From: Stephen Compall
Subject: Re: [Help-smalltalk] Dictionary>>#addAll: fails
Date: Fri, 23 Mar 2007 13:55:29 -0500

On Fri, 2007-03-23 at 15:26 +0100, Paolo Bonzini wrote:
> One possibility could be to extend the {...} syntax to something
> like "OrderedCollection {...}", "Dictionary {...}", and have it send
> messages like "#braceWithAll:".  Then you would have:

I would rather leave the syntax alone and just add the protocol:

<collection factory> >> withBraced: anArray
    Convert anArray to an instance of the receiver.
    anArray is structured such that the instance can be conveniently
    and fully specified using brace-syntax, possibly by imposing some
    additional structure on anArray.

I feel that this protocol specifies what we want from a semi-literal
syntax, without closing off too many possibilities.  withStructure: may
be a better name than the perhaps too specific withBraced:, though the
latter has the advantage of putting the writer in the right mindset to
produce the semantics intended by the protocol.  I'll prefer
withBraced:.

>      Array >> braceWithAll: x
>          ^self
> 
>      Collection >> braceWithAll: x
>          ^self withAll: x
> 
>      Dictionary >> braceWithAll: x
>          | dict |
>          dict := self new: x size * 2.
>          "in the loop we want 'self add: x' maybe?"
>          x do: [ :each | dict at: x key put: x value ].
>          ^dict

I like these as they are, except for the * 2 in Dictionary's method.

-- 
;;; Stephen Compall ** http://scompall.nocandysw.com/blog **
"Peta" is Greek for fifth; a petabyte is 10 to the fifth power, as
well as fifth in line after kilo, mega, giga, and tera.
  -- Lee Gomes, performing every Wednesday in his tech column
     "Portals" on page B1 of The Wall Street Journal

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]