Re: [Pharo-users] why is asDictonary a class method
I think you probably need to show us *all* the code. directionLooking: aString self new direction: aString Well, there is your problem. There are two ways for a method to return a value. One is to execute '^ e' for some expression e, which is quite like a 'return e;' statement in C. The other is to execute the whole body and come to the end of the method, and in that case the result is always 'self'. This means that the method as you wrote it - created an uninitialised or incompletely initialised instance of Robot (self new) - asked that instance to set its direction - discarded the result of that setting - forgot the new instance - returned the Robot class What you probably meant was directionLooking: aString ^(self new) direction: aString; yourself where 'yourself' has nothing to do with a new object being created but with the fact that you want the new object as the result, not whatever #direction: returns. directionLooking: aString |newRobot| newRobot := self new. newRobot direction: aString. ^newRobot may be clearer to you. By the way, you didn't say WHY the caller wants a Dictionary instead of a Robot. I don't think I've ever written a program where that was a good idea. On Sun, 31 Mar 2019 at 19:55, Roelof Wobben wrote: > Op 31-3-2019 om 03:47 schreef Richard O'Keefe: > > Question 1. Should that be #asDictionary? > > > > yes, it does. > > Question 2. If not, what's a Dictonary? > Question 3. I see you are using self-encapsulation, > with a getter 'self robot' > and a setter 'self robot: something'. > Of course that means that outside code > can freely smash your "robot" property, > unless #robot: checks that its argument > makes sense. Does it? > > > > no, it does not. > > > Question 4. What kind of thing *is* "robot". > Have you checked that 'Robot directionLooking: ...' > returns an instance of Robot? If you accidentally > omitted '^' it might return the Robot class itself. > > > > yes, I forget the ^ thing > see this code. > > directionLooking: aString > self new direction: aString > > > so I have to think well how to return a instance of a Robot here. > > as far as I see I do not have a robot yet. > > createDirection: aString position: aCollection > self robot: (Robot directionLooking: aString) yourself. > ^ self robot asDictionary > > or I overlook something. > > > > Question 5. Are you sure that 'self robot' returns > what you think it does? Have you checked? > > > yes, I checked. self Robot give me a variable robot which is a Robot. > > Question 6. Does Robot have an #asDictionary method? > Does Robot have an #asDictonary method? > > > > Yes, it does > > Question 7. Why is "aCollection" not used in this method? > > > Because I wanted to be sure things are working before I added the > position which is a difficult one. > > Question 8. Why are you using 'yourself'? > > > I thought I was needed so I get a instance of a Robot back. > > Question 9. Why does the caller want a dictionary instead of > a Robot? What should be in that dictionary? > > > The same data as the Robot has but then in a dictionary form. > That is what I try to achieve. > > There are more questions but those will do to be going on with. > If your #robot: method began like > robot: aRobot > (aRobot isKindOf: Robot) > ifFalse: [aRobot error: 'not an instance of Robot']. > you would have caught what I suspect is your problem. > Check question 4. > > > > On Sun, 31 Mar 2019 at 07:19, Roelof Wobben wrote: > >> Hello, >> >> Im busy with a new challenge from exercism. >> Where I have to keep track of a robot , where it facing and on that >> coordinate the robot is. >> >> so I made this function what the test wanted >> >> createDirection: aString position: aCollection >> self robot: (Robot directionLooking: aString) yourself. >> ^ self robot asDictonary >> >> I can see that on the first part a new robot is made with the right data. >> but the test wants the data back as a Dictonary >> that is why I made the self robot asDictonary line >> >> but to my suprise the compiler wants it be a class method where I expect >> it to be a instance method. >> >> Can someone explain to my why this is ? >> >> Roelof >> >> >> >
Re: [Pharo-users] why is asDictonary a class method
Hi Richard/all - thanks for helping Roelof out. He’s working through the exercism.io exercises that we’ve managed to convert so far. As they are based on more C like languages, they aren’t always as OO as we want (once we get a decent set converted, we’ll try and add some smallish examples - anyone’s favourites appreciated). The dictionary reference is normally because the exercise tests like to assert on some description at the end (and dictionaries tend to exist universally in most languages). So view it more as a #printOn: like finalé (this said - Roelof might have this behaviour in the wrong place - but we will see). The feedback so far, seems to have helpfully unblocked him so thanks all. Tim Sent from my iPhone > On 31 Mar 2019, at 12:02, Richard O'Keefe wrote: > > I think you probably need to show us *all* the code. > > directionLooking: aString > self new direction: aString > > Well, there is your problem. > There are two ways for a method to return a value. > One is to execute '^ e' for some expression e, > which is quite like a 'return e;' statement in C. > The other is to execute the whole body and come to > the end of the method, and in that case the result > is always 'self'. This means that the method as you > wrote it > - created an uninitialised or incompletely initialised >instance of Robot (self new) > - asked that instance to set its direction > - discarded the result of that setting > - forgot the new instance > - returned the Robot class > > What you probably meant was > directionLooking: aString > ^(self new) direction: aString; yourself > where 'yourself' has nothing to do with a new > object being created but with the fact that > you want the new object as the result, not > whatever #direction: returns. > directionLooking: aString > |newRobot| > newRobot := self new. > newRobot direction: aString. > ^newRobot > may be clearer to you. > > By the way, you didn't say WHY the caller wants a Dictionary > instead of a Robot. I don't think I've ever written a program > where that was a good idea. > > > > >> On Sun, 31 Mar 2019 at 19:55, Roelof Wobben wrote: >> Op 31-3-2019 om 03:47 schreef Richard O'Keefe: >>> Question 1. Should that be #asDictionary? >> >> >> yes, it does. >> >>> Question 2. If not, what's a Dictonary? >>> Question 3. I see you are using self-encapsulation, >>> with a getter 'self robot' >>> and a setter 'self robot: something'. >>> Of course that means that outside code >>> can freely smash your "robot" property, >>> unless #robot: checks that its argument >>> makes sense. Does it? >> >> >> no, it does not. >> >> >>> Question 4. What kind of thing *is* "robot". >>> Have you checked that 'Robot directionLooking: ...' >>> returns an instance of Robot? If you accidentally >>> omitted '^' it might return the Robot class itself. >> >> >> yes, I forget the ^ thing >> see this code. >> >> directionLooking: aString >> self new direction: aString >> >> >> so I have to think well how to return a instance of a Robot here. >> >> as far as I see I do not have a robot yet. >> >> createDirection: aString position: aCollection >> self robot: (Robot directionLooking: aString) yourself. >> ^ self robot asDictionary >> >> or I overlook something. >> >> >> >>> Question 5. Are you sure that 'self robot' returns >>> what you think it does? Have you checked? >> >> yes, I checked. self Robot give me a variable robot which is a Robot. >> >>> Question 6. Does Robot have an #asDictionary method? >>> Does Robot have an #asDictonary method? >> >> >> Yes, it does >>> Question 7. Why is "aCollection" not used in this method? >> >> Because I wanted to be sure things are working before I added the position >> which is a difficult one. >> >>> Question 8. Why are you using 'yourself'? >> >> I thought I was needed so I get a instance of a Robot back. >> >>> Question 9. Why does the caller want a dictionary instead of >>> a Robot? What should be in that dictionary? >>> >> >> The same data as the Robot has but then in a dictionary form. >> That is what I try to achieve. >> >>> There are more questions but those will do to be going on with. >>> If your #robot: method began like >>> robot: aRobot >>> (aRobot isKindOf: Robot) >>> ifFalse: [aRobot error: 'not an instance of Robot']. >>> you would have caught what I suspect is your problem. >>> Check question 4. >>> >>> >>> On Sun, 31 Mar 2019 at 07:19, Roelof Wobben wrote: Hello, Im busy with a new challenge from exercism. Where I have to keep track of a robot , where it facing and on that coordinate the robot is. so I made this function what the test wanted createDirection: aString position: aCollection se
Re: [Pharo-users] why is asDictonary a class method
Tim Thanks I could not answer this because of the birtday of my wife today but you did a excellent job. Roelof Op 31-3-2019 om 17:29 schreef Tim Mackinnon: Hi Richard/all - thanks for helping Roelof out. He’s working through the exercism.io exercises that we’ve managed to convert so far. As they are based on more C like languages, they aren’t always as OO as we want (once we get a decent set converted, we’ll try and add some smallish examples - anyone’s favourites appreciated). The dictionary reference is normally because the exercise tests like to assert on some description at the end (and dictionaries tend to exist universally in most languages). So view it more as a #printOn: like finalé (this said - Roelof might have this behaviour in the wrong place - but we will see). The feedback so far, seems to have helpfully unblocked him so thanks all. Tim Sent from my iPhone On 31 Mar 2019, at 12:02, Richard O'Keefewrote: I think you probably need to show us *all* the code. directionLooking: aString self new direction: aString Well, there is your problem. There are two ways for a method to return a value. One is to execute '^ e' for some _expression_ e, which is quite like a 'return e;' statement in C. The other is to execute the whole body and come to the end of the method, and in that case the result is always 'self'. This means that the method as you wrote it - created an uninitialised or incompletely initialised instance of Robot (self new) - asked that instance to set its direction - discarded the result of that setting - forgot the new instance - returned the Robot class What you probably meant was directionLooking: aString ^(self new) direction: aString; yourself where 'yourself' has nothing to do with a new object being created but with the fact that you want the new object as the result, not whatever #direction: returns. directionLooking: aString |newRobot| newRobot := self new. newRobot direction: aString. ^newRobot may be clearer to you. By the way, you didn't say WHY the caller wants a Dictionary instead of a Robot. I don't think I've ever written a program where that was a good idea. On Sun, 31 Mar 2019 at 19:55, Roelof Wobben wrote: Op 31-3-2019 om 03:47 schreef Richard O'Keefe: Question 1. Should that be #asDictionary? yes, it does.
[Pharo-users] What's wrong with latest Pharo?
I just installed Pharo under Linux and when I start it up, I get: *Error: External module not found* It doesn't matter how I install Pharo.
Re: [Pharo-users] What's wrong with latest Pharo?
What Linux (distro and version) and which version of Pharo. You couldn’t supply less information if you tried. /*—-*/ Sent from my iPhone https://boincstats.com/signature/-1/user/51616339056/sig.png See https://objectnets.net and https://objectnets.org > On Mar 31, 2019, at 14:21, Richard Kenneth Eng > wrote: > > I just installed Pharo under Linux and when I start it up, I get: > > Error: External module not found > > It doesn't matter how I install Pharo.
Re: [Pharo-users] What's wrong with latest Pharo?
Come on, let’s try not to be dismissive , we’ve all had that annoying moment where something doesn’t work. Richard, was this installed with zero conf or Launcher, and as mentioned - a Linux distro is going to be helpful. I’m assuming it worked before at some point for you right? But was that v6 and now you’re trying v7? Tim Sent from my iPhone > On 31 Mar 2019, at 23:46, john pfersich wrote: > > What Linux (distro and version) and which version of Pharo. You couldn’t > supply less information if you tried. > > > /*—-*/ > Sent from my iPhone > https://boincstats.com/signature/-1/user/51616339056/sig.png > See https://objectnets.net and https://objectnets.org > >> On Mar 31, 2019, at 14:21, Richard Kenneth Eng >> wrote: >> >> I just installed Pharo under Linux and when I start it up, I get: >> >> Error: External module not found >> >> It doesn't matter how I install Pharo.
Re: [Pharo-users] What's wrong with latest Pharo?
> Am 01.04.2019 um 08:10 schrieb Tim Mackinnon : > > Come on, let’s try not to be dismissive , we’ve all had that annoying moment > where something doesn’t work. > Sure and we don‘t put that on a public mailing list. If you want to get help you need to provide context. Norbert > Richard, was this installed with zero conf or Launcher, and as mentioned - a > Linux distro is going to be helpful. > > I’m assuming it worked before at some point for you right? But was that v6 > and now you’re trying v7? > > Tim > > > Sent from my iPhone > >> On 31 Mar 2019, at 23:46, john pfersich wrote: >> >> What Linux (distro and version) and which version of Pharo. You couldn’t >> supply less information if you tried. >> >> >> /*—-*/ >> Sent from my iPhone >> https://boincstats.com/signature/-1/user/51616339056/sig.png >> See https://objectnets.net and https://objectnets.org >> >>> On Mar 31, 2019, at 14:21, Richard Kenneth Eng >>> wrote: >>> >>> I just installed Pharo under Linux and when I start it up, I get: >>> >>> Error: External module not found >>> >>> It doesn't matter how I install Pharo.