Best way to implement two-dimensional array

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Best way to implement two-dimensional array

John Almberg
This is a smalltalk question, but hopefully not too off-topic...

I need a lookup table object... something to which I can send a  
message like:

anElement := myTable index1: #aSymbol index2: #anotherSymbol

The underlying structure is actually a table... rows and columns...  
and I want to be able to fetch elements in the table.

I am thinking myTable should hold a dictionary of dictionaries, (a  
hash of hashes, I might say if using another language), but I am  
wondering if there is a more smalltalk-ish way to do this?

Any suggestions much appreciated.

-- John



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

John Almberg
Sorry... forgot one other thing... I'd like to be able to initialize  
the table using a literal, like:

#( #(1 4 3)
    #(4 3 6)
    #(9 5 4) )

That would be a real bonus, because the table is quite large and I  
want to be able to 'see' the table in the source code so I can change  
it easily.

-- John

On Sep 2, 2007, at 8:45 AM, John Almberg wrote:

> This is a smalltalk question, but hopefully not too off-topic...
>
> I need a lookup table object... something to which I can send a  
> message like:
>
> anElement := myTable index1: #aSymbol index2: #anotherSymbol
>
> The underlying structure is actually a table... rows and columns...  
> and I want to be able to fetch elements in the table.
>
> I am thinking myTable should hold a dictionary of dictionaries, (a  
> hash of hashes, I might say if using another language), but I am  
> wondering if there is a more smalltalk-ish way to do this?
>
> Any suggestions much appreciated.
>
> -- John
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Websites for On-line Collectible Dealers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Identry, LLC
John Almberg
(631) 546-5079
[hidden email]
www.identry.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

Karl-19
Look at class Matrix

Karl


John Almberg wrote:

> Sorry... forgot one other thing... I'd like to be able to initialize
> the table using a literal, like:
>
> #( #(1 4 3)
>    #(4 3 6)
>    #(9 5 4) )
>
> That would be a real bonus, because the table is quite large and I
> want to be able to 'see' the table in the source code so I can change
> it easily.
>
> -- John
>
> On Sep 2, 2007, at 8:45 AM, John Almberg wrote:
>
>> This is a smalltalk question, but hopefully not too off-topic...
>>
>> I need a lookup table object... something to which I can send a
>> message like:
>>
>> anElement := myTable index1: #aSymbol index2: #anotherSymbol
>>
>> The underlying structure is actually a table... rows and columns...
>> and I want to be able to fetch elements in the table.
>>
>> I am thinking myTable should hold a dictionary of dictionaries, (a
>> hash of hashes, I might say if using another language), but I am
>> wondering if there is a more smalltalk-ish way to do this?
>>
>> Any suggestions much appreciated.
>>
>> -- John
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Websites for On-line Collectible Dealers
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Identry, LLC
> John Almberg
> (631) 546-5079
> [hidden email]
> www.identry.com
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

John Almberg
In reply to this post by John Almberg
H'mmm... *is* there a way to create a dictionary literal? I can't  
seem to find an example....

-- John


On Sep 2, 2007, at 9:00 AM, John Almberg wrote:

> Sorry... forgot one other thing... I'd like to be able to  
> initialize the table using a literal, like:
>
> #( #(1 4 3)
>    #(4 3 6)
>    #(9 5 4) )
>
> That would be a real bonus, because the table is quite large and I  
> want to be able to 'see' the table in the source code so I can  
> change it easily.
>
> -- John
>
> On Sep 2, 2007, at 8:45 AM, John Almberg wrote:
>
>> This is a smalltalk question, but hopefully not too off-topic...
>>
>> I need a lookup table object... something to which I can send a  
>> message like:
>>
>> anElement := myTable index1: #aSymbol index2: #anotherSymbol
>>
>> The underlying structure is actually a table... rows and  
>> columns... and I want to be able to fetch elements in the table.
>>
>> I am thinking myTable should hold a dictionary of dictionaries, (a  
>> hash of hashes, I might say if using another language), but I am  
>> wondering if there is a more smalltalk-ish way to do this?
>>
>> Any suggestions much appreciated.
>>
>> -- John
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Websites for On-line Collectible Dealers
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Identry, LLC
> John Almberg
> (631) 546-5079
> [hidden email]
> www.identry.com
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Websites for On-line Collectible Dealers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Identry, LLC
John Almberg
(631) 546-5079
[hidden email]
www.identry.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

Bert Freudenberg
No, but this comes close:

{'key1'->'value1'. 'key2'->'value2'} as: Dictionary.

- Bert -

On Sep 2, 2007, at 12:00 , John Almberg wrote:

