Hello,
Im still trying to make part1 of day2 working at a way I can also test things. the tests are working but when I call on the class side the method which should reed the masses which are on the instanc side , the masses cannnot be found. So question 1 is why is masses not found. and question 2 is how can I use the changed array at the process method so I can calculate the outcome. Regards, Roelof IntComputer.st (4K) Download Attachment |
I only skimmed over your code briefly. It seems you implemented a class
method #masses which returns stuff, but never call that method. You reference the class var #masses which is never initialized. So I guess there should be some place where you assign the return value of #masses to the masses variable....? HTH Joachim Am 31.12.19 um 12:00 schrieb Roelof Wobben: > Hello, > > Im still trying to make part1 of day2 working at a way I can also test > things. > the tests are working but when I call on the class side the method > which should reed the masses which are on the instanc side , the > masses cannnot be found. > > So question 1 is why is masses not found. > > and question 2 is how can I use the changed array at the process > method so I can calculate the outcome. > > Regards, > > Roelof > -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:[hidden email] Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1 |
Thanks.
I think I misunderstood you. There is a instance method called masses where all the numbers are mentioned. The class variable masses that I used there was just because masses were not understood but that one can be deleted. Roelof Op 31-12-2019 om 12:18 schreef [hidden email]: > I only skimmed over your code briefly. It seems you implemented a > class method #masses which returns stuff, but never call that method. > You reference the class var #masses which is never initialized. > > So I guess there should be some place where you assign the return > value of #masses to the masses variable....? > > HTH > > Joachim > > > > Am 31.12.19 um 12:00 schrieb Roelof Wobben: >> Hello, >> >> Im still trying to make part1 of day2 working at a way I can also >> test things. >> the tests are working but when I call on the class side the method >> which should reed the masses which are on the instanc side , the >> masses cannnot be found. >> >> So question 1 is why is masses not found. >> >> and question 2 is how can I use the changed array at the process >> method so I can calculate the outcome. >> >> Regards, >> >> Roelof >> > |
In reply to this post by jtuchel
Roelof,
I didn't import your code, just read the .st file in an editor, and I'm not an expert in Pharo source files, so maybe I overlooked something. I even don't have Pharo on this machine I'm sitting at. Still you seem to reference a variable called masses and send this as an argument to readRam. But I cannot find a method that would initialize this variable. Maybe what you wanted to write is readRam: self masses ??? Without the self keyword, you are referencing some variable instead of sending a message. Is that your problem? Joachim Am 31.12.19 um 12:26 schrieb Roelof Wobben: > Thanks. > > I think I misunderstood you. > > There is a instance method called masses where all the numbers are > mentioned. > The class variable masses that I used there was just because masses > were not understood but that one can be deleted. > > Roelof > > > > Op 31-12-2019 om 12:18 schreef [hidden email]: >> I only skimmed over your code briefly. It seems you implemented a >> class method #masses which returns stuff, but never call that method. >> You reference the class var #masses which is never initialized. >> >> So I guess there should be some place where you assign the return >> value of #masses to the masses variable....? >> >> HTH >> >> Joachim >> >> >> >> Am 31.12.19 um 12:00 schrieb Roelof Wobben: >>> Hello, >>> >>> Im still trying to make part1 of day2 working at a way I can also >>> test things. >>> the tests are working but when I call on the class side the method >>> which should reed the masses which are on the instanc side , the >>> masses cannnot be found. >>> >>> So question 1 is why is masses not found. >>> >>> and question 2 is how can I use the changed array at the process >>> method so I can calculate the outcome. >>> >>> Regards, >>> >>> Roelof >>> >> > > > -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:[hidden email] Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1 |
nope,
Then masses is still not understood , I tried that already and tried it a few moments ago. Roelof Op 31-12-2019 om 12:30 schreef [hidden email]: > Roelof, > > I didn't import your code, just read the .st file in an editor, and > I'm not an expert in Pharo source files, so maybe I overlooked > something. I even don't have Pharo on this machine I'm sitting at. > Still you seem to reference a variable called masses and send this as > an argument to readRam. But I cannot find a method that would > initialize this variable. Maybe what you wanted to write is > > readRam: self masses > > ??? > Without the self keyword, you are referencing some variable instead of > sending a message. Is that your problem? > > Joachim > > > Am 31.12.19 um 12:26 schrieb Roelof Wobben: >> Thanks. >> >> I think I misunderstood you. >> >> There is a instance method called masses where all the numbers are >> mentioned. >> The class variable masses that I used there was just because masses >> were not understood but that one can be deleted. >> >> Roelof >> >> >> >> Op 31-12-2019 om 12:18 schreef [hidden email]: >>> I only skimmed over your code briefly. It seems you implemented a >>> class method #masses which returns stuff, but never call that >>> method. You reference the class var #masses which is never initialized. >>> >>> So I guess there should be some place where you assign the return >>> value of #masses to the masses variable....? >>> >>> HTH >>> >>> Joachim >>> >>> >>> >>> Am 31.12.19 um 12:00 schrieb Roelof Wobben: >>>> Hello, >>>> >>>> Im still trying to make part1 of day2 working at a way I can also >>>> test things. >>>> the tests are working but when I call on the class side the method >>>> which should reed the masses which are on the instanc side , the >>>> masses cannnot be found. >>>> >>>> So question 1 is why is masses not found. >>>> >>>> and question 2 is how can I use the changed array at the process >>>> method so I can calculate the outcome. >>>> >>>> Regards, >>>> >>>> Roelof >>>> >>> >> >> >> > |
In reply to this post by jtuchel
I solved it but I think with ugly code on the class side.
solution | computer | computer := self new. computer readRam: computer masses. computer patchRam: 1 value: 12. computer patchRam: 2 value: 2. computer processData: computer ram. computer at: 0 Is there a way I can make this more smalltalk. Roelof Op 31-12-2019 om 12:36 schreef Roelof Wobben: > nope, > > Then masses is still not understood , I tried that already and tried > it a few moments ago. > > Roelof > > > > Op 31-12-2019 om 12:30 schreef [hidden email]: >> Roelof, >> >> I didn't import your code, just read the .st file in an editor, and >> I'm not an expert in Pharo source files, so maybe I overlooked >> something. I even don't have Pharo on this machine I'm sitting at. >> Still you seem to reference a variable called masses and send this as >> an argument to readRam. But I cannot find a method that would >> initialize this variable. Maybe what you wanted to write is >> >> readRam: self masses >> >> ??? >> Without the self keyword, you are referencing some variable instead >> of sending a message. Is that your problem? >> >> Joachim >> >> >> Am 31.12.19 um 12:26 schrieb Roelof Wobben: >>> Thanks. >>> >>> I think I misunderstood you. >>> >>> There is a instance method called masses where all the numbers are >>> mentioned. >>> The class variable masses that I used there was just because masses >>> were not understood but that one can be deleted. >>> >>> Roelof >>> >>> >>> >>> Op 31-12-2019 om 12:18 schreef [hidden email]: >>>> I only skimmed over your code briefly. It seems you implemented a >>>> class method #masses which returns stuff, but never call that >>>> method. You reference the class var #masses which is never >>>> initialized. >>>> >>>> So I guess there should be some place where you assign the return >>>> value of #masses to the masses variable....? >>>> >>>> HTH >>>> >>>> Joachim >>>> >>>> >>>> >>>> Am 31.12.19 um 12:00 schrieb Roelof Wobben: >>>>> Hello, >>>>> >>>>> Im still trying to make part1 of day2 working at a way I can also >>>>> test things. >>>>> the tests are working but when I call on the class side the method >>>>> which should reed the masses which are on the instanc side , the >>>>> masses cannnot be found. >>>>> >>>>> So question 1 is why is masses not found. >>>>> >>>>> and question 2 is how can I use the changed array at the process >>>>> method so I can calculate the outcome. >>>>> >>>>> Regards, >>>>> >>>>> Roelof >>>>> >>>> >>> >>> >>> >> > |
In reply to this post by Pharo Smalltalk Users mailing list
Hi
Roelof, I could file-in or look at your attached code to try to help, but its not clear what your question is or how to reproduce your scenario. You say... "when I call on the class side the method which should read the masses" which is a non-specific **description**. So I feel its extra work to try and decipher your question and perhaps I won't work it out and it would be wasted effort, which discourages me from trying to answer. Being more specific, something like... "when I call MyClass class>>myMethodXyz" would make feel like I have a chance at answering. Same for... "at the process method" - I see no method named #process so I can't guess what you question is. I've taken the time to provide this feedback to encourage you to improve your question to facilitate a better response. I recommend reading... http://www.catb.org/~esr/faqs/smart-questions.html (although the tone is a bit dark, there are some useful tidbits) P.S. Before your next (improved :^) restatement of your question, could you try an exercise... Slowly debug into the class-side call you are making, each step recording on paper on a new line the message sent, and on the same line the value of significant variables, to see if anything unexpected catches your attention. When the stepping is at a return statement ($^), select that statement and Inspect it, so you are sure of the value being returned. HTH. And btw, keep at it. The "process" of finding out why things don't work as expected is where you learn the most. On Tue, 31 Dec 2019 at 22:02, Roelof Wobben via Pharo-users <[hidden email]> wrote: Hello, |
In reply to this post by Pharo Smalltalk Users mailing list
On Tue, Dec 31, 2019 at 11:29 AM Roelof Wobben via Pharo-users
<[hidden email]> wrote: > > I solved it but I think with ugly code on the class side. > > solution > | computer | > computer := self new. > computer readRam: computer masses. > computer patchRam: 1 value: 12. > computer patchRam: 2 value: 2. > computer processData: computer ram. > computer at: 0 > > Is there a way I can make this more smalltalk. I don't know exactly why you mean by "more smalltalk", I don't know the problem you're solving, but you have a class side method that doesn't return anything, and the readRam: and processData: methods pass arguments that the receiver already have. So I'd do: solution | computer | computer := self new. computer readMasses; computer patchRam: 1 value: 12. computer patchRam: 2 value: 2. computer processRAMData. ^computer at: 0 "I don't know what this does". |
Administrator
|
In reply to this post by Pharo Smalltalk Users mailing list
Pharo Smalltalk Users mailing list wrote
> when I call on the class side the method which > should reed the masses which are on the instanc side , the masses > cannnot be found. IntComputer class >> solution | computer ram | computer := self new. computer readRam: masses. ... In your code above, you are not actually "calling a class-side method" (which BTW in Smalltalk the term is "sending a message", an important philosophical distinction if you want to grok Smalltalk), but referring to a class-side instance variable named "masses". The clue to this would have been that when you tried to compile the method, a dialog came up telling you about the undeclared variable. You seem to have clicked through choosing to create a variable, which you can now see in the class-side class definition: IntComputer class instanceVariableNames: 'masses' Probably you forgot to add "computer" before "masses", like so: `computer readRam: computer masses.` For future exploration, there are some design smells in your code, but it seems like you're currently at the "get it to work" stage, so it seems premature to dive into them here. NB: It will be much easier to help you in the future, if you include both of the following in your questions: 1. the exact error 2. "steps to reproduce" IOW in this case, something like: "I'm seeing '#splitOn: was sent to nil' from IntComputer class>>#readRam:. To reproduce, do `IntComputer solution`" This way we don't have to go hunting for an entry point, which will stop many (busy) people from even trying! ----- Cheers, Sean -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Cheers,
Sean |
Hello,
I have it now working but as you said there is a lot of code smells and my exact question is how to get rid of them. solution | computer | computer := self new. computer readRam: computer masses. computer patchRam: 1 value: 12. computer patchRam: 2 value: 2. computer processData: computer ram. computer at: 0 this is now a class method but I need a lot the computer variable. here you can find the whole code under intComputer class. Op 31-12-2019 om 19:29 schreef Sean P. DeNigris: > Pharo Smalltalk Users mailing list wrote >> when I call on the class side the method which >> should reed the masses which are on the instanc side , the masses >> cannnot be found. > IntComputer class >> solution > | computer ram | > computer := self new. > computer readRam: masses. > ... > > In your code above, you are not actually "calling a class-side method" > (which BTW in Smalltalk the term is "sending a message", an important > philosophical distinction if you want to grok Smalltalk), but referring to a > class-side instance variable named "masses". The clue to this would have > been that when you tried to compile the method, a dialog came up telling you > about the undeclared variable. You seem to have clicked through choosing to > create a variable, which you can now see in the class-side class definition: > IntComputer class > instanceVariableNames: 'masses' > > Probably you forgot to add "computer" before "masses", like so: `computer > readRam: computer masses.` > > For future exploration, there are some design smells in your code, but it > seems like you're currently at the "get it to work" stage, so it seems > premature to dive into them here. > > NB: It will be much easier to help you in the future, if you include both of > the following in your questions: > 1. the exact error > 2. "steps to reproduce" > > IOW in this case, something like: "I'm seeing '#splitOn: was sent to nil' > from IntComputer class>>#readRam:. To reproduce, do `IntComputer solution`" > > This way we don't have to go hunting for an entry point, which will stop > many (busy) people from even trying! > > > > ----- > Cheers, > Sean > -- > Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html > > |
Op 1-1-2020 om 17:27 schreef Roelof
Wobben via Pharo-users:
Hello, I made some changes. Is this better or are there still some code smells. Code : https://github.com/rwobben/intComputer/blob/master/AOC%202019/IntComputer.class.st if so, can someone help me to solve the code smells. Here is the challenge I try to solve : On the way to your gravity assist around the Moon, your ship computer beeps angrily about a "1202 program alarm". On the radio, an Elf is already explaining how to handle the situation: "Don't worry, that's perfectly norma--" The ship computer bursts into flames. You notify the Elves that the computer's magic smoke seems to have escaped. "That computer ran Intcode programs like the gravity assist program it was working on; surely there are enough spare parts up there to build a new Intcode computer!" An Intcode program is a list of integers
separated by commas (like Opcode For example, if your Intcode computer encounters Opcode Once you're done processing an opcode, move to the next one
by stepping forward For example, suppose you have the following program:
For the purposes of illustration, here is the same program split into multiple lines:
The first four integers,
Step forward
Stepping forward |
Hi Roelof, It looks pretty good to me with methods generally being small and doing one thing. The way your class-side-method "IntComputer class >> solution" just creates an instance and sends #process is good. I'm a little curious that it doesn't return a value. #process returns a value but nothing is done with it. I guess the test-frame doesn't require it. The way zero-index ram access is
encapsulated by #at: and #at:put: is good. Possible cleanup, #in and #in: don't seem required since variable "in" is used directly in the rest of the code, which is fine. The hardcoded #masses return value is fine, except it makes the "masses" class variable redundant. Your various #processXXX methods are succinct and consume the stream neatly. However its curious your #processData and #processData: methods have identical code, since the latter has an argument that is then not used. So your code is working a bit by accident. At line 59 (https://github.com/rwobben/intComputer/blob/master/AOC%202019/IntComputer.class.st#L59) its just lucky that the "self ram" you pass
there
to #processData: is the same as the "ram" variable referenced Well done. cheers -ben On Thu, 2 Jan 2020 at 23:37, Roelof Wobben via Pharo-users <[hidden email]> wrote:
|
Hello Ben.
That was a error . There schould be a caret for it. Im talking about the solution method. No, I cannot clean the in part because it is used in the process* methods The processData: can also be deleted . I think Its a part of a earlier try to solve it. and yes. the ram is the same at both places. Is there then a better way to pass the stream around. and of course thanks for the feedback. Roelof Op 2-1-2020 om 14:27 schreef Ben Coman:
|
Administrator
|
In reply to this post by Pharo Smalltalk Users mailing list
Pharo Smalltalk Users mailing list wrote
> I made some changes. Is this better or are there still some code > smells. I don't have time for an in-depth review, but I skimmed it and it seems better. ----- Cheers, Sean -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Cheers,
Sean |
In reply to this post by Ben Coman
On Fri, 3 Jan 2020 at 00:41, Roelof Wobben <[hidden email]> wrote:
But its not. Your statement would be true if your processXXX methods did... a := self at: self in next. but they don't, instead you have... a := self at: in next. You never send the #in message, which is fine since "information hiding" can be useful to avoid exposing your internal representation that the outside doesn't need to know about. (the proof is in the pudding, see if it works after deleting #in and #in:)
I think its fine how you've done it. Final thing is to clean up the "class-instance variable" (i.e. class-side instance variable) which Sean mentioned. You can see it here... To remove it from the image, in the System Browser while viewing the class definition, click the "Class" button and you should see it. cheers -ben
|
Free forum by Nabble | Edit this page |