On Mon, 2007-03-26 at 09:21 +0200, Paolo Bonzini wrote:
> > I would rather leave the syntax alone and just add the protocol:
> 
> What about adding #from: ?  I want it to be terse and still clear if
> possible.

smalltalk--backstage--2.2--patch-14, diff attached.

-- 
;;; Stephen Compall ** http://scompall.nocandysw.com/blog **
Failure to imagine vast possibilities usually stems from a lack of
imagination, not a lack of possibility.
2007-03-29  Stephen Compall  <[EMAIL PROTECTED]>

	* kernel/Collection.st: Add and describe class from: protocol.
	* kernel/Array.st: Specialize from:.
	* kernel/Dictionary: Same.

--- orig/kernel/Array.st
+++ mod/kernel/Array.st
@@ -46,6 +46,14 @@
 and general access behavior from SequenceableCollection.' !
 
 
+!Array class methodsFor: 'instance creation'!
+
+from: anArray
+    "Answer anArray, which is expected to be an array specified with a
+     brace-syntax expression per my inherited protocol."
+    ^anArray
+! !
+
 !Array methodsFor: 'printing'!
 
 printOn: aStream
--- orig/kernel/Collection.st
+++ mod/kernel/Collection.st
@@ -51,6 +51,14 @@
 
 !Collection class methodsFor: 'instance creation'!
 
+from: 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."
+    ^self withAll: anArray
+!
+
 withAll: aCollection
     "Answer a collection whose elements are all those in aCollection"
     ^self new addAll: aCollection; yourself
--- orig/kernel/Dictionary.st
+++ mod/kernel/Dictionary.st
@@ -49,6 +49,16 @@
 
 !Dictionary class methodsFor: 'instance creation'!
 
+from: anArray
+    "Answer a new dictionary created from the keys and values of
+     Associations in anArray, such as {1 -> 2. 3 -> 4}.  anArray
+     should be specified using brace-syntax."
+    | inst |
+    inst := self new: anArray size.
+    anArray do: [:assoc | inst at: assoc key put: assoc value].
+    ^inst
+!
+
 new
     "Create a new dictionary with a default size"
     "Builtins defines a #new method, so that during bootstrap there is a way

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

_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to