> H'mmm... *is* there a way to create a dictionary literal? I can't  
> seem to find an example....
>
> -- John
>
>
> On Sep 2, 2007, at 9:00 AM, John Almberg wrote:
>
>> Sorry... forgot one other thing... I'd like to be able to  
>> initialize the table using a literal, like:
>>
>> #( #(1 4 3)
>>    #(4 3 6)
>>    #(9 5 4) )
>>
>> That would be a real bonus, because the table is quite large and I  
>> want to be able to 'see' the table in the source code so I can  
>> change it easily.
>>
>> -- John
>>
>> On Sep 2, 2007, at 8:45 AM, John Almberg wrote:
>>
>>> This is a smalltalk question, but hopefully not too off-topic...
>>>
>>> I need a lookup table object... something to which I can send a  
>>> message like:
>>>
>>> anElement := myTable index1: #aSymbol index2: #anotherSymbol
>>>
>>> The underlying structure is actually a table... rows and  
>>> columns... and I want to be able to fetch elements in the table.
>>>
>>> I am thinking myTable should hold a dictionary of dictionaries,  
>>> (a hash of hashes, I might say if using another language), but I  
>>> am wondering if there is a more smalltalk-ish way to do this?
>>>
>>> Any suggestions much appreciated.
>>>
>>> -- John




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

Blake-5
In reply to this post by John Almberg
John,

        You know, I've asked this a number of times and there's a neglected 2D  
array class, but I've found you don't really need it. You can just use a  
dictionary:

        aDict at:x@y put:anObject
        anObject := aDict at:x@y

        It sort of rubs me the wrong way but it's workable.

        ===Blake===

On Sun, 02 Sep 2007 05:45:42 -0700, John Almberg <[hidden email]>  
wrote:

> This is a smalltalk question, but hopefully not too off-topic...
>
> I need a lookup table object... something to which I can send a message  
> like:
>
> anElement := myTable index1: #aSymbol index2: #anotherSymbol
>
> The underlying structure is actually a table... rows and columns... and  
> I want to be able to fetch elements in the table.
>
> I am thinking myTable should hold a dictionary of dictionaries, (a hash  
> of hashes, I might say if using another language), but I am wondering if  
> there is a more smalltalk-ish way to do this?
>
> Any suggestions much appreciated.
>
> -- John
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

John Almberg
In reply to this post by Bert Freudenberg
Ah... Now that's handy. Though it's not clear, at first glance, how  
it works...

Those curly braces aren't standard Smalltalk, are they? I need to  
Google them.

Anyway, thanks for the tip. That will make life much easier... I was  
starting to think my table initialization was going to have a lot of  
add: statements...

-- John


On Sep 2, 2007, at 3:05 PM, Bert Freudenberg wrote:

> No, but this comes close:
>
> {'key1'->'value1'. 'key2'->'value2'} as: Dictionary.
>
> - Bert -
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

Bert Freudenberg
See

        http://www.mucow.com/squeak-qref.html#BraceArray

Another common way is to use a literal array #(...) and convert that  
into a Dictionary with a few statements. That way you use only a  
single literal.

- Bert -


On Sep 2, 2007, at 19:54 , John Almberg wrote:

> Ah... Now that's handy. Though it's not clear, at first glance, how  
> it works...
>
> Those curly braces aren't standard Smalltalk, are they? I need to  
> Google them.
>
> Anyway, thanks for the tip. That will make life much easier... I  
> was starting to think my table initialization was going to have a  
> lot of add: statements...
>
> -- John
>
>
> On Sep 2, 2007, at 3:05 PM, Bert Freudenberg wrote:
>
>> No, but this comes close:
>>
>> {'key1'->'value1'. 'key2'->'value2'} as: Dictionary.
>>
>> - Bert -
>


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

John Almberg
H'mmm...

The only way I can figure out how to create a nested directory  
literal is to do this:

|t|
t := { #fs -> ({ #C -> 0. #B -> 1. #R -> 2 } as: Dictionary)  } as:  
Dictionary.
(t at: #fs) at: #B.  "Gives '1' when evaluated"

The parens are necessary, as far as I can figure.

Is there any simpler syntax than this? This is acceptable. Just  
wondering if there is a better way.

Or, I'm thinking it might be simpler to leave the literal as an  
array, and do the castings as necessary during access, like this:

|t|
"Create as simple array"
        t := { #fs -> { #C -> 0. #B -> 1. #R -> 0 } }.
"Access as dictionary"
        (((t as: Dictionary) at: #fs) as: Dictionary) at: #B.

The reason being, the actual table will be pretty big, and all those  
parens and :as Dictionary statements will clutter up the data.

By the way, I would never have figured this out without the Workspace  
to play in. Obviously I'm not the first to discover this, but Wow!  
Workspace is a great tool!

I have used Ruby's IRB to experiment with Ruby expressions, and  
interactive Perl and PHP a bit, but even IRB is no where near as  
useful as the Workspace. It's so simple... I wonder why other  
languages haven't adopted something like it?

-- John



On Sep 3, 2007, at 3:26 AM, Bert Freudenberg wrote:

> See
>
> http://www.mucow.com/squeak-qref.html#BraceArray
>
> Another common way is to use a literal array #(...) and convert  
> that into a Dictionary with a few statements. That way you use only  
> a single literal.
>
> - Bert -
>
>
> On Sep 2, 2007, at 19:54 , John Almberg wrote:
>
>> Ah... Now that's handy. Though it's not clear, at first glance,  
>> how it works...
>>
>> Those curly braces aren't standard Smalltalk, are they? I need to  
>> Google them.
>>
>> Anyway, thanks for the tip. That will make life much easier... I  
>> was starting to think my table initialization was going to have a  
>> lot of add: statements...
>>
>> -- John
>>
>>
>> On Sep 2, 2007, at 3:05 PM, Bert Freudenberg wrote:
>>
>>> No, but this comes close:
>>>
>>> {'key1'->'value1'. 'key2'->'value2'} as: Dictionary.
>>>
>>> - Bert -
>>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Websites for On-line Collectible Dealers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Identry, LLC
John Almberg
(631) 546-5079
[hidden email]
www.identry.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

Göran Krampe
Hi!

> H'mmm...
>
> The only way I can figure out how to create a nested directory
> literal is to do this:
>
> |t|
> t := { #fs -> ({ #C -> 0. #B -> 1. #R -> 2 } as: Dictionary)  } as:
> Dictionary.
> (t at: #fs) at: #B.  "Gives '1' when evaluated"
>
> The parens are necessary, as far as I can figure.
>
> Is there any simpler syntax than this? This is acceptable. Just
> wondering if there is a better way.

Mmmm, I feel I must ask the "why?" question here. :) What are you actually
trying to implement? The reason I ask is because it looks like you may be
falling into the trap of "data objects" (creating structures of data with
no real behaviors).

> Or, I'm thinking it might be simpler to leave the literal as an
> array, and do the castings as necessary during access, like this:

The word "casting" is not generally used in the Smalltalk context given
that Smalltalk is not statically typed. #as: is a message send and it
creates a new object of the given class. You can see what it does by
looking at Object>>as:.

> |t|
> "Create as simple array"
> t := { #fs -> { #C -> 0. #B -> 1. #R -> 0 } }.
> "Access as dictionary"
> (((t as: Dictionary) at: #fs) as: Dictionary) at: #B.
>
> The reason being, the actual table will be pretty big, and all those
> parens and :as Dictionary statements will clutter up the data.

You can do it in several ways - it's just "code". If you only need Symbols
and literals as above you could use regular Array syntax (it only
evaluates literals - not expressions - and it is constructed at compile
time):

| result dict |
result := Dictionary new.
#(
        (fs (C 0  B 1  R 0))
        (gs (C 7  B 5  R 4))
        (gs (C 7  B 5  R 4))
) do: [:arr |
        dict := Dictionary new.
        arr second pairsDo: [:a :b | dict at: a put: b].
        result at: arr first put: dict].
result

Do an inspect-it on that to see the resulting dicts-in-dict.

> By the way, I would never have figured this out without the Workspace
> to play in. Obviously I'm not the first to discover this, but Wow!
> Workspace is a great tool!
>
> I have used Ruby's IRB to experiment with Ruby expressions, and
> interactive Perl and PHP a bit, but even IRB is no where near as
> useful as the Workspace. It's so simple... I wonder why other
> languages haven't adopted something like it?

The mystery of Smalltalk *not* ruling the earth. Who knows? :)

regards, Göran

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

John Almberg
Hi Goran,

> Mmmm, I feel I must ask the "why?" question here. :) What are you  
> actually
> trying to implement? The reason I ask is because it looks like you  
> may be
> falling into the trap of "data objects" (creating structures of  
> data with
> no real behaviors).

Yes, that's an accurate description of what I'm trying to model: the  
Movement Table from a very complicated, 'age of sail' board game. The  
table models the speed of 9 classes of sailing ships at various wind  
speeds, sail settings, damage, and points of sail.

Thus it describes or summarizes some of the sailing attributes of  
these 9 classes of ships. I've studied the table to see if it could  
be computed, rather than simply stored, but I think the table  
summarizes empirical data gleaned from historical records, rather  
than a mathematical function, so not easy to model without a table.

I have use polymorphism to break the one massive table into 9 smaller  
tables, one in each of the 9 classes of ships (children of class Ship).

I'm storing them in a class variable and using it, more or less, as a  
constant lookup table. There isn't much behavior in the table itself,  
but it models behavior, if you see what I mean.

And there is plenty of other behavior in the ship classes, as you can  
imagine.

The real 'why' is fun. I've been wanting to learn Smalltalk and to  
program a game like this for about 25 years. With Squeak on a Mac,  
and a pile of Smalltalk books bought second-hand from Amazon, I'm  
making some progress. With the side benefit of learning some new  
tricks that help my Ruby programming (my day job).


>> Or, I'm thinking it might be simpler to leave the literal as an
>> array, and do the castings as necessary during access, like this:
>
> The word "casting" is not generally used in the Smalltalk context  
> given
> that Smalltalk is not statically typed. #as: is a message send and it
> creates a new object of the given class. You can see what it does by
> looking at Object>>as:.

Sorry... still learning the Smalltalk jargon.

> You can do it in several ways - it's just "code". If you only need  
> Symbols
> and literals as above you could use regular Array syntax (it only
> evaluates literals - not expressions - and it is constructed at  
> compile
> time):
>
> | result dict |
> result := Dictionary new.
> #(
> (fs (C 0  B 1  R 0))
> (gs (C 7  B 5  R 4))
> (gs (C 7  B 5  R 4))
> ) do: [:arr |
> dict := Dictionary new.
> arr second pairsDo: [:a :b | dict at: a put: b].
> result at: arr first put: dict].
> result

This is an interesting approach, too. I'm currently thinking that I  
don't really need to store the data as a dictionary... my main  
concern is to format the table(s) in a way that is easy for *me* to  
read (so I can find and fix the inevitable typos.)

I don't really care if the computer has to do some heavy lifting to  
*access* the data. It's not something that has to be fast. So I'm  
going to go for an approach that maximizes the human readability of  
the data, and pushes the complicated bits into the accessors.

Thanks!

-- John

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

Bert Freudenberg

On Sep 4, 2007, at 5:58 , John Almberg wrote:

> Hi Goran,
>
>> Mmmm, I feel I must ask the "why?" question here. :) What are you  
>> actually
>> trying to implement? The reason I ask is because it looks like you  
>> may be
>> falling into the trap of "data objects" (creating structures of  
>> data with
>> no real behaviors).
>
> Yes, that's an accurate description of what I'm trying to model:  
> the Movement Table from a very complicated, 'age of sail' board  
> game. The table models the speed of 9 classes of sailing ships at  
> various wind speeds, sail settings, damage, and points of sail.
>
> Thus it describes or summarizes some of the sailing attributes of  
> these 9 classes of ships. I've studied the table to see if it could  
> be computed, rather than simply stored, but I think the table  
> summarizes empirical data gleaned from historical records, rather  
> than a mathematical function, so not easy to model without a table.
>
> I have use polymorphism to break the one massive table into 9  
> smaller tables, one in each of the 9 classes of ships (children of  
> class Ship).
>
> I'm storing them in a class variable and using it, more or less, as  
> a constant lookup table. There isn't much behavior in the table  
> itself, but it models behavior, if you see what I mean.
>
> And there is plenty of other behavior in the ship classes, as you  
> can imagine.
>
> The real 'why' is fun. I've been wanting to learn Smalltalk and to  
> program a game like this for about 25 years. With Squeak on a Mac,  
> and a pile of Smalltalk books bought second-hand from Amazon, I'm  
> making some progress. With the side benefit of learning some new  
> tricks that help my Ruby programming (my day job).
>
>
>>> Or, I'm thinking it might be simpler to leave the literal as an
>>> array, and do the castings as necessary during access, like this:
>>
>> The word "casting" is not generally used in the Smalltalk context  
>> given
>> that Smalltalk is not statically typed. #as: is a message send and it
>> creates a new object of the given class. You can see what it does by
>> looking at Object>>as:.
>
> Sorry... still learning the Smalltalk jargon.
>
>> You can do it in several ways - it's just "code". If you only need  
>> Symbols
>> and literals as above you could use regular Array syntax (it only
>> evaluates literals - not expressions - and it is constructed at  
>> compile
>> time):
>>
>> | result dict |
>> result := Dictionary new.
>> #(
>> (fs (C 0  B 1  R 0))
>> (gs (C 7  B 5  R 4))
>> (gs (C 7  B 5  R 4))
>> ) do: [:arr |
>> dict := Dictionary new.
>> arr second pairsDo: [:a :b | dict at: a put: b].
>> result at: arr first put: dict].
>> result
>
> This is an interesting approach, too. I'm currently thinking that I  
> don't really need to store the data as a dictionary... my main  
> concern is to format the table(s) in a way that is easy for *me* to  
> read (so I can find and fix the inevitable typos.)
>
> I don't really care if the computer has to do some heavy lifting to  
> *access* the data. It's not something that has to be fast. So I'm  
> going to go for an approach that maximizes the human readability of  
> the data, and pushes the complicated bits into the accessors.

Well, since you are storing it in a class var, the "heavy lifting"  
can be done at initialization time. This way the code remains  
readable but you can do heavy pre-processing to bring that stuff into  
an easily accessible form. Btw, the "real" Smalltalk way would be to  
just create your data in the class var interactively using an  
inspector. The image will store these just fine. The problem with  
there may not be a simple way of transporting them along with the  
code into another image.

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

John Almberg
Bert,

> Well, since you are storing it in a class var, the "heavy lifting"  
> can be done at initialization time. This way the code remains  
> readable but you can do heavy pre-processing to bring that stuff  
> into an easily accessible form.

Oh! I see what you mean. That would be a good approach.

> Btw, the "real" Smalltalk way would be to just create your data in  
> the class var interactively using an inspector. The image will  
> store these just fine. The problem with there may not be a simple  
> way of transporting them along with the code into another image.

H'mmm... this is over my head. I'm not sure how to inspect a class  
object.

I tried doing:

        MyClass inspect

and also poking around the menus, but it looks like I'm inspecting an  
instance of the class, not the class itself -- the class variable is  
not displayed.

How do you edit data in a class interactively? Probably not what I  
want, as you say, but sounds interesting.

-- John

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

Bert Freudenberg

On Sep 4, 2007, at 10:07 , John Almberg wrote:

> Bert,
>
>> Well, since you are storing it in a class var, the "heavy lifting"  
>> can be done at initialization time. This way the code remains  
>> readable but you can do heavy pre-processing to bring that stuff  
>> into an easily accessible form.
>
> Oh! I see what you mean. That would be a good approach.
>
>> Btw, the "real" Smalltalk way would be to just create your data in  
>> the class var interactively using an inspector. The image will  
>> store these just fine. The problem with there may not be a simple  
>> way of transporting them along with the code into another image.
>
> H'mmm... this is over my head. I'm not sure how to inspect a class  
> object.
>
> I tried doing:
>
> MyClass inspect
>
> and also poking around the menus, but it looks like I'm inspecting  
> an instance of the class, not the class itself -- the class  
> variable is not displayed.
>
> How do you edit data in a class interactively? Probably not what I  
> want, as you say, but sounds interesting.

Type "MyClass", select it, press Cmd-i (or Alt-i). You get an  
inspector on a class - which of course is the instance of another  
class, as everything is an object (and hence an instance of a class)  
in Smalltalk. Anyway, you should see a reference to the superclass, a  
dictionary of all the methods, the list of instance variables and  
subclasses etc. Class variables are simply held in a Dictionary in  
the "classPool" instance variable of that class. So by inspecting  
that and drilling down into your class var you can modify it.

A simpler way to get at the contents of your class var is just  
selecting its name in a browser showing any method of your class, and  
press Cmd-i there. That works because in the browser, code is  
evaluated in the context of the selected class.

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

John Almberg
Whoa... that worked, but the implications are a bit hard to digest...

So MyClass is an object in my Smalltalk image, and it can have  
variables that I can set interactively, and the values contained  
therein are now part of the class...

I keep reading that classes are objects, but this is the first time  
I've seen something that makes me realize that they are fundamentally  
different than objects in other languages. I guess because they are  
'live', in some sense, in the Smalltalk environment. That is, not  
just source code, but an instantiated object.

Talk about paradigm whiplash... I'm going to have to think about  
this, a bit :-)

Thanks!

-- John

> Type "MyClass", select it, press Cmd-i (or Alt-i). You get an  
> inspector on a class - which of course is the instance of another  
> class, as everything is an object (and hence an instance of a  
> class) in Smalltalk. Anyway, you should see a reference to the  
> superclass, a dictionary of all the methods, the list of instance  
> variables and subclasses etc. Class variables are simply held in a  
> Dictionary in the "classPool" instance variable of that class. So  
> by inspecting that and drilling down into your class var you can  
> modify it.
>
> A simpler way to get at the contents of your class var is just  
> selecting its name in a browser showing any method of your class,  
> and press Cmd-i there. That works because in the browser, code is  
> evaluated in the context of the selected class.
>
> - Bert -
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

Bert Freudenberg
Seems you've made the first step to truly understanding Smalltalk :)

Also you must realize that the browser is just a view into that live  
system of objects we call classes and is simply modifying those live  
objects. You could do that in an inspector as well, but the class  
browser is more specialized so it is easier to use for that purpose.

Welcome to Real Objects.

- Bert -

On Sep 4, 2007, at 12:19 , John Almberg wrote:

> Whoa... that worked, but the implications are a bit hard to digest...
>
> So MyClass is an object in my Smalltalk image, and it can have  
> variables that I can set interactively, and the values contained  
> therein are now part of the class...
>
> I keep reading that classes are objects, but this is the first time  
> I've seen something that makes me realize that they are  
> fundamentally different than objects in other languages. I guess  
> because they are 'live', in some sense, in the Smalltalk  
> environment. That is, not just source code, but an instantiated  
> object.
>
> Talk about paradigm whiplash... I'm going to have to think about  
> this, a bit :-)
>
> Thanks!
>
> -- John
>
>> Type "MyClass", select it, press Cmd-i (or Alt-i). You get an  
>> inspector on a class - which of course is the instance of another  
>> class, as everything is an object (and hence an instance of a  
>> class) in Smalltalk. Anyway, you should see a reference to the  
>> superclass, a dictionary of all the methods, the list of instance  
>> variables and subclasses etc. Class variables are simply held in a  
>> Dictionary in the "classPool" instance variable of that class. So  
>> by inspecting that and drilling down into your class var you can  
>> modify it.
>>
>> A simpler way to get at the contents of your class var is just  
>> selecting its name in a browser showing any method of your class,  
>> and press Cmd-i there. That works because in the browser, code is  
>> evaluated in the context of the selected class.
>>
>> - Bert -




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

John Almberg
Right, so if classes are factories that produce objects of a certain  
kind, then I've just changed the factory, and potentially it's  
products, interactively.

That's pretty cool. I get it!

-- John


On Sep 4, 2007, at 4:49 PM, Bert Freudenberg wrote:

> Seems you've made the first step to truly understanding Smalltalk :)
>
> Also you must realize that the browser is just a view into that  
> live system of objects we call classes and is simply modifying  
> those live objects. You could do that in an inspector as well, but  
> the class browser is more specialized so it is easier to use for  
> that purpose.
>
> Welcome to Real Objects.
>
> - Bert -
>
> On Sep 4, 2007, at 12:19 , John Almberg wrote:
>
>> Whoa... that worked, but the implications are a bit hard to digest...
>>
>> So MyClass is an object in my Smalltalk image, and it can have  
>> variables that I can set interactively, and the values contained  
>> therein are now part of the class...
>>
>> I keep reading that classes are objects, but this is the first  
>> time I've seen something that makes me realize that they are  
>> fundamentally different than objects in other languages. I guess  
>> because they are 'live', in some sense, in the Smalltalk  
>> environment. That is, not just source code, but an instantiated  
>> object.
>>
>> Talk about paradigm whiplash... I'm going to have to think about  
>> this, a bit :-)
>>
>> Thanks!
>>
>> -- John
>>
>>> Type "MyClass", select it, press Cmd-i (or Alt-i). You get an  
>>> inspector on a class - which of course is the instance of another  
>>> class, as everything is an object (and hence an instance of a  
>>> class) in Smalltalk. Anyway, you should see a reference to the  
>>> superclass, a dictionary of all the methods, the list of instance  
>>> variables and subclasses etc. Class variables are simply held in  
>>> a Dictionary in the "classPool" instance variable of that class.  
>>> So by inspecting that and drilling down into your class var you  
>>> can modify it.
>>>
>>> A simpler way to get at the contents of your class var is just  
>>> selecting its name in a browser showing any method of your class,  
>>> and press Cmd-i there. That works because in the browser, code is  
>>> evaluated in the context of the selected class.
>>>
>>> - Bert -
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Websites for On-line Collectible Dealers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Identry, LLC
John Almberg
(631) 546-5079
[hidden email]
www.identry.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Best way to implement two-dimensional array

