[Pharo-users] why is masses not found?
--- Begin Message --- 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 'From Pharo8.0.0 of 26 December 2019 [Build information: Pharo-8.0.0+build.1095.sha.a3829b06f0bc488adf52053b1dd7a5f0a2c6c499 (64 Bit)] on 31 December 2019 at 11:56:11.318362 am'! Object subclass: #IntComputer instanceVariableNames: 'ram in' classVariableNames: '' package: 'AOC 2019'! !IntComputer methodsFor: 'accessing' stamp: 'RoelofWobben 12/28/2019 08:36'! in ^ in! ! !IntComputer methodsFor: 'accessing' stamp: 'RoelofWobben 12/28/2019 08:36'! ram: anObject ram := anObject! ! !IntComputer methodsFor: 'accessing' stamp: 'RoelofWobben 12/28/2019 08:38'! in: anObject in := anObject! ! !IntComputer methodsFor: 'accessing' stamp: 'RoelofWobben 12/28/2019 08:36'! ram ^ ram! ! !IntComputer methodsFor: 'calculations' stamp: 'RoelofWobben 12/29/2019 18:18'! masses ^ '1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,6,19,1,19,5,23,2,13,23,27,1,10,27,31,2,6,31,35,1,9,35,39,2,10,39,43,1,43,9,47,1,47,9,51,2,10,51,55,1,55,9,59,1,59,5,63,1,63,6,67,2,6,67,71,2,10,71,75,1,75,5,79,1,9,79,83,2,83,10,87,1,87,6,91,1,13,91,95,2,10,95,99,1,99,6,103,2,13,103,107,1,107,2,111,1,111,9,0,99,2,14,0,0 '! ! !IntComputer methodsFor: 'processing' stamp: 'RoelofWobben 12/29/2019 13:23'! processData: anArray | op | in := ReadStream on: ram. [ (op := in next) = 99 ] whileFalse: [ self processOpcode: op ]. ^ self at: 0! ! !IntComputer methodsFor: 'processing' stamp: 'RoelofWobben 12/29/2019 13:24'! processData | op | in := ReadStream on: ram. [ (op := in next) = 99 ] whileFalse: [ self processOpcode: op ]. ^ self at: 0! ! !IntComputer methodsFor: 'processing' stamp: 'RoelofWobben 12/29/2019 13:25'! readRam: anArray ram := (anArray splitOn: ',') collect: [ :ea | ea asInteger ].! ! !IntComputer methodsFor: 'processing' stamp: 'RoelofWobben 12/29/2019 18:15'! patchRam: position value: value self at: position put: value ! ! !IntComputer methodsFor: 'running' stamp: 'RoelofWobben 12/28/2019 08:33'! at: idx ^ram at: idx + 1! ! !IntComputer methodsFor: 'running' stamp: 'RoelofWobben 12/28/2019 08:35'! at: idx put: value ^ ram at: idx +1 put: value! ! !IntComputer methodsFor: 'running' stamp: 'RoelofWobben 12/28/2019 08:31'! processMultiply | a b c | a := self at: in next. b := self at: in next. self at: in next put: a*b! ! !IntComputer methodsFor: 'running' stamp: 'RoelofWobben 12/28/2019 08:32'! processAdd | a b| a := self at: in next. b := self at: in next. self at: in next put: a + b! ! !IntComputer methodsFor: 'running' stamp: 'RoelofWobben 12/28/2019 08:31'! processOpcode: op op = 1 ifTrue: [ ^self processAdd ]. op = 2 ifTrue: [ ^self processMultiply ].! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! IntComputer class instanceVariableNames: 'masses'! !IntComputer class methodsFor: 'as yet unclassified' stamp: 'RoelofWobben 12/29/2019 19:39'! solution | computer ram | computer := self new. computer readRam: masses. computer patchRam: 1 value: 12. computer patchRam: 2 value: 2. computer processData: ram. computer at: 0! ! --- End Message ---
Re: [Pharo-users] why is masses not found?
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:jtuc...@objektfabrik.de 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
Re: [Pharo-users] why is masses not found?
--- Begin Message --- 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 jtuc...@objektfabrik.de: 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 --- End Message ---
Re: [Pharo-users] why is masses not found?
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 jtuc...@objektfabrik.de: 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:jtuc...@objektfabrik.de 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
Re: [Pharo-users] why is masses not found?
--- Begin Message --- 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 jtuc...@objektfabrik.de: 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 jtuc...@objektfabrik.de: 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 --- End Message ---
Re: [Pharo-users] why is masses not found?
--- Begin Message --- 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 jtuc...@objektfabrik.de: 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 jtuc...@objektfabrik.de: 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 --- End Message ---
Re: [Pharo-users] why is masses not found?
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) cheers -ben 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 < pharo-users@lists.pharo.org> wrote: > 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 > >
Re: [Pharo-users] why is masses not found?
On Tue, Dec 31, 2019 at 11:29 AM Roelof Wobben via Pharo-users 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".
Re: [Pharo-users] why is masses not found?
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