On Mon, Nov 7, 2011 at 3:46 PM, Nicolas Cellier < [email protected]> wrote:
> 2011/11/8 Eliot Miranda <[email protected]>: > > > > > > On Mon, Nov 7, 2011 at 3:21 PM, Markus Rother <[email protected] > > > > wrote: > >> > >> On 11/07/2011 11:08 PM, Stéphane Ducasse wrote: > >> > >> The issue I could not solve on my own is this: > >> I would like to instantiate from symbols. My use-case is a collection of > >> class names which I want to ask to return one instance each. > >> > >> why are you trying to do? > >> because symbols are not done to be instantiated like that. > >> > >> aString asSymbol is instantiating symbols for you. > >> > >> Stef > >> > >> Thanks everybody for the kind, plenty and swift replies. > >> > >> Here is what I was up to: > >> > >> ChessBoard class>>newGame > >> | newBoard | > >> ... > >> firstRow := #(Rook Knight Bishop Queen King Bishop Knight Rook). > >> 1 to: 8 do: [ :col | > >> (newBoard at: 1 at: col) putFigure: (firstRow at: col) asClass > >> newWhite > >> ]. > >> ... > >> > >> Symbol>>asClass > >> ^(Smalltalk classNamed: self) > >> > >> I don't see how a string representation would have helped me here...? > >> Although, I am a noob, my intuition tells me that symbols are absolutely > >> fine, here - especially considering they are used precisely for that > purpose > >> internally. > > > > But so is > > > > ChessBoard class>>newGame > > | newBoard | > > ... > > firstRow := {Rook. Knight. Bishop. Queen. King. Bishop. Knight. > Rook}. > > 1 to: 8 do: [ :col | > > (newBoard at: 1 at: col) putFigure: (firstRow at: col) newWhite > > ]. > > ... > > as could be > > newBoard > > at: 1 put: ({Rook. Knight. Bishop. Queen. King. Bishop. Knight. > > Rook} collect: [:class| class newWhite]; > > at: 2 put: (1 to: 8) collect: [:ign| Pawn newWhite]; > > atAll: (3 to: 6) put: (Array new: 8); > > Then avoid statefull operations like > ((board at; i) at: j) put: move. > because you just shared some rows. > > ;) > <blush>oops</blush>. Quite so. So... newBoard at: 1 put: ({Rook. Knight. Bishop. Queen. King. Bishop. Knight. Rook} collect: [:class| class newWhite]; at: 2 put: (1 to: 8) collect: [:ign| Pawn newWhite]; atAll: (3 to: 6) putAll: ((3 to: 6) collect: [:ign| Array new: 8]); at: 7 put: (1 to: 8) collect: [:ign| Pawn newBlack]; at: 8 put: ({Rook. Knight. Bishop. Queen. King. Bishop. Knight. Rook} collect: [:class| class newBlack] > > Nicolas > > > at: 7 put: (1 to: 8) collect: [:ign| Pawn newBlack]; > > at: 8 put: ({Rook. Knight. Bishop. Queen. King. Bishop. Knight. > > Rook} collect: [:class| class newBlack] > >> > >> Greets, > >> Markus > > > > > > > > -- > > best, > > Eliot > > > > -- best, Eliot