Nicolas Cellier-3
In reply to this post by Bert Freudenberg
However, Classes and methods are Objects which have well defined tools
to help them migrating from an image to another, even to another
Smalltalk dialect. This ease code sharing.

This is less clear for arbitrary objects...

That's why I restrict myself to initialize these class vars in an
initialize method in the class side, and loose some of the power of the
image...

But there is a better reason:
if you construct your object with some snippets of code, say in an
inspector or a debugger:
        MyTable at: 1 put: 30 degreesToRadians cos * 4

Then your image will loose the history of construction.
All it retains is 3.464101615137755 which is somehow less expressive.

Nicolas

Bert Freudenberg a écrit :

> Seems you've made the first step to truly understanding Smalltalk :)
>
> Also you must realize that the browser is just a view into that live
> system of objects we call classes and is simply modifying those live
> objects. You could do that in an inspector as well, but the class
> browser is more specialized so it is easier to use for that purpose.
>
> Welcome to Real Objects.
>
> - Bert -
>
> On Sep 4, 2007, at 12:19 , John Almberg wrote:
>
>> Whoa... that worked, but the implications are a bit hard to digest...
>>
>> So MyClass is an object in my Smalltalk image, and it can have
>> variables that I can set interactively, and the values contained
>> therein are now part of the class...
>>
>> I keep reading that classes are objects, but this is the first time
>> I've seen something that makes me realize that they are fundamentally
>> different than objects in other languages. I guess because they are
>> 'live', in some sense, in the Smalltalk environment. That is, not just
>> source code, but an instantiated object.
>>
>> Talk about paradigm whiplash... I'm going to have to think about this,
>> a bit :-)
>>
>> Thanks!
>>
>> -- John
>>
>>> Type "MyClass", select it, press Cmd-i (or Alt-i). You get an
>>> inspector on a class - which of course is the instance of another
>>> class, as everything is an object (and hence an instance of a class)
>>> in Smalltalk. Anyway, you should see a reference to the superclass, a
>>> dictionary of all the methods, the list of instance variables and
>>> subclasses etc. Class variables are simply held in a Dictionary in
>>> the "classPool" instance variable of that class. So by inspecting
>>> that and drilling down into your class var you can modify it.
>>>
>>> A simpler way to get at the contents of your class var is just
>>> selecting its name in a browser showing any method of your class, and
>>> press Cmd-i there. That works because in the browser, code is
>>> evaluated in the context of the selected class.
>>>
>>> - Bert -

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re: Best way to implement two-dimensional array

John Almberg
Yes, that's clear, and I do intend to initialize this big table with  
code, mainly to make it easy for me to spot and fix typos. However,  
it's still cool to gain a sense of the concreteness of Smalltalk  
classes.

And I find myself trying out code in a Workspace to see how things  
work, before encoding it in a method. I suspect interactively  
tweaking a class might help me figure things out before committing it  
to an initialize method.

-- John

On Sep 4, 2007, at 5:29 PM, nicolas cellier wrote:

> However, Classes and methods are Objects which have well defined  
> tools to help them migrating from an image to another, even to  
> another Smalltalk dialect. This ease code sharing.
>
> This is less clear for arbitrary objects...
>
> That's why I restrict myself to initialize these class vars in an  
> initialize method in the class side, and loose some of the power of  
> the image...
>
> But there is a better reason:
> if you construct your object with some snippets of code, say in an  
> inspector or a debugger:
> MyTable at: 1 put: 30 degreesToRadians cos * 4
>
> Then your image will loose the history of construction.
> All it retains is 3.464101615137755 which is somehow less expressive.
>
> Nicolas
>
> Bert Freudenberg a écrit :
>> Seems you've made the first step to truly understanding Smalltalk :)
>> Also you must realize that the browser is just a view into that  
>> live system of objects we call classes and is simply modifying  
>> those live objects. You could do that in an inspector as well, but  
>> the class browser is more specialized so it is easier to use for  
>> that purpose.
>> Welcome to Real Objects.
>> - Bert -
>> On Sep 4, 2007, at 12:19 , John Almberg wrote:
>>> Whoa... that worked, but the implications are a bit hard to  
>>> digest...
>>>
>>> So MyClass is an object in my Smalltalk image, and it can have  
>>> variables that I can set interactively, and the values contained  
>>> therein are now part of the class...
>>>
>>> I keep reading that classes are objects, but this is the first  
>>> time I've seen something that makes me realize that they are  
>>> fundamentally different than objects in other languages. I guess  
>>> because they are 'live', in some sense, in the Smalltalk  
>>> environment. That is, not just source code, but an instantiated  
>>> object.
>>>
>>> Talk about paradigm whiplash... I'm going to have to think about  
>>> this, a bit :-)
>>>
>>> Thanks!
>>>
>>> -- John
>>>
>>>> Type "MyClass", select it, press Cmd-i (or Alt-i). You get an  
>>>> inspector on a class - which of course is the instance of  
>>>> another class, as everything is an object (and hence an instance  
>>>> of a class) in Smalltalk. Anyway, you should see a reference to  
>>>> the superclass, a dictionary of all the methods, the list of  
>>>> instance variables and subclasses etc. Class variables are  
>>>> simply held in a Dictionary in the "classPool" instance variable  
>>>> of that class. So by inspecting that and drilling down into your  
>>>> class var you can modify it.
>>>>
>>>> A simpler way to get at the contents of your class var is just  
>>>> selecting its name in a browser showing any method of your  
>>>> class, and press Cmd-i there. That works because in the browser,  
>>>> code is evaluated in the context of the selected class.
>>>>
>>>> - Bert -
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Websites for On-line Collectible Dealers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Identry, LLC
John Almberg
(631) 546-5079
[hidden email]
www.identry.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re: Best way to implement two-dimensional array

Bert Freudenberg
Also, you easily can inflate your image to ridiculous sizes with  
class variables accidentally holding onto huge structures.  
Maintaining an image requires a bit of discipline. It's an organic  
thing, which quite literally has been nurtured for 30 years now (with  
periods of hibernation of course).

- Bert -

On Sep 4, 2007, at 15:31 , John Almberg wrote:

> Yes, that's clear, and I do intend to initialize this big table  
> with code, mainly to make it easy for me to spot and fix typos.  
> However, it's still cool to gain a sense of the concreteness of  
> Smalltalk classes.
>
> And I find myself trying out code in a Workspace to see how things  
> work, before encoding it in a method. I suspect interactively  
> tweaking a class might help me figure things out before committing  
> it to an initialize method.
>
> -- John
>
> On Sep 4, 2007, at 5:29 PM, nicolas cellier wrote:
>
>> However, Classes and methods are Objects which have well defined  
>> tools to help them migrating from an image to another, even to  
>> another Smalltalk dialect. This ease code sharing.
>>
>> This is less clear for arbitrary objects...
>>
>> That's why I restrict myself to initialize these class vars in an  
>> initialize method in the class side, and loose some of the power  
>> of the image...
>>
>> But there is a better reason:
>> if you construct your object with some snippets of code, say in an  
>> inspector or a debugger:
>> MyTable at: 1 put: 30 degreesToRadians cos * 4
>>
>> Then your image will loose the history of construction.
>> All it retains is 3.464101615137755 which is somehow less expressive.
>>
>> Nicolas
>>
>> Bert Freudenberg a écrit :
>>> Seems you've made the first step to truly understanding Smalltalk :)
>>> Also you must realize that the browser is just a view into that  
>>> live system of objects we call classes and is simply modifying  
>>> those live objects. You could do that in an inspector as well,  
>>> but the class browser is more specialized so it is easier to use  
>>> for that purpose.
>>> Welcome to Real Objects.
>>> - Bert -
>>> On Sep 4, 2007, at 12:19 , John Almberg wrote:
>>>> Whoa... that worked, but the implications are a bit hard to  
>>>> digest...
>>>>
>>>> So MyClass is an object in my Smalltalk image, and it can have  
>>>> variables that I can set interactively, and the values contained  
>>>> therein are now part of the class...
>>>>
>>>> I keep reading that classes are objects, but this is the first  
>>>> time I've seen something that makes me realize that they are  
>>>> fundamentally different than objects in other languages. I guess  
>>>> because they are 'live', in some sense, in the Smalltalk  
>>>> environment. That is, not just source code, but an instantiated  
>>>> object.
>>>>
>>>> Talk about paradigm whiplash... I'm going to have to think about  
>>>> this, a bit :-)
>>>>
>>>> Thanks!
>>>>
>>>> -- John
>>>>
>>>>> Type "MyClass", select it, press Cmd-i (or Alt-i). You get an  
>>>>> inspector on a class - which of course is the instance of  
>>>>> another class, as everything is an object (and hence an  
>>>>> instance of a class) in Smalltalk. Anyway, you should see a  
>>>>> reference to the superclass, a dictionary of all the methods,  
>>>>> the list of instance variables and subclasses etc. Class  
>>>>> variables are simply held in a Dictionary in the "classPool"  
>>>>> instance variable of that class. So by inspecting that and  
>>>>> drilling down into your class var you can modify it.
>>>>>
>>>>> A simpler way to get at the contents of your class var is just  
>>>>> selecting its name in a browser showing any method of your  
>>>>> class, and press Cmd-i there. That works because in the  
>>>>> browser, code is evaluated in the context of the selected class.
>>>>>
>>>>> - Bert -




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
12