Hi,
I've read the sparse documentation on 'dynamic message' calls and I've experimented a lot and still cannot figure out how to do something that should be simple: I want to build a message like this: cellObject cellLock: aBoolean where cellObject is to look like: cell1, cell2, cell3 ..., or cell9 I can build up cellObject like this: self perform: ('cell', cellNumber asString) asSymbol but I can't figure out how to build the full message with the key selector "cellLock:", and the value 'aBoolean'. I've tried everything I can think of based on the terse documentation, and anything I can find on the internet, which isn't much (including this forum). Any help would be appreciated. Thanks
---
Under the age of 15 so don't want to post my name ![]() |
Hi,
For your example: cellObject cellLock: aBoolean where cellObject is to look like: cell1, cell2, cell3 ..., or cell9 I don't think you want or need to use #perform:. You use #perform: when you want to construct the message name and sent the constructed message name to an object. In your case you know the message you want to send, it is #cellLock:. What you don't know (or have easily available) is the object you want to send the message to. What I think you need to do is save your cell objects in an array or collection (I will let you look up collections, but ask again if you need help). With something like: cellObjects := OrderedCollection new. cellObjects add: YourCellClass new. Once you have a collection of your cells, you can access one or more of them and sent the #cellLock: message to it like so: (cellObjects at: cellNumber) cellLock: aBoolean Good luck and keep posting if you need help. Lou On Mon, 23 Apr 2012 07:58:47 -0700 (PDT), OrgmiGeek <[hidden email]> wrote: >Hi, >I've read the sparse documentation on 'dynamic message' calls and I've >experimented a lot and still cannot figure out how to do something that >should be simple: > >I want to build a message like this: > > cellObject cellLock: aBoolean > >where cellObject is to look like: cell1, cell2, cell3 ..., or cell9 > >I can build up cellObject like this: > > self perform: ('cell', cellNumber asString) asSymbol > >but I can't figure out how to build the full message with the key selector >"cellLock:", and the value 'aBoolean'. >I've tried everything I can think of based on the terse documentation, and >anything I can find on the internet, which isn't much (including this >forum). > >Any help would be appreciated. > >Thanks > >----- >--- >Under the age of 15 so don't want to post my name :D Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:[hidden email] http://www.Keystone-Software.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by OrgmiGeek
On 23.04.2012, at 07:58, OrgmiGeek wrote: > Hi, > I've read the sparse documentation on 'dynamic message' calls and I've > experimented a lot and still cannot figure out how to do something that > should be simple: > > I want to build a message like this: > > cellObject cellLock: aBoolean > > where cellObject is to look like: cell1, cell2, cell3 ..., or cell9 > > I can build up cellObject like this: > > self perform: ('cell', cellNumber asString) asSymbol > > but I can't figure out how to build the full message with the key selector > "cellLock:", and the value 'aBoolean'. > I've tried everything I can think of based on the terse documentation, and > anything I can find on the internet, which isn't much (including this > forum). > > Any help would be appreciated. So if I understand correctly you want to do something equivalent to this: cell1 cellLock: true. cell2 cellLock: true. cell3 cellLock: true. ... etc ... Yes? If so, then perform is not what you are looking for. Perform lets you assemble the message selector, but not the receiver of the message. The Right Way to do this would be to have an Array of cells. Arrays are a collection of objects, and individual objects can be accessed by index. So if "cells" was an array of your cell objects, you could write (cells at: 1) cellLock: true. (cells at: 2) cellLock: true. (cells at: 3) cellLock: true. ... etc ... but also iterate over all of them: 1 to: 10 do: [:i | (cells at: i) cellLock: true] Does that make sense? - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Louis LaBrunda
Ah that's curious - your reply did not have a Re: and was not threaded with the original message. Would have saved me to write a message very similar to yours ;)
- Bert - On 23.04.2012, at 10:44, Louis LaBrunda wrote: > Hi, > > For your example: > > cellObject cellLock: aBoolean > > where cellObject is to look like: cell1, cell2, cell3 ..., or cell9 > > I don't think you want or need to use #perform:. You use #perform: when > you want to construct the message name and sent the constructed message > name to an object. > > In your case you know the message you want to send, it is #cellLock:. What > you don't know (or have easily available) is the object you want to send > the message to. > > What I think you need to do is save your cell objects in an array or > collection (I will let you look up collections, but ask again if you need > help). With something like: > > cellObjects := OrderedCollection new. > cellObjects add: YourCellClass new. > > Once you have a collection of your cells, you can access one or more of > them and sent the #cellLock: message to it like so: > > (cellObjects at: cellNumber) cellLock: aBoolean > > Good luck and keep posting if you need help. > > Lou > > On Mon, 23 Apr 2012 07:58:47 -0700 (PDT), OrgmiGeek > <[hidden email]> wrote: > >> Hi, >> I've read the sparse documentation on 'dynamic message' calls and I've >> experimented a lot and still cannot figure out how to do something that >> should be simple: >> >> I want to build a message like this: >> >> cellObject cellLock: aBoolean >> >> where cellObject is to look like: cell1, cell2, cell3 ..., or cell9 >> >> I can build up cellObject like this: >> >> self perform: ('cell', cellNumber asString) asSymbol >> >> but I can't figure out how to build the full message with the key selector >> "cellLock:", and the value 'aBoolean'. >> I've tried everything I can think of based on the terse documentation, and >> anything I can find on the internet, which isn't much (including this >> forum). >> >> Any help would be appreciated. >> >> Thanks >> >> ----- >> --- >> Under the age of 15 so don't want to post my name :D > ----------------------------------------------------------- > Louis LaBrunda > Keystone Software Corp. > SkypeMe callto://PhotonDemon > mailto:[hidden email] http://www.Keystone-Software.com > _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Bert Freudenberg
Hi,
actually, that is not quite what we want to do (we meaning my son and I in our first squeak project). Since we were unable to assemble the message, we ended up doing a brute force method to get it to work: lockCell: aBoolean row: aRow column: aColumn self addressToCellNumber: aRow and: aColumn "this converts the big grid aRow, aCoulumn into a cellNumber" (aBoolean isKindof: Boolean) ifTrue: [ (cellNumber =1) ifTrue: [cell1 cellLock:aBoolean]. (cellNumber =2) ifTrue: [cell2 cellLock:aBoolean]. (cellNumber =3) ifTrue: [cell3 cellLock:aBoolean]. (cellNumber =4) ifTrue: [cell4 cellLock:aBoolean]. (cellNumber =5) ifTrue: [cell5 cellLock:aBoolean]. (cellNumber =6) ifTrue: [cell6 cellLock:aBoolean]. (cellNumber =7) ifTrue: [cell7 cellLock:aBoolean]. (cellNumber =8) ifTrue: [cell8 cellLock:aBoolean]. (cellNumber =9) ifTrue: [cell9 cellLock:aBoolean]. ]. As you can see that is really repetitive. So, it seemed to us that one should be able to dynamically build the message in one line, that is why we tried to do something like: self perform: ('cell', cellNumber asString) asSymbol ... to build up the "cell1 ... cell9" object. But we couldn't figure out how to build up the rest of the message. (One solution which is possible was presented by Louis Labranda which involves using an ordered collection ... that should work fine ... but is there no way of building up the message similar to our attempt, but expanding on it? We thought that everything's an object in Squeak ... what happened to that?) Thanks, Dawson (I'm the under 15 year old's father, and I don't mind my name being published) On 24/04/12 7:59 AM, Bert Freudenberg wrote: > So if I understand correctly you want to do something equivalent to this: > > cell1 cellLock: true. > cell2 cellLock: true. > cell3 cellLock: true. > ... etc ... > > Yes? If so, then perform is not what you are looking for. Perform lets you assemble the message selector, but not the receiver of the message. The Right Way to do this would be to have an Array of cells. Arrays are a collection of objects, and individual objects can be accessed by index. So if "cells" was an array of your cell objects, you could write > > (cells at: 1) cellLock: true. > (cells at: 2) cellLock: true. > (cells at: 3) cellLock: true. > ... etc ... > > but also iterate over all of them: > > 1 to: 10 do: [:i | (cells at: i) cellLock: true] > > Does that make sense? > > - Bert - Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Bert Freudenberg
Hi Bert,
>Ah that's curious - your reply did not have a Re: and was not threaded with the original message. Would have saved me to write a message very similar to yours ;) >- Bert - Sorry about that. I don't like seeing all the Re: Re:.... filling up the subject line often to the point where you can't see the real subject any more, so I often remove it. I use Forte Agent for email and news groups because it (by and large) treats them the same and I can keep them all in one place. I read the post at and posted my reply to gmane.comp.lang.smalltalk.squeak.beginners. With Forte Agent, all the posts, including mine were in the same thread. What is also curious is that I also received a copy of your post (the one I am replying to here) as an email but none of the other posts including your other one. I seem to get all the posts via the news group but only some of the emails. I would rather I just get the news group posts but don't know how to turn off the email copies. Anyway, I will try to remember to leave one Re: in the future. Although I'm not sure why it is required to keep the thread together. If anything, having exactly the same subject line should keep post together better than having to ignore a lot of Re:'s to fine the real subject. Lou > >On 23.04.2012, at 10:44, Louis LaBrunda wrote: > >> Hi, >> >> For your example: >> >> cellObject cellLock: aBoolean >> >> where cellObject is to look like: cell1, cell2, cell3 ..., or cell9 >> >> I don't think you want or need to use #perform:. You use #perform: when >> you want to construct the message name and sent the constructed message >> name to an object. >> >> In your case you know the message you want to send, it is #cellLock:. What >> you don't know (or have easily available) is the object you want to send >> the message to. >> >> What I think you need to do is save your cell objects in an array or >> collection (I will let you look up collections, but ask again if you need >> help). With something like: >> >> cellObjects := OrderedCollection new. >> cellObjects add: YourCellClass new. >> >> Once you have a collection of your cells, you can access one or more of >> them and sent the #cellLock: message to it like so: >> >> (cellObjects at: cellNumber) cellLock: aBoolean >> >> Good luck and keep posting if you need help. >> >> Lou >> >> On Mon, 23 Apr 2012 07:58:47 -0700 (PDT), OrgmiGeek >> <[hidden email]> wrote: >> >>> Hi, >>> I've read the sparse documentation on 'dynamic message' calls and I've >>> experimented a lot and still cannot figure out how to do something that >>> should be simple: >>> >>> I want to build a message like this: >>> >>> cellObject cellLock: aBoolean >>> >>> where cellObject is to look like: cell1, cell2, cell3 ..., or cell9 >>> >>> I can build up cellObject like this: >>> >>> self perform: ('cell', cellNumber asString) asSymbol >>> >>> but I can't figure out how to build the full message with the key selector >>> "cellLock:", and the value 'aBoolean'. >>> I've tried everything I can think of based on the terse documentation, and >>> anything I can find on the internet, which isn't much (including this >>> forum). >>> >>> Any help would be appreciated. >>> >>> Thanks >>> >>> ----- >>> --- >>> Under the age of 15 so don't want to post my name :D >> ----------------------------------------------------------- >> Louis LaBrunda >> Keystone Software Corp. >> SkypeMe callto://PhotonDemon >> mailto:[hidden email] http://www.Keystone-Software.com >> Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:[hidden email] http://www.Keystone-Software.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Dawson
>>>>> "Dawson" == Dawson <[hidden email]> writes:
Dawson> (cellNumber =1) ifTrue: [cell1 cellLock:aBoolean]. Dawson> (cellNumber =2) ifTrue: [cell2 cellLock:aBoolean]. Dawson> (cellNumber =3) ifTrue: [cell3 cellLock:aBoolean]. Dawson> (cellNumber =4) ifTrue: [cell4 cellLock:aBoolean]. Dawson> (cellNumber =5) ifTrue: [cell5 cellLock:aBoolean]. Dawson> (cellNumber =6) ifTrue: [cell6 cellLock:aBoolean]. Dawson> (cellNumber =7) ifTrue: [cell7 cellLock:aBoolean]. Dawson> (cellNumber =8) ifTrue: [cell8 cellLock:aBoolean]. Dawson> (cellNumber =9) ifTrue: [cell9 Dawson> cellLock:aBoolean]. The problem is upstream of this. Why do you have variables named like "cell1" through "cell9"? At that point, your design went awry. Back up to there, and put those values into an array, and things will clear up. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <URL:http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.posterous.com/ for Smalltalk discussion _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Dawson
Hi Dawson and Dawson's 15 year old son,
>From your code below, I assume that somewhere in your program you have created (instantiated) nine cells in instance variables named cell1-cell9. This is fine but you should realize that they (cell1-cell9) are variables that hold pointers to the objects and not really the objects themselves. It is okay to think of them as the objects because for the most part it is easier than thinking of them as pointers to objects. The real point is to realize that more than one variable can point to the same instance of an object. For example, if I were to write: cell10 := cell1. There would not be two copies of cell1, there would just be two pointers to it. Any messages sent to cell10 would effect cell1. This can be confusing, so I'm not recommending doing it exactly. But putting the nine cells in a collection is a good idea because it gives you another way to get to the cells without using the original variables they were created in. You ask about everything being an object is Smalltalk. Yes everything is an object. You also ask if there is a way to construct the message with the original variable names. I don't know how to do it and don't think you can with many Smalltalks. Bert may know how to do it with Squeak. Even if Bert knows how, I wouldn't recommend it and I hope I'm not speaking out of turn but I doubt Bert would recommend it either. If it is doable, it's use would be unusual and therefor confusing. Even #perform: is seldom used by most programmers and even less so by beginners. Back to your program. I assume that you have a good reason for putting the cells in variables named (cell1-cell9) and again that is fine but there is no reason why you can't have the same objects addressable or accessible from a collection. Smalltalk's collection classes are one of its many unknown treasures. They are a big part of why Smalltalk code is shorter and more understandable than code of other languages. Check them out. And please keep asking questions. Lou >Hi, >actually, that is not quite what we want to do (we meaning my son and I >in our first squeak project). > >Since we were unable to assemble the message, we ended up doing a >brute force method to get it to work: > >lockCell: aBoolean row: aRow column: aColumn > > self addressToCellNumber: aRow and: aColumn > "this converts the big grid aRow, aCoulumn into a cellNumber" > > (aBoolean isKindof: Boolean) > ifTrue: [ > (cellNumber =1) ifTrue: [cell1 cellLock:aBoolean]. > (cellNumber =2) ifTrue: [cell2 cellLock:aBoolean]. > (cellNumber =3) ifTrue: [cell3 cellLock:aBoolean]. > (cellNumber =4) ifTrue: [cell4 cellLock:aBoolean]. > (cellNumber =5) ifTrue: [cell5 cellLock:aBoolean]. > (cellNumber =6) ifTrue: [cell6 cellLock:aBoolean]. > (cellNumber =7) ifTrue: [cell7 cellLock:aBoolean]. > (cellNumber =8) ifTrue: [cell8 cellLock:aBoolean]. > (cellNumber =9) ifTrue: [cell9 cellLock:aBoolean]. > ]. > >As you can see that is really repetitive. So, it seemed to us that one >should be able to dynamically build the message in one line, > >that is why we tried to do something like: > > self perform: ('cell', cellNumber asString) asSymbol ... to build up >the "cell1 ... cell9" object. But we couldn't figure out how to build up >the rest of the message. > >(One solution which is possible was presented by Louis Labranda which >involves using an ordered collection ... that should work fine ... but >is there no way of building up the message similar to our attempt, but >expanding on it? We thought that everything's an object in Squeak ... >what happened to that?) > >Thanks, > >Dawson (I'm the under 15 year old's father, and I don't mind my name >being published) > > > > > > >On 24/04/12 7:59 AM, Bert Freudenberg wrote: >> So if I understand correctly you want to do something equivalent to this: >> >> cell1 cellLock: true. >> cell2 cellLock: true. >> cell3 cellLock: true. >> ... etc ... >> >> Yes? If so, then perform is not what you are looking for. Perform lets you assemble the message selector, but not the receiver of the message. The Right Way to do this would be to have an Array of cells. Arrays are a collection of objects, and individual objects can be accessed by index. So if "cells" was an array of your cell objects, you could write >> >> (cells at: 1) cellLock: true. >> (cells at: 2) cellLock: true. >> (cells at: 3) cellLock: true. >> ... etc ... >> >> but also iterate over all of them: >> >> 1 to: 10 do: [:i | (cells at: i) cellLock: true] >> >> Does that make sense? >> >> - Bert - Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:[hidden email] http://www.Keystone-Software.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Louis LaBrunda
Hi Louis,
Thanks, your advice looks very good here we hadn't even thought about ordered collections (we studied the "Squeak by example book" before we started our project, but sometimes it's hard to figure out when exactly you might need to use stuff you read about, even if you do the examples) .. I had thought there might be a way of "building up" the "cellObject cellLock: aBoolean" ... judging from the replies, it seems that it is either a) crazy, b) it can't be done, c) no one knows how to do it. I think we'll give your suggestion a go when we get a few minutes. (ah .. the we is my son and I). Thanks, Dawson _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Randal L. Schwartz
Hi Randal,
thanks for your note ... yes we believe we've made some mistakes in our program already, but there are so many undocumented things in Squeak ... (or at least we can't find them, or know what to look for) that we figured we'd try to get a prototype going, and then fix it up as we learned more about Squeak. Each of the cells (cell1, cell2 ... etc) are insantiations of a Class that we wrote called SudokuCell which is one cell in a 3cell X 3cell Sudoku block, and then nine of these blocks are built up by the 3cells X 3 cells ... we did some brute force stuff because we just couldn't find things that we thought we needed. We are really quite new to Squeak. I've come from a Fortran / Assembly language / C / C++ / Eiffel background, and my son came from a Scratch background. Thanks for your suggestions, Dawson On 24/04/12 6:07 PM, Randal L. Schwartz wrote: cellLock:aBoolean]. > > The problem is upstream of this. Why do you have variables named like > "cell1" through "cell9"? At that point, your design went awry. Back up > to there, and put those values into an array, and things will clear up. > _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Dawson
>>>>> "Dawson" == Dawson <[hidden email]> writes:
Dawson> .. I had thought there might be a way of "building up" the "cellObject Dawson> cellLock: aBoolean" ... judging from the replies, it seems that it is Dawson> either a) crazy, b) it can't be done, c) no one knows how to do Dawson> it. There are ways to do anything and everything in Squeak. And many ways are crazy. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <URL:http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.posterous.com/ for Smalltalk discussion _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Louis LaBrunda
Hi Louis,
thanks for your very helpful posts, particularly the most recent one ... On 24/04/12 6:49 PM, Louis LaBrunda wrote: > Hi Dawson and Dawson's 15 year old son, > >>From your code below, I assume that somewhere in your program you have > created (instantiated) nine cells in instance variables named cell1-cell9. Yes, you are right .. these are instantiations of a class (more info in my other reply to Randal) > This is fine but you should realize that they (cell1-cell9) are variables > that hold pointers to the objects and not really the objects themselves. It > is okay to think of them as the objects because for the most part it is Yes, I was using inexact language here (back to everything is an object ... are pointers in Squeak considered objects then? or is this a case of something that isn't an object in Squeak?) > easier than thinking of them as pointers to objects. The real point is to > realize that more than one variable can point to the same instance of an > object. For example, if I were to write: > > cell10 := cell1. > Point taken. SNIP > Back to your program. I assume that you have a good reason for putting the > cells in variables named (cell1-cell9) and again that is fine but there is > no reason why you can't have the same objects addressable or accessible > from a collection. > Yeah .. I suppose with very little context it looks like we haven't got a clue what we are doing. (Maybe we don't, but what we've written so far works even if there is a bit of brute force kind of stuff in there). To be honest, it is why we started asking questions, as a trained engineer, and as an artist, I like elegant solutions, perhaps that is what drew me to Squeak after my son began enquiring if we could learn it together. But our program right now is certainly not very elegant yet. As we learn more we can tweak it though. > Smalltalk's collection classes are one of its many unknown treasures. They > are a big part of why Smalltalk code is shorter and more understandable > than code of other languages. Check them out. And please keep asking > questions. Excellent. We have read the "Squeak by Example" book, but we don't always know how to use the stuff we've read about even after following the examples. We figured after we wrote this program, that we'd re-read the book, and get more out of it the next time through. Thanks again for taking the time to write your advice and suggestions, we appreciate it. Dawson _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Dawson
On 24.04.2012, at 10:59, Dawson wrote:
> .. I had thought there might be a way of "building up" the "cellObject > cellLock: aBoolean" ... judging from the replies, it seems that it is > either a) crazy, b) it can't be done, c) no one knows how to do it. It's a) crazy. Of course there's a way to do it. It depends on where your variables actually are. For temporary variables, you would use thisContext. | cell1 cell2 cell3 | cell1 := 'this'. cell2 := 'is'. cell3 := 'crazy'. ctx := thisContext. (1 to: 3) inject: '' into: [:s :i | s, (ctx at: i), ' '] For instance variables, you would use "instVarNamed:" cell1 := 'this'. cell2 := 'is'. cell3 := 'crazy'. (1 to: 3) inject: '' into: [:s :i | s, (self instVarNamed: 'cell', i asString), ' '] Both of these are equally crazy. An array is much less crazy: cell1 := 'not'. cell2 := 'so'. cell3 := 'crazy'. array := {cell1. cell2. cell3}. array inject: '' into: [:s :cell | s, cell, ' '] But as others pointed out, in real code you would not even put cells into individual variables in the first place, but create them as an array (not OrderedCollection, since you do not need the number of cells to change). - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Dawson
Hi Dawson,
>Hi Louis, >Thanks, your advice looks very good here we hadn't even thought about >ordered collections (we studied the "Squeak by example book" before we >started our project, but sometimes it's hard to figure out when exactly >you might need to use stuff you read about, even if you do the examples) Your welcome. Please don't feel bad about asking what seems like dumb questions, there really aren't any. Also, it is often hard to know which programming construct best fits your needs, that takes experience. >.. I had thought there might be a way of "building up" the "cellObject >cellLock: aBoolean" ... judging from the replies, it seems that it is >either a) crazy, b) it can't be done, c) no one knows how to do it. I don't know if I would say it is crazy but some might. Mostly I use VA Smalltalk, it is designed more for business use that Squeak is (that's not a knock on Squeak, it's just the way it is). In VA Smalltalk the compiler is not included with the packaged images. In Squeak, you always live in the image with the compiler. I expect there is a way to build up a string that might look like this: "cell1 cellLock: true" and then send it to the compiler and then execute the compiled code returned by the compiler. I bet Bert and many other in the group know how to do this. But once you play with collections, you will see it is not needed. >I think we'll give your suggestion a go when we get a few minutes. >(ah .. the we is my son and I). >Thanks, >Dawson Sounds like a great father/son project. I have done some with my boys but wish I could do more, so I envy you both. Lou ----------------------------------------------------------- Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:[hidden email] http://www.Keystone-Software.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On 24.04.2012, at 11:34, Louis LaBrunda wrote:
> >> .. I had thought there might be a way of "building up" the "cellObject >> cellLock: aBoolean" ... judging from the replies, it seems that it is >> either a) crazy, b) it can't be done, c) no one knows how to do it. > > I don't know if I would say it is crazy but some might. Mostly I use VA > Smalltalk, it is designed more for business use that Squeak is (that's not > a knock on Squeak, it's just the way it is). In VA Smalltalk the compiler > is not included with the packaged images. In Squeak, you always live in > the image with the compiler. I expect there is a way to build up a string > that might look like this: "cell1 cellLock: true" and then send it to the > compiler and then execute the compiled code returned by the compiler. I > bet Bert and many other in the group know how to do this. But once you > play with collections, you will see it is not needed. Hah! Using the compiler is even more crazy than the meta programming facilities (thisContext, instVarNamed:). But yes, it's possible: Compiler new evaluate: 'cell1 cellLock: true' in: thisContext to: self - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Dawson
Hi Dawson,
>Snip... >Yes, I was using inexact language here (back to everything is an object >... are pointers in Squeak considered objects then? or is this a case of >something that isn't an object in Squeak?) Well everything is an object in Smalltalk. If you really had to you could probably get to the pointer that is in the instance variable. We should stop talking about it as a pointer. The only thing that cares it is a pointer is the Smalltalk/Squeak VM (virtual machine - usually a C program). The VM uses the pointer in the variable to find the data that is the object. It is much better to just think of the instance variables as the objects as long as we remember that more than one instance variable can address/access/point to the same object. Spoiler alert: I have written a Sudoku program and used many arrays to map the same cells to make it easier to check the values of the cells. One set of arrays would map the nine columns of cells. Another set of arrays maps the nine rows of cells. And another set to map the cells in a 3x3 block. Each cell is in more than one of the arrays. And the might themselves be in arrays. Lou ----------------------------------------------------------- Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:[hidden email] http://www.Keystone-Software.com _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Dawson
Dawson wrote:
I found Stephan Wessels' Laser Game [1] very useful as an end-to-end development example.Hi Louis, thanks for your very helpful posts, particularly the most recent one ... On 24/04/12 6:49 PM, Louis LaBrunda wrote:Hi Dawson and Dawson's 15 year old son, >From your code below, I assume that somewhere in your program you have created (instantiated) nine cells in instance variables named cell1-cell9.Yes, you are right .. these are instantiations of a class (more info in my other reply to Randal)This is fine but you should realize that they (cell1-cell9) are variables that hold pointers to the objects and not really the objects themselves. It is okay to think of them as the objects because for the most part it isYes, I was using inexact language here (back to everything is an object ... are pointers in Squeak considered objects then? or is this a case of something that isn't an object in Squeak?)easier than thinking of them as pointers to objects. The real point is to realize that more than one variable can point to the same instance of an object. For example, if I were to write: cell10 := cell1.Point taken. SNIPBack to your program. I assume that you have a good reason for putting the cells in variables named (cell1-cell9) and again that is fine but there is no reason why you can't have the same objects addressable or accessible from a collection.Yeah .. I suppose with very little context it looks like we haven't got a clue what we are doing. (Maybe we don't, but what we've written so far works even if there is a bit of brute force kind of stuff in there). To be honest, it is why we started asking questions, as a trained engineer, and as an artist, I like elegant solutions, perhaps that is what drew me to Squeak after my son began enquiring if we could learn it together. But our program right now is certainly not very elegant yet. As we learn more we can tweak it though.Smalltalk's collection classes are one of its many unknown treasures. They are a big part of why Smalltalk code is shorter and more understandable than code of other languages. Check them out. And please keep asking questions.Excellent. We have read the "Squeak by Example" book, but we don't always know how to use the stuff we've read about even after following the examples. We figured after we wrote this program, that we'd re-read the book, and get more out of it the next time through. Thanks again for taking the time to write your advice and suggestions, we appreciate it. Dawson _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners Seeing how the development of a whole application progresses using Squeak is quite insightful. It is written against an older Squeak 3.9, but I just downloaded that version to match the tutorial. [1] http://squeak.preeminent.org/tut2007/html/008.html http://squeak.preeminent.org/tut2007/html/ _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |