Administrator
|
I'm subclassing ArrayedCollection while coding the examples from A Mentoring Course in Smalltalk, but I can't figure out how to create one!
ClassBasedCharacterArray is a subclass of ArrayedCollection ClassBasedCharacterArray newFrom: 'a string' -> error: ClassBasedCharacterArray cannot have variable sized instances. Huh? Behavior class>>new: calls Behavior class>>basicNew: which calls Behavior class>>isVariable which returns false. How does string get around this to create instances? I DebugIt-ed 'a string', but couldn't follow it in the debugger for some reason. Thanks. Sean
Cheers,
Sean |
what do you want to do?
what is the example? Stef > I'm subclassing ArrayedCollection while coding the examples from A Mentoring > Course in Smalltalk, but I can't figure out how to create one! > > ClassBasedCharacterArray is a subclass of ArrayedCollection > ClassBasedCharacterArray newFrom: 'a string' -> error: > ClassBasedCharacterArray cannot have variable sized instances. Huh? > > Behavior class>>new: calls Behavior class>>basicNew: which calls Behavior > class>>isVariable which returns false. > > How does string get around this to create instances? I DebugIt-ed 'a > string', but couldn't follow it in the debugger for some reason. > > Thanks. > Sean > -- > View this message in context: http://forum.world.st/Creating-ArrayedCollections-tp2714552p2714552.html > Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. > > _______________________________________________ > Pharo-users mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
Administrator
|
I want to write 'a string' asCondensedCharacterArray where CondensedCharacterArray is a subclass of ClassBasedCharacterArray which is a subclass of ArrayedCollection. In the book, it inherits from CharacterArray, which was the parent class of String in his system. His implementation was: CharacterArray>>asCondensedClassBasedCharacterArray | answer | answer := CondensedClassBasedCharacterArray new: self size. 1 to: self size do: [ :each | answer at: each put: (self at: each) asCondensedClassBasedCharacter ]. ^ answer. But when I put this in ArrayedCollection, I get the error I mentioned. Sean
Cheers,
Sean |
In reply to this post by Sean P. DeNigris
Am 2010-09-26 um 19:53 schrieb Sean P. DeNigris:
> I'm subclassing ArrayedCollection while coding the examples from A Mentoring > Course in Smalltalk, but I can't figure out how to create one! > > ClassBasedCharacterArray is a subclass of ArrayedCollection > ClassBasedCharacterArray newFrom: 'a string' -> error: > ClassBasedCharacterArray cannot have variable sized instances. Huh? > > Behavior class>>new: calls Behavior class>>basicNew: which calls Behavior > class>>isVariable which returns false. > > How does string get around this to create instances? I DebugIt-ed 'a > string', but couldn't follow it in the debugger for some reason. Sean, how did you subclass from ArrayedCollection? So Long, -Tobias _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
It has to do with the indexing type for what I see.
Don't know how that works exactly.
If using VisualWorks is as easy as changing the indexing type to Object at the NewClass wizard in the advanced properties. Although I don't know what that actually does, but it fix the problem.
I don't know how to achieve that same thing in Pharo. But knowing that maybe someone with real knowledge can help.
The problem is: class Foo sublcasing ArrayedCollection Foo>>mynew ^super new: 10. The Error ' cannot have variable sized instances' is launched in Beahavior Behavior>>basicNew: sizeRequested
"Primitive. Answer an instance of this class with the number of indexable variables specified by the argument, sizeRequested.
Fail if this class is not indexable or if the argument is not a positive Integer, or if there is not enough memory available.
Essential. See Object documentation whatIsAPrimitive." <primitive: 71>
self isVariable ifFalse: [self error: self printString, ' cannot have variable sized instances'].
(sizeRequested isInteger and: [sizeRequested >= 0]) ifTrue: ["arg okay; space must be low."
OutOfMemory signal. ^ self basicNew: sizeRequested "retry if user proceeds"].
self primitiveFailed I try redefining isVariable so it returns true, but then the error of OutOfMemory raises.
Sorry for not being of much help, I've just started with Pharo, and I'm really used to VW (Where you don't actually know whats going on) so I still can't do much in Pharo. -- Alan Rodas Bonjour _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
Administrator
|
In reply to this post by Tobias Pape
ArrayedCollection subclass: #ClassBasedCharacterArray instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Mentoring Course'
Cheers,
Sean |
Am 2010-09-26 um 22:04 schrieb Sean P. DeNigris:
> Tobias Pape wrote: >> >> how did you subclass from ArrayedCollection? >> > > ArrayedCollection subclass: #ClassBasedCharacterArray > instanceVariableNames: '' > classVariableNames: '' > poolDictionaries: '' > category: 'Mentoring Course' Sean, try to use ArrayedCollection variableSubclass: #ClassBasedCharacterArray instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Collections-Arrayed' (as in Array.) As Alan Rodas points out, if the class isn't variable, #new: cannot be used. Hope that helps. So Long, -Tobias _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
Administrator
|
Thanks. Where can I read about what's actually happening here? I've never heard of this alternate subclass method, and I'm running into other problems. Sean
Cheers,
Sean |
Am 2010-09-26 um 23:26 schrieb Sean P. DeNigris:
> Tobias Pape wrote: >> >> try to use >> >> ArrayedCollection variableSubclass: #ClassBasedCharacterArray >> instanceVariableNames: '' >> classVariableNames: '' >> poolDictionaries: '' >> category: 'Collections-Arrayed' >> >> (as in Array.) >> As Alan Rodas points out, if the class isn't variable, #new: cannot be >> used. >> > > Thanks. Where can I read about what's actually happening here? I've never > heard of this alternate subclass method, and I'm running into other > problems. > > Sean From gnu-smalltalk, but most should apply: http://www.gnu.org/software/smalltalk/manual/html_node/Inside-Arrays.html#Inside-Arrays in the blue book, i only found two references to variableSubclass. On page 289 is a little explanation, don't know if that suffices. So Long, -Tobias _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
In reply to this post by Sean P. DeNigris
I would look at how Array or OrderedCollection is defined. Some objects
only have instance variables, and some have instance variables and indexed slots (the so-called "variable" property of classes, perhaps better described in terms of instances being "indexable" via basicAt:/basicAt:put:). So, from what I've read so far, the problem is that the class ClassBasedCharacterArray is being defined as "non-indexable", and so you can't use new:. Now, originally, I subclassed CharacterArray because then I'd inherit useful methods such as nice printString and what not. Strictly speaking, however, any sort of "array" should do for what the book is trying to show. If you want, you can also use the NC version of VisualWorks to get the code going. Finally, one of my to-dos is to convert my implementation to use Assessments for its tests. I think it would be easier to release a sort of official version in the public Store repository then. Alas, so much to do, so little time. In the mean time, let me know if you need the MIT license to appear somewhere. Andres. On 9/26/10 14:26 , Sean P. DeNigris wrote: > > > Tobias Pape wrote: >> >> try to use >> >> ArrayedCollection variableSubclass: #ClassBasedCharacterArray >> instanceVariableNames: '' >> classVariableNames: '' >> poolDictionaries: '' >> category: 'Collections-Arrayed' >> >> (as in Array.) >> As Alan Rodas points out, if the class isn't variable, #new: cannot be >> used. >> > > Thanks. Where can I read about what's actually happening here? I've never > heard of this alternate subclass method, and I'm running into other > problems. > > Sean _______________________________________________ Pharo-users mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users |
Administrator
|
In reply to this post by Tobias Pape
Thanks. I also found http://www.iam.unibe.ch/~ducasse/Web/BotsInc/ExtraChapter-Syntax.pdf, which shed some light. Sean
Cheers,
Sean |
Free forum by Nabble | Edit this page |