[Pharo-users] help with understanding the visitor pattern

2019-10-16 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

Im busy with this project: https://github.com/RoelofWobben/Die

Now I also want to try to add a DieHandler and a Die together.
And I heared you can use the visitor pattern to solve this.

As far as  I understand the pattern I have to make a new class which 
contains only the + method.


But I fail to understand to see how I can make a difference between the 
+ of a Die and the + of a DieHandler.


So can someone help me understand this pattern and maybe learn me step 
by step how to implement this in my code.


Regards,

Roelof


--- End Message ---


[Pharo-users] help bij one of the last challenges of the chapterof network simulation of the oop book.

2019-10-29 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Hello, 

I have to  made this challenge as last on of the OOP book 

Servers answering requests
  
When a server node consumes a
  packet, it converts the payload to uppercase,
  then sends that back to the sender of the request. 

This is yet another subclass which
  redefines the consume: method, but this
  time the node is stateless, so we have no initialization or
  accessor methods to
  write:
  
KANetworkNode
  subclass: #KANetworkServer
  instanceVariableNames: ''
  classVariableNames: ''
  category: 'NetworkSimulator-Nodes'
  
  KANetworkServer >> consume: aPacket
  | response |
  response := aPacket payload asUppercase.
  self send: (KANetworkPacket
  from: self address
  to: aPacket sourceAddress
  payload: response)
  
  
Define a test for the behavior of
  server nodes. 


I tried but I miss something 

so far as I have this : 

testSendToServer
    | packet ping pong link |
    packet := KANetworkPacket from: #ping to: #pong payload: #ball.
    ping := net nodeAt: #ping.
    pong := net nodeAt: #pong.
    link := net linkFrom: #ping to: #pong.
    ping send: packet.
    pong consume: packet.

but whatever I tried I cannot think of a test that works.

I tried 

assert:  ping payload equals: #BALL
assert: ping arrievedpackages equals; 1 

but they all fail

It looks like ping does not recieve the package back. 

What do I do wrong or what can I test better ?

my code so far : https://github.com/RoelofWobben/network

and the problem is the testToServerTest that I cannot make work 

Regards, 

Roelof 
 
  


--- End Message ---


Re: [Pharo-users] help bij one of the last challenges of the chapterof network simulation of the oop book.

2019-10-29 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Thanks,

That part I understand  but what I try  to say is that if I understand 
the code right the string BALL  is send back to the node that send the 
orginal messsgae #ball.  But as I said that one do not seem to recieve 
any packages and my question is still why ?


I debugged it several times but I do not see the reason.

Roelof



Op 30-10-2019 om 01:38 schreef Richard O'Keefe:

The first question you should ask is "What do I expect #ball asUppercase to be?"
The ANSI Smalltalk standard says
5.7.10.9 Message:  asUppercase
Synopsis
   Answer a new string which contains all of the elements of the
receiver converted to their upper
case equivalents.
Definition: 
   Answer a new string which contains all of the elements of the
receiver converted to their upper
case equivalents. Individual element of the string are converted as if
they were receivers of the
message #asUppercase.
Return Values
new
Errors
   none

Notice the word "string", the protocol "", and the
entire absence of anything
suggesting that the receiver and result belong to the same class.

In my Smalltalk library, the receiver and result DO belong to the same class,
so #ball asUppercase ==> #BALL.
But the ANSI standard does not require that.
And I may change my library, because
GNU Smalltalk, Dolphin Smalltalk, Smalltalk/X, Squeak, and Pharo
all return a String.  (On the other hand, one reason I wrote my Smalltalk
was to press the edges of the ANSI standard, so maybe I'll leave it.)

So I think where you have #BALL you should have 'BALL'.
There may be other issues.

On Wed, 30 Oct 2019 at 11:00, Roelof Wobben via Pharo-users
 wrote:

Hello,

I have to  made this challenge as last on of the OOP book

Servers answering requests

When a server node consumes a packet, it converts the payload to uppercase,
then sends that back to the sender of the request.

This is yet another subclass which redefines the consume: method, but this
time the node is stateless, so we have no initialization or accessor methods to
write:

KANetworkNode subclass: #KANetworkServer
instanceVariableNames: ''
classVariableNames: ''
category: 'NetworkSimulator-Nodes'

KANetworkServer >> consume: aPacket
| response |
response := aPacket payload asUppercase.
self send: (KANetworkPacket
from: self address
to: aPacket sourceAddress
payload: response)


Define a test for the behavior of server nodes.


I tried but I miss something

so far as I have this :

testSendToServer
 | packet ping pong link |
 packet := KANetworkPacket from: #ping to: #pong payload: #ball.
 ping := net nodeAt: #ping.
 pong := net nodeAt: #pong.
 link := net linkFrom: #ping to: #pong.
 ping send: packet.
 pong consume: packet.

but whatever I tried I cannot think of a test that works.

I tried

assert:  ping payload equals: #BALL
assert: ping arrievedpackages equals; 1

but they all fail

It looks like ping does not recieve the package back.

What do I do wrong or what can I test better ?

my code so far : https://github.com/RoelofWobben/network

and the problem is the testToServerTest that I cannot make work

Regards,

Roelof




--- End Message ---


Re: [Pharo-users] help bij one of the last challenges of the chapterof network simulation of the oop book.

2019-10-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

I solved that part but I wonder if  some one can give me a hint how I 
can read the package send from the server


consume seems to return a node and not a package.

Roelof




Op 30-10-2019 om 06:56 schreef Roelof Wobben:

Thanks,

That part I understand  but what I try  to say is that if I understand 
the code right the string BALL  is send back to the node that send the 
orginal messsgae #ball.  But as I said that one do not seem to recieve 
any packages and my question is still why ?


I debugged it several times but I do not see the reason.

Roelof



Op 30-10-2019 om 01:38 schreef Richard O'Keefe:
The first question you should ask is "What do I expect #ball 
asUppercase to be?"

The ANSI Smalltalk standard says
5.7.10.9 Message:  asUppercase
Synopsis
   Answer a new string which contains all of the elements of the
receiver converted to their upper
case equivalents.
Definition: 
   Answer a new string which contains all of the elements of the
receiver converted to their upper
case equivalents. Individual element of the string are converted as if
they were receivers of the
message #asUppercase.
Return Values
    new
Errors
   none

Notice the word "string", the protocol "", and the
entire absence of anything
suggesting that the receiver and result belong to the same class.

In my Smalltalk library, the receiver and result DO belong to the 
same class,

so #ball asUppercase ==> #BALL.
But the ANSI standard does not require that.
And I may change my library, because
GNU Smalltalk, Dolphin Smalltalk, Smalltalk/X, Squeak, and Pharo
all return a String.  (On the other hand, one reason I wrote my 
Smalltalk

was to press the edges of the ANSI standard, so maybe I'll leave it.)

So I think where you have #BALL you should have 'BALL'.
There may be other issues.

On Wed, 30 Oct 2019 at 11:00, Roelof Wobben via Pharo-users
 wrote:

Hello,

I have to  made this challenge as last on of the OOP book

Servers answering requests

When a server node consumes a packet, it converts the payload to 
uppercase,

then sends that back to the sender of the request.

This is yet another subclass which redefines the consume: method, 
but this
time the node is stateless, so we have no initialization or accessor 
methods to

write:

KANetworkNode subclass: #KANetworkServer
instanceVariableNames: ''
classVariableNames: ''
category: 'NetworkSimulator-Nodes'

KANetworkServer >> consume: aPacket
| response |
response := aPacket payload asUppercase.
self send: (KANetworkPacket
from: self address
to: aPacket sourceAddress
payload: response)


Define a test for the behavior of server nodes.


I tried but I miss something

so far as I have this :

testSendToServer
 | packet ping pong link |
 packet := KANetworkPacket from: #ping to: #pong payload: #ball.
 ping := net nodeAt: #ping.
 pong := net nodeAt: #pong.
 link := net linkFrom: #ping to: #pong.
 ping send: packet.
 pong consume: packet.

but whatever I tried I cannot think of a test that works.

I tried

assert:  ping payload equals: #BALL
assert: ping arrievedpackages equals; 1

but they all fail

It looks like ping does not recieve the package back.

What do I do wrong or what can I test better ?

my code so far : https://github.com/RoelofWobben/network

and the problem is the testToServerTest that I cannot make work

Regards,

Roelof






--- End Message ---


Re: [Pharo-users] help bij one of the last challenges of the chapterof network simulation of the oop book.

2019-10-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
I did already and noticed that the text
  is changed.
  and I noticed that the payload is only avaible at a link.
  
  or if I made the node that sends is a Node and not a Workstation
  or  whatever because they do not store the payload somewhere. 
  
  Roelof
  
  
  Op 30-10-2019 om 10:06 schreef Stéphane Ducasse:


  
  Put a breakpoint.
  
  
  What you are learning is how to help yourself and
this is 80% of programming. 
  
  
  S. 

  
On 30 Oct 2019, at 08:30, Roelof Wobben <r.wob...@home.nl> wrote:


  From: Roelof Wobben
  <r.wob...@home.nl>

  Subject: Re:
[Pharo-users] help bij one of the last challenges of
the chapterof network simulation of the oop book.

  Date: 30 October 2019
  at 08:30:14 CET

  To: Any question
  about pharo is welcome <pharo-users@lists.pharo.org>

  
  
  Hello,
  
  I solved that part but I wonder if  some one can give me a
  hint how I can read the package send from the server
  
  consume seems to return a node and not a package.
  
  Roelof
  
  
  
  
  Op 30-10-2019 om 06:56 schreef Roelof Wobben:
  Thanks,

That part I understand  but what I try  to say is that
if I understand the code right the string BALL  is send
back to the node that send the orginal messsgae #ball. 
But as I said that one do not seem to recieve any
packages and my question is still why ?

I debugged it several times but I do not see the reason.

Roelof



Op 30-10-2019 om 01:38 schreef Richard O'Keefe:
The first question you
  should ask is "What do I expect #ball asUppercase to
  be?"
  The ANSI Smalltalk standard says
  5.7.10.9 Message:  asUppercase
  Synopsis
     Answer a new string which contains all of the
  elements of the
  receiver converted to their upper
  case equivalents.
  Definition: 
     Answer a new string which contains all of the
  elements of the
  receiver converted to their upper
  case equivalents. Individual element of the string are
  converted as if
  they were receivers of the
  message #asUppercase.
  Return Values
      new
  Errors
     none
  
  Notice the word "string", the protocol
  "", and the
  entire absence of anything
  suggesting that the receiver and result belong to the
  same class.
  
  In my Smalltalk library, the receiver and result DO
  belong to the same class,
  so #ball asUppercase ==> #BALL.
  But the ANSI standard does not require that.
  And I may change my library, because
  GNU Smalltalk, Dolphin Smalltalk, Smalltalk/X, Squeak,
  and Pharo
  all return a String.  (On the other hand, one reason I
  wrote my Smalltalk
  was to press the edges of the ANSI standard, so maybe
  I'll leave it.)
  
  So I think where you have #BALL you should have
  'BALL'.
  There may be other issues.
          
  On Wed, 30 Oct 2019 at 11:00, Roelof Wobben via
  Pharo-users
  <pharo-users@lists.pharo.org>
  wrote:
  Hello,

I have to  made this challenge as last on of the OOP
book

Servers answering requests

When a server node consumes a packet, it converts
the payload to uppercase,
then sends that back to the sender of the request.

This is yet another subclass which redefines the
consume: m

Re: [Pharo-users] help bij one of the last challenges of the chapterof network simulation of the oop book.

2019-10-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Did find two possibly solutions but I
  think difficult to implement
  
  
  
  or 
  
  
  
  
  
  
  but on the second I see that every time the package is on another
  place.
  
  
  So someone some tips how to implement one of the two ?
  
  Roelof
  
  
  Op 30-10-2019 om 12:20 schreef Roelof Wobben:


  
  I did already and noticed that the
text is changed.
and I noticed that the payload is only avaible at a link.

or if I made the node that sends is a Node and not a Workstation
or  whatever because they do not store the payload somewhere. 

Roelof


Op 30-10-2019 om 10:06 schreef Stéphane Ducasse:
  
  

Put a breakpoint.


What you are learning is how to help yourself and
  this is 80% of programming. 


S. 
  

  On 30 Oct 2019, at 08:30, Roelof Wobben <r.wob...@home.nl> wrote:
  
  
From: Roelof Wobben
<r.wob...@home.nl>
  
Subject: Re:
  [Pharo-users] help bij one of the last challenges
  of the chapterof network simulation of the oop
  book.
  
Date: 30 October
2019 at 08:30:14 CET
  
To: Any question
about pharo is welcome <pharo-users@lists.pharo.org>
  


Hello,

I solved that part but I wonder if  some one can give me
a hint how I can read the package send from the server

consume seems to return a node and not a package.

Roelof




Op 30-10-2019 om 06:56 schreef Roelof Wobben:
Thanks,
  
  That part I understand  but what I try  to say is that
  if I understand the code right the string BALL  is
  send back to the node that send the orginal messsgae
  #ball.  But as I said that one do not seem to recieve
  any packages and my question is still why ?
  
  I debugged it several times but I do not see the
  reason.
  
  Roelof
  
  
  
  Op 30-10-2019 om 01:38 schreef Richard O'Keefe:
  The first question
you should ask is "What do I expect #ball
asUppercase to be?"
The ANSI Smalltalk standard says
5.7.10.9 Message:  asUppercase
Synopsis
   Answer a new string which contains all of the
elements of the
receiver converted to their upper
case equivalents.
Definition: 
   Answer a new string which contains all of the
elements of the
receiver converted to their upper
case equivalents. Individual element of the string
are converted as if
they were receivers of the
message #asUppercase.
Return Values
    new
Errors
   none

Notice the word "string", the protocol
"", and the
entire absence of anything
suggesting that the receiver and result belong to
the same class.

In my Smalltalk library, the receiver and result DO
belong to the same class,
so #ball asUppercase ==> #BALL.
But the ANSI standard does not require that.
And I may change my library, because
GNU Smalltalk, Dolphin Smalltalk, Smalltalk/X,
Squeak, and Pharo
all return a String.  (On the other hand, one reason
I wrote my Smalltalk
was to press the edges of the ANSI standard, so
maybe I'll leave it.)

So I think where you have #BALL you should have
'BALL'.
There may be other issues.
            
    On Wed, 

[Pharo-users] can I somehow test the contents of a package

2019-11-13 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

IM doing now this book to understand better the OOP side of Pharo : 
https://books.pharo.org/learning-oop/


im now at the last challenge of the network-simulator and im stuck.

I want to test if the send package is really send back uppercase but I 
cannot find a way to see the contents of the package in my test I have 
made so far : 
https://github.com/RoelofWobben/network/blob/master/NetworkSimulator-Tests/KANetworkTest.class.st#L145


Can anyone give me a hint how I can achieve what I want ?

Regards,

Roelof


--- End Message ---


[Pharo-users] some sort of mentor help ?

2019-12-03 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Hello, 

do not know if this is the right channel but is there someone or
some book which can help me learn how to approach complex problems
like the AdventOfCode challenges , I try that but im stuck because
most of the time I have the feeling I choose a difficult solution
where some easier one exist.

  

  or I have a very bad plan

  


  that is a wall I hit many times with my
languages and I need a way to get out of it and make a step
further with Pharo

Regards, 

Roelof 

  

  


--- End Message ---


[Pharo-users] twilllio quest

2019-12-10 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

I wonder if I can solve the TwillioQuest with Pharo.

I then have to write code to send SMS and return a respons a a SMS.
is this possible in Pharo and can I use for example teapot for it ?

and if it possible does anyone have a example of how to send a SMS with 
Twillio.


Regards,

Roelof


--- End Message ---


[Pharo-users] sot of mentor help (second time asking)

2019-12-12 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Hello, 

do not know if this is the right channel but is there someone or
some book which can help me learn how to approach complex problems
like the AdventOfCode challenges , I try that but im stuck because
most of the time I have the feeling I choose a difficult solution
where some easier one exist.

  

  or I have a very bad plan

  

that is a wall I hit many times with my languages and I need a way
to get out of it and make a step further with Pharo

I ask earlier and somone volunteeed and I hope he or another person
would help me. 
With the earlier volunteeer it did not work because I m not always
understand him/her and want to apolize for that and the way I ended
it. it was not a nice way. 

Regards, 

Roelof
  


--- End Message ---


Re: [Pharo-users] sot of mentor help (second time asking)

2019-12-16 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Pity that no one answers.
  
  Is it a possibility to ask for feedback for the ones that I can
  solve and ask for some pointers for the one I have no clue how to
  solve them.
  
  So anyone who can  and is willing to help me can respond.
  
  Roelof
  
  
  
  Op 12-12-2019 om 19:11 schreef Roelof Wobben:


  
  Hello, 
  
  do not know if this is the right channel but is there someone or
  some book which can help me learn how to approach complex problems
  like the AdventOfCode challenges , I try that but im stuck because
  most of the time I have the feeling I choose a difficult solution
  where some easier one exist.
  

  
or I have a very bad plan
  

  
  that is a wall I hit many times with my languages and I need a way
  to get out of it and make a step further with Pharo
  
  I ask earlier and somone volunteeed and I hope he or another
  person would help me. 
  With the earlier volunteeer it did not work because I m not always
  understand him/her and want to apolize for that and the way I
  ended it. it was not a nice way. 
  
  Regards, 
  
  Roelof 

  


--- End Message ---


Re: [Pharo-users] sot of mentor help (second time asking)

2019-12-16 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Oke,
  
  So I can ask feedback on challenges or hints here if I understand
  you well.
  if so, that could also work for me.
  
  Roelof
  
  
  
  Op 16-12-2019 om 14:33 schreef Esteban Lorenzano:


  
  Hello, 
  
  
  I don’t think anyone will answer positively this
kind of question (mentoring is time consuming, and requires a
dedication probably nobody can take) :)
  But what you can do is to ask direct questions,
those ones we are always happy to answer, here or in discord
channel.
  
  
  Cheers,
  Esteban
  

  
On 16 Dec 2019, at 13:56, Roelof Wobben via
  Pharo-users <pharo-users@lists.pharo.org>
  wrote:


  From: Roelof Wobben
  <r.wob...@home.nl>

  Subject: Re:
sot of mentor help (second time asking)

  Date: 16 December
  2019 at 13:56:15 CET

  To: Any question
  about pharo is welcome <pharo-users@lists.pharo.org>

  
  
  
  
Pity that no one answers.
  
  Is it a possibility to ask for feedback for the ones
  that I can solve and ask for some pointers for the one
  I have no clue how to solve them.
  
  So anyone who can  and is willing to help me can
  respond.
  
  Roelof
  
  
  
  Op 12-12-2019 om 19:11 schreef Roelof Wobben:


  
  Hello, 
  
  do not know if this is the right channel but is there
  someone or some book which can help me learn how to
  approach complex problems like the AdventOfCode
  challenges , I try that but im stuck because most of
  the time I have the feeling I choose a difficult
  solution where some easier one exist.
  

  
or I have a very bad
  plan
  

  
  that is a wall I hit many times with my languages and
  I need a way to get out of it and make a step further
  with Pharo
  
  I ask earlier and somone volunteeed and I hope he or
  another person would help me. 
  With the earlier volunteeer it did not work because I
  m not always understand him/her and want to apolize
  for that and the way I ended it. it was not a nice
  way. 
  
  Regards, 
  
  Roelof 

  
  
  

  


  


  


--- End Message ---


[Pharo-users] how can I this refractor this so its more smalltalk

2019-12-17 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

My solution to day2 part1 is right this :

processData: instructions
    | opcode index firstNumber secondNumber placeToPut firstNumberIndex 
secondNumberIndex |

    index := 1.
    opcode := instructions at: index.
    [ opcode ~= 99 ]
        whileTrue: [ firstNumberIndex := instructions at: index + 1.
            secondNumberIndex := instructions at: index + 2.
            firstNumber := instructions at: firstNumberIndex + 1.
            secondNumber := instructions at: secondNumberIndex + 1.
            placeToPut := (instructions at: index + 3) + 1.
            opcode == 1
                ifTrue: [ instructions at: placeToPut put: firstNumber 
+ secondNumber ].

            opcode == 2
                ifTrue: [ instructions at: placeToPut put: firstNumber 
* secondNumber ].

            index := index + 4.
            opcode := instructions at: index ].
    ^ instructions at: 1

so its ugly code

is there a way  I can this more the smalltalk way by using streams or 
something else.
if so, is there someone who can tell me or can let me see how to make 
this cleaner code


Roelof


--- End Message ---


Re: [Pharo-users] how can I this refractor this so its more smalltalk

2019-12-17 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
of course but you have to use a githut
  account to reach it.
  
  All the puzzles can be found here :  https://adventofcode.com/
  
  I try to solve day2 and then part1. 
  
  Roelof
  
  
  Op 17-12-2019 om 18:33 schreef Kasper Osterbye:


  
  
Hi Roelof
  
  
  I saw your posts earlier, and will try to take a look. I
am not into the advent of code myself, but love a good
puzzle. Would it be possible to provide a link to the puzzle
you are trying to solve?

  


  


--- End Message ---


[Pharo-users] can I write this without the three if then;s

2019-12-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Hello, 

Im trying to solve a challenge from exercism where  I have to
calculate the points somehow gets on a very simple darts board.

I solved it like this : 

  
  scoreX: anInteger y: anInteger2
      | distance |
      distance := (anInteger squared + anInteger2 squared) sqrt.
      distance > 10
          ifTrue: [ ^ 0 ].
      distance > 5
          ifTrue: [ ^ 1 ].
      distance > 1
          ifTrue: [ ^ 5 ].
      ^ 10
  
  
  but now I use three if then and I think it's ugly code. 
  
  Is there a way I can make it more the smalltalk way ? 
  
  
  Regards, 
  
  Roelof

  


--- End Message ---


Re: [Pharo-users] can I write this without the three if then;s

2019-12-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Thanks,

But it looks to me I still need the ifTrue because the between gives 
also a true or false.


Roelof



Op 27-12-2019 om 20:38 schreef tbrunz:

You might try Magnitude >> between: min and: max




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html





--- End Message ---


Re: [Pharo-users] can I write this without the three if then;s

2019-12-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Hello Kasper
  
  Thanks for the feedback.
  
  I also like readable and  easy to understand code but I get the
  feeling that it;s good practice to use as minimal as possible if
  then's 
  So I wonder if and how I can achieve that here.
  
  Roelof
  
  
  Op 27-12-2019 om 20:47 schreef Kasper Østerbye:


  
  
  Hi
  
  
  First, I
think your code is readable and easy to understand.
  
  
  I think
the problem does not lend itself too much towards having “an
object oriented solution”, as such.
  
  
  If you are
looking for a one-liner using smalltalk libraries, you could do:
  ({10 ->
0. 5 -> 1. 1 -> 5. 0 -> 10} detect: [ :dist | dist key
< distance ]) value
  
  
  but I
really think your code is easier to read, which is what I
appreciate the most.
  
  
  Best,
  
  
  Kasper

On 27 December 2019 at 20.18.38, Roelof
      Wobben via Pharo-users (pharo-users@lists.pharo.org)
  wrote:


  

  
  Hello,
  
  Im trying to solve a challenge from exercism where  I
  have to
  calculate the points somehow gets on a very simple
  darts
  board.
  
  I solved it like this :
  

scoreX: anInteger y: anInteger2
    | distance |
    distance := (anInteger squared + anInteger2
squared) sqrt.
    distance > 10
        ifTrue: [ ^ 0 ].
    distance > 5
        ifTrue: [ ^ 1 ].
    distance > 1
        ifTrue: [ ^ 5 ].
    ^ 10


but now I use three if then and I think it's ugly
code.

Is there a way I can make it more the smalltalk way
?


Regards,

Roelof
  

  

  
  


  


--- End Message ---


[Pharo-users] uses or instead of a searching literal

2019-12-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Hello, 


How can I get rid of the above error message with this code : 


abbreviatePhrase: aString
| splitted |
splitted := aString
splitOn: [ :char | char = Character space or: [ char = $- or: [ char = $_ ] ] ].
^ String
streamContents: [ :stream | 
splitted
reject: [ :word | word isEmpty ]
    thenDo: [ :word | stream nextPut: word first uppercase ] ]


Regards, 

Roelof



  


--- End Message ---


Re: [Pharo-users] can I write this without the three if then;s

2019-12-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello Richard,

Thanks for the feedback. I was using it because the challenge was 
talking about it, that yu have the use the formula
a ^2  +  b ^2  =  c ^2   and the challenge was talking about the 
distance and not the distance squared.


I think a better name schould be then x or xCoordinate and y or 
Y_Coordinate.


Roelof



Op 27-12-2019 om 22:48 schreef Richard O'Keefe:

Myself, I see only one issue in your code, and that is the pointless
use of sqrt.
scoreX: anInteger y: anInteger2
 | radiusSquared |
 radiusSquared := anInteger squared + anInteger2 squared.
 radiusSquared > 100
 ifTrue: [ ^ 0 ].
 radiusSquared > 25
 ifTrue: [ ^ 1 ].
 radiusSquared > 1
 ifTrue: [ ^ 5 ].
 ^ 10

Make that two issues.  The names anInteger and anInteger2.
How about
scoreHorizontal: horizontal vertical: vertical
   ...

The OO dogma about "if' that you refer to is about not using
"if" to make decisions based on TYPE.  Making decisions based
on NUMERIC RANGES is perfectly OK.

You could introduce a 'HalfOpenRangeDictionary" class
[K1,K2) -> V1
[K2,K3) -> V2
...
[Kn,infinity) -> Vn
But "You Ain't Gonna Need It", so don't.

On Sat, 28 Dec 2019 at 08:18, Roelof Wobben via Pharo-users
 wrote:

Hello,

Im trying to solve a challenge from exercism where  I have to calculate the 
points somehow gets on a very simple darts board.

I solved it like this :


scoreX: anInteger y: anInteger2
 | distance |
 distance := (anInteger squared + anInteger2 squared) sqrt.
 distance > 10
 ifTrue: [ ^ 0 ].
 distance > 5
 ifTrue: [ ^ 1 ].
 distance > 1
 ifTrue: [ ^ 5 ].
 ^ 10


but now I use three if then and I think it's ugly code.

Is there a way I can make it more the smalltalk way ?


Regards,

Roelof




--- End Message ---


Re: [Pharo-users] uses or instead of a searching literal

2019-12-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 27-12-2019 om 23:33 schreef Richard O'Keefe:

  aString splitOn: ' -_' asSet


Hello Richard,

Thanks again , I find this  "aString splitOn: '_- `  asSet "   much 
cleaner but on some way I does not  split for example  'Portable Network 
Graphics' into  " #(Portable, Network, Graphics) ".  When I debug  it , 
it seems there is no splitting at all.


So today time to dive into it why it does not work and how to solve it.

Roelof


--- End Message ---


Re: [Pharo-users] uses or instead of a searching literal

2019-12-28 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
yep. Im aware of this tool but on this
  case nothing pops up.
  
  Roelof
  
  
  
  
  Op 28-12-2019 om 09:22 schreef Kasper Østerbye:


  
  
  Are you
aware of the ‘finder’ tool?, in particular the ‘examples' mode
is useful.
  
  
  try:
‘aaa_bbb-ccc’. ‘_-‘. #(‘aaa’ ‘bbb’ ‘ccc’) 
  
  
  
  
  Best,
  
  
  Kasper

On 28 December 2019 at 08.12.03, Roelof
  Wobben via Pharo-users (pharo-users@lists.pharo.org)
  wrote:


  
Op 27-12-2019 om 23:33 schreef Richard O'Keefe:
  
  > aString splitOn: ' -_' asSet
  
  
  Hello Richard,
  
  
  Thanks again , I find this  "aString splitOn: '_- ` 
  asSet "   much 
  cleaner but on some way I does not  split for example 
  'Portable Network 
  Graphics' into  " #(Portable, Network, Graphics) ". 
  When I debug  it , 
  it seems there is no splitting at all.
  
  
  So today time to dive into it why it does not work and
  how to solve it.
  
  
  Roelof
  
  
  

  

  
  


  


--- End Message ---


Re: [Pharo-users] uses or instead of a searching literal

2019-12-28 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello  Sven,

Thanks. this is what im looking for.

Roelof





Op 28-12-2019 om 10:46 schreef Sven Van Caekenberghe:

I would go for

   'Portable Network Graphics' findTokens: ' -_'.


On 28 Dec 2019, at 09:35, Roelof Wobben via Pharo-users 
 wrote:


From: Roelof Wobben 
Subject: Re: [Pharo-users] uses or instead of a searching literal
Date: 28 December 2019 at 09:35:17 GMT+1
To: pharo-users@lists.pharo.org


yep. Im aware of this tool but on this case nothing pops up.

Roelof




Op 28-12-2019 om 09:22 schreef Kasper Østerbye:

Are you aware of the ‘finder’ tool?, in particular the ‘examples' mode is 
useful.

try: ‘aaa_bbb-ccc’. ‘_-‘. #(‘aaa’ ‘bbb’ ‘ccc’)


Best,

Kasper

On 28 December 2019 at 08.12.03, Roelof Wobben via Pharo-users 
(pharo-users@lists.pharo.org) wrote:


Op 27-12-2019 om 23:33 schreef Richard O'Keefe:

aString splitOn: ' -_' asSet

Hello Richard,

Thanks again , I find this  "aString splitOn: '_- `  asSet "   much
cleaner but on some way I does not  split for example  'Portable Network
Graphics' into  " #(Portable, Network, Graphics) ".  When I debug  it ,
it seems there is no splitting at all.

So today time to dive into it why it does not work and how to solve it.

Roelof










--- End Message ---


[Pharo-users] how to change data on real data but not on test data

2019-12-28 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  

  I have this code so solve a
challenge of Advent Of Code :
process: anArray
| op |
ram := (anArray splitOn: ',') collect: [ :ea | ea asInteger ].
in := ReadStream on: ram.
[ (op := in next) = 99 ] whileFalse: [ self processOpcode: op ].
^ self at: 0
  


  

  
that works fine for the given
  tests
  

  


  

  
but on the real data I have to
  change 2 numbers
  

  


  

  
so I can do :
   
process: anArray
| op |
ram := (anArray splitOn: ',') collect: [ :ea | ea asInteger ].
self  put: 2  at: 3. 
 in := ReadStream on: ram.
[ (op := in next) = 99 ] whileFalse: [ self processOpcode: op ].
^ self at: 0

  

  


  

  
but that breaks all the tests
  

  


  

  
is there a way I can make it
  work for the tests and for the real data without breaking
  anything ?
  
  so to be clear. In the test are data given which not has
  to be changed. As soon as you have to solve the real
  problem , some data needs to be changed. 
  

  

  


  Roelof

  

  


--- End Message ---


Re: [Pharo-users] how to change data on real data but not on test data

2019-12-28 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Oke 
  
  Maybe it is better to give the whole challenge 
  
  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 1,0,0,3,99). To run one,
start by looking at the first integer (called position 0).
Here, you will find an opcode - either 1,
2, or 99. The opcode indicates what
to do; for example, 99 means that the program is
finished and should immediately halt. Encountering an unknown
opcode means something went wrong.
  Opcode 1 adds together numbers read
from two positions and stores the result in a third position.
The three integers immediately after the opcode tell
you these three positions - the first two indicate the positions
from which you should read the input values, and the third
indicates the position at which the output should be
stored.
  For example, if your Intcode computer encounters 1,10,20,30,
it should read the values at positions 10 and 20,
add those values, and then overwrite the value at position 30
with their sum.
  Opcode 2 works exactly like opcode 1,
except it multiplies the two inputs instead of adding
them. Again, the three integers after the opcode indicate where
the inputs and outputs are, not their values.
  Once you're done processing an opcode, move to the next
  one by stepping forward 4 positions.
  For example, suppose you have the following program:
  1,9,10,3,2,3,11,0,99,30,40,50
  For the purposes of illustration, here is the same program
split into multiple lines:
  1,9,10,3,
2,3,11,0,
99,
30,40,50

  The first four integers, 1,9,10,3, are at
positions 0, 1, 2, and
3. Together, they represent the first opcode (1,
addition), the positions of the two inputs (9 and 10),
and the position of the output (3). To handle this
opcode, you first need to get the values at the input positions:
position 9 contains 30, and position
10 contains 40. Add these
numbers together to get 70. Then, store this value
at the output position; here, the output position (3)
is at position 3, so it overwrites
itself. Afterward, the program looks like this:
  1,9,10,70,
2,3,11,0,
99,
30,40,50

  Step forward 4 positions to reach the next
opcode, 2. This opcode works just like the
previous, but it multiplies instead of adding. The inputs are at
positions 3 and 11; these positions
contain 70 and 50 respectively.
Multiplying these produces 3500; this is stored at
position 0:
  3500,9,10,70,
2,3,11,0,
99,
30,40,50

  Stepping forward 4 more positions arrives at
opcode 99, halting the program.
  Here are the initial and final states of a few more small
programs:
  
1,0,0,0,99 becomes 2,0,0,0,99
  (1 + 1 = 2).
2,3,0,3,99 becomes 2,3,0,6,99
  (3 * 2 = 6).
2,4,4,5,99,0 becomes 2,4,4,5,99,9801
  (99 * 99 = 9801).
1,1,1,4,99,5,6,0,99 becomes 30,1,1,4,2,5,6,0,99.
  
  Once you have a working computer, the first step is to restore
the gravity assist program (your puzzle input) to the "1202
program alarm" state it had just before the last computer caught
fire. To do this, before running the program, replace
position 1 with the value 12 and
replace position 2 with the value 2.
What value is left at position 0 after
the program halts?
  
  
  so as you can see in the tests there are no data changed so my
code works fine and all the tests are green but when you want to
work with the real data  the say that you have to replace two
values. 
  
  So my question is how to make that part work without breaking
the tests. 
  
  Roelof
  
  
  
  
  
  Op 28-12-2019 om 21:46 schreef Sean P. DeNigris:


  Pharo Smalltalk Users mailing list wrote

  
so to be clear. In the test are data given which not has to be changed. As
soon as you have to solve the real problem , some data needs to be
changed. 

  
  
It's difficult to give good design advice with such a par

[Pharo-users] why is masses not found?

2019-12-31 Thread Roelof Wobben via Pharo-users
--- 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?

2019-12-31 Thread Roelof Wobben via Pharo-users
--- 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?

2019-12-31 Thread Roelof Wobben via Pharo-users
--- 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?

2019-12-31 Thread Roelof Wobben via Pharo-users
--- 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?

2020-01-01 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

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





--- End Message ---


Re: [Pharo-users] why is masses not found?

2020-01-02 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
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 1,0,0,3,99). To run one,
  start by looking at the first integer (called position 0).
  Here, you will find an opcode - either 1,
  2, or 99. The opcode indicates what to
  do; for example, 99 means that the program is
  finished and should immediately halt. Encountering an unknown
  opcode means something went wrong.
Opcode 1 adds together numbers read from
  two positions and stores the result in a third position. The three
  integers immediately after the opcode tell you these
  three positions - the first two indicate the positions
  from which you should read the input values, and the third
  indicates the position at which the output should be
  stored.
For example, if your Intcode computer encounters 1,10,20,30,
  it should read the values at positions 10 and 20,
  add those values, and then overwrite the value at position 30
  with their sum.
Opcode 2 works exactly like opcode 1,
  except it multiplies the two inputs instead of adding
  them. Again, the three integers after the opcode indicate where
  the inputs and outputs are, not their values.
Once you're done processing an opcode, move to the next one
  by stepping forward 4 positions.
For example, suppose you have the following program:
1,9,10,3,2,3,11,0,99,30,40,50
For the purposes of illustration, here is the same program split
  into multiple lines:
1,9,10,3,
2,3,11,0,
99,
30,40,50

The first four integers, 1,9,10,3, are at positions
  0, 1, 2, and 3.
  Together, they represent the first opcode (1,
  addition), the positions of the two inputs (9 and 10),
  and the position of the output (3). To handle this
  opcode, you first need to get the values at the input positions:
  position 9 contains 30, and position 10
  contains 40. Add these numbers together to
  get 70. Then, store this value at the output
  position; here, the output position (3) is at
  position 3, so it overwrites itself. Afterward, the
  program looks like this:
1,9,10,70,
2,3,11,0,
99,
30,40,50

Step forward 4 positions to reach the next opcode,
  2. This opcode works just like the previous, but it
  multiplies instead of adding. The inputs are at positions 3
  and 11; these positions contain 70 and
  50 respectively. Multiplying these produces 3500;
  this is stored at position 0:
3500,9,10,70,
2,3,11,0,
99,
30,40,50

Stepping forward 4 more positions arrives at opcode
  99, halting the program.
  


--- End Message ---


Re: [Pharo-users] why is masses not found?

2020-01-02 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
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:


  
  
Hi Roelof,


I presume its working since you only asked for code smells.   
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 
  on line 82 (https://github.com/rwobben/intComputer/blob/master/AOC%202019/IntComputer.class.st#L82)
  
  
  Well done.
  cheers -ben
  
  
  
  
  





      
        On Thu, 2 Jan 2020 at
  23:37, Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
  wrote:

        
      
        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 1,0,0,3,99).
  To run one, start by looking at the first integer
  (called position 0). Here, you will
  find an opcode - either 1,
  2, or 99. The opcode
  indicates what to do; for example, 99
  means that the program is finished and should
  immediately halt. Encountering an unknown opcode
  means something went wrong.
Opcode 1 adds together
  

[Pharo-users] why is my css not found in a seaside project

2020-01-04 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  

  Hello, 

I have this in my library class on the instance side :
 
updateRoot: anHtmlRoot
super updateRoot: anHtmlRoot.
anHtmlRoot stylesheet url: self class / #mainCss.
anHtmlRoot _javascript_ url: self class / #mainJs
  


  

  
and a file mainCss on the
  instance side filled with css
  

  


  

  
and still the css is not found
  

  


  

  anyone idea why ?
  
  if needed I can put my whole code on github. 
  
  
  Regards, 
  
  Roelof
  

  

  


--- End Message ---


Re: [Pharo-users] why is my css not found in a seaside project

2020-01-04 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Yes. it is callled

Roelof


Op 4-1-2020 om 11:48 schreef Sven Van Caekenberghe:

Try putting a breakpoint inside the #updateRoot: of your library class. Is it 
even called ?


On 4 Jan 2020, at 11:17, Roelof Wobben via Pharo-users 
 wrote:


From: Roelof Wobben 
Subject: why is my css not found in a seaside project
Date: 4 January 2020 at 11:17:13 GMT+1
To: Any question about pharo is welcome 


Hello,

I have this in my library class on the instance side :
  
updateRoot: anHtmlRoot

 super updateRoot: anHtmlRoot.
 anHtmlRoot stylesheet url: self class / #mainCss.
 anHtmlRoot javascript url: self class / #mainJs

and a file mainCss on the instance side filled with css
and still the css is not found

anyone idea why ?

if needed I can put my whole code on github.


Regards,

Roelof








--- End Message ---


Re: [Pharo-users] why is my css not found in a seaside project

2020-01-04 Thread Roelof Wobben via Pharo-users
--- Begin Message ---
Yes, I added it by using localhost:8080/config and then choose for the 
application.


In the tutorial Im following that was the way the application is 
registered and the library.


So where should I add the code you are saying to use.

Here is the code I have so far: https://github.com/RoelofWobben/paintings

Roelof




Op 4-1-2020 om 12:58 schreef Sven Van Caekenberghe:

Did you add your library to your application ?

| app |
app := WAAdmin register: YourWAComponent asApplicationAt: 'my-app'.
app addLibrary: YourLibrary;


On 4 Jan 2020, at 11:58, Roelof Wobben via Pharo-users 
 wrote:


From: Roelof Wobben 
Subject: Re: [Pharo-users] why is my css not found in a seaside project
Date: 4 January 2020 at 11:58:46 GMT+1
To: Any question about pharo is welcome 


Yes. it is callled

Roelof


Op 4-1-2020 om 11:48 schreef Sven Van Caekenberghe:

Try putting a breakpoint inside the #updateRoot: of your library class. Is it 
even called ?


On 4 Jan 2020, at 11:17, Roelof Wobben via Pharo-users 
 wrote:


From: Roelof Wobben 
Subject: why is my css not found in a seaside project
Date: 4 January 2020 at 11:17:13 GMT+1
To: Any question about pharo is welcome 


Hello,

I have this in my library class on the instance side :
  updateRoot: anHtmlRoot
 super updateRoot: anHtmlRoot.
 anHtmlRoot stylesheet url: self class / #mainCss.
 anHtmlRoot javascript url: self class / #mainJs

and a file mainCss on the instance side filled with css
and still the css is not found

anyone idea why ?

if needed I can put my whole code on github.


Regards,

Roelof












--- End Message ---


[Pharo-users] can I make this so the vm would not be not responsibe when running the tests

2020-01-04 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

For a exercism challenge I need to calculate the total grains on a 
chessboard.

So I did :

atSquare: anInteger
    self validateInput: anInteger.
    ^ anInteger = 1
        ifTrue: [ 1 ]
        ifFalse: [ 2 * (self atSquare: anInteger - 1) ]


but when I run the tests , the vm seems to be not responsive for some 4 
- 5 seconds.


Is there a way I can use this code and take care that the vm stays 
responsive.


Regards,

Roelof


--- End Message ---


Re: [Pharo-users] can I make this so the vm would not be not responsibe when running the tests

2020-01-04 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Oke, 
  
  So I can better not use recursion for this problem if I understand
  you well,  Richard. 
  
  Roelof
  
  
  
  Op 4-1-2020 om 19:02 schreef Richard Sargent:


  
  

  On Sat, Jan 4, 2020 at 9:47
AM Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
wrote:
  
  Hello,

For a exercism challenge I need to calculate the total
grains on a 
chessboard.
So I did :

atSquare: anInteger
 self validateInput: anInteger.
 ^ anInteger = 1
     ifTrue: [ 1 ]
     ifFalse: [ 2 * (self atSquare: anInteger - 1) ]


but when I run the tests , the vm seems to be not responsive
for some 4 
- 5 seconds.

Is there a way I can use this code and take care that the vm
stays 
responsive.
  
  
  
  What do you want the VM to do in addition to calculating
that sum while it is calculating that sum?
  
  
  
  
  The best way to keep the VM responsive is to take a page
from Gauss' notebook and pay attention to the numbers[1].
Let's consider the first four squares and extrapolate from
there.
  
  
  In binary, the squares hold the following grains: 2r1,
2r10, r2100, and 2r1000. When we add them up, we get 2r.
If we use Gauss' tricks, we can notice that 2r is equal
to 2r1 - 1. So, the sum of the grains on the first 4
squares is 2^5 - 1. You can easily generalize that pattern,
of course. Then your program can calculate the answer
quickly.
  
  
  
  
  [1] The story goes that Gauss' teacher was frustrated
with his student's abilities and set him a challenge to
occupy him for some time: sum the numbers from 1 through
100. Gauss immediately answered 5,050, much to his teacher's
chagrin.
  
  
  

Regards,

Roelof


  

  


  


--- End Message ---


Re: [Pharo-users] why is my css not found in a seaside project

2020-01-04 Thread Roelof Wobben via Pharo-users
--- Begin Message ---
So, if I understand the seaside book well , I have to add this to the 
painting class :



initialize
 | app |
app := WAAdmin register: YourWAComponent asApplicationAt: 'my-app'.
app addLibrary: YourLibrary;


or must I use another class and if so, which class.

Roelof



Op 4-1-2020 om 13:32 schreef Roelof Wobben:
Yes, I added it by using localhost:8080/config and then choose for the 
application.


In the tutorial Im following that was the way the application is 
registered and the library.


So where should I add the code you are saying to use.

Here is the code I have so far: https://github.com/RoelofWobben/paintings

Roelof




Op 4-1-2020 om 12:58 schreef Sven Van Caekenberghe:

Did you add your library to your application ?

| app |
app := WAAdmin register: YourWAComponent asApplicationAt: 'my-app'.
app addLibrary: YourLibrary;

On 4 Jan 2020, at 11:58, Roelof Wobben via Pharo-users 
 wrote:



From: Roelof Wobben 
Subject: Re: [Pharo-users] why is my css not found in a seaside project
Date: 4 January 2020 at 11:58:46 GMT+1
To: Any question about pharo is welcome 


Yes. it is callled

Roelof


Op 4-1-2020 om 11:48 schreef Sven Van Caekenberghe:
Try putting a breakpoint inside the #updateRoot: of your library 
class. Is it even called ?


On 4 Jan 2020, at 11:17, Roelof Wobben via Pharo-users 
 wrote:



From: Roelof Wobben 
Subject: why is my css not found in a seaside project
Date: 4 January 2020 at 11:17:13 GMT+1
To: Any question about pharo is welcome 


Hello,

I have this in my library class on the instance side :
  updateRoot: anHtmlRoot
 super updateRoot: anHtmlRoot.
 anHtmlRoot stylesheet url: self class / #mainCss.
 anHtmlRoot javascript url: self class / #mainJs

and a file mainCss on the instance side filled with css
and still the css is not found

anyone idea why ?

if needed I can put my whole code on github.


Regards,

Roelof














--- End Message ---


Re: [Pharo-users] can I make this so the vm would not be not responsibe when running the tests

2020-01-04 Thread Roelof Wobben via Pharo-users
say something that isn't clear. (2) Distill the explanation
into a single concise sentence. If you cannot do that,
chances are your artefact isn't well factored. It's a good
indicator you need to rethink how you are envisioning the
decomposition of the solution. (3) Throw away every word
which doesn't change the meaning if it is present or not. At
this point, you are moving away from a grammatical sentence
to a name of a concept, so grammar no longer matters. (4)
You should end up with a name which cannot be simplified
further, yet is no bigger than necessary.
  
  
  
  
  Enough rambling! I'm glad you're working in Pharo
(Smalltalk). I wish you every success with it and with
learning programming. Keep these thoughts in mind when you
are deciding on names, but do focus on learning the
mechanics.
  
  
  
  

   
Roelof

        
    Op 4-1-2020 om 20:33 schreef Richard Sargent:
  
  

  
On Sat, Jan 4,
  2020 at 10:37 AM Roelof Wobben via Pharo-users
  <pharo-users@lists.pharo.org>
  wrote:


  
Oke, 
  
  So I can better not use recursion for this
  problem if I understand you well,  Richard. 

  



That is oversimplifying. If the purpose of the
  *training* *exercise* is to learn how to use
  recursion, then using recursion is a necessary
  thing. If the purpose of the exercise is to solve
  a problem, understanding whether there are more
  efficient approaches to the solution is an
  essential skill.


This particular problem could have been solved
  using a recursive implementation, an iterative
  implementation, or a fundamental reframing of the
  problem to change it to an O(1) problem. Other
  problems are no so simply reframed.




One of the most important skills you will ever
  develop is to understand that a request for a
  feature may not be accurately describing the
  problem. A feature request is often a description
  of a problem from a single perspective. Learning
  to recognize whether it is one or the other will
  be crucial to your long-term success as a
  programmer.



  
 
  Roelof
  
  
  
  Op 4-1-2020 om 19:02 schreef Richard Sargent:
    
        
  

  On Sat,
Jan 4, 2020 at 9:47 AM Roelof Wobben via
Pharo-users <pharo-users@lists.pharo.org>
wrote:
  
  Hello,

For a exercism challenge I need to
calculate the total grains on a 
chessboard.
So I did :

atSquare: anInteger
 self validateInput: anInteger.
 ^ anInteger = 1
     ifTrue: [ 1 ]
     ifFalse: [ 2 * (self atSquare:
anInteger - 1) ]


but when I run the tests , the vm seems
to be not responsive for some 4 
- 5 seconds.

Is there a way I can use this code and

Re: [Pharo-users] why is my css not found in a seaside project

2020-01-04 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 4-1-2020 om 22:48 schreef Sven Van Caekenberghe:

| app |
 app := WAAdmin register: YourWAComponent asApplicationAt: 'my-app'.
 app addLibrary: YourLibrary;



Oke, so like I did in my last commit here : 
https://github.com/RoelofWobben/paintings


but still I do not understand why the css is not used.

Roelof


--- End Message ---


Re: [Pharo-users] can I make this so the vm would not be not responsibe when running the tests

2020-01-05 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Thanks.

I know that im at that stage and like I said I have the feeling that Im 
at the stage for more then a half year.


I think I know a lot of pieces but need some help to see how the pieces 
could help me to solve the more complex problems.


But maybe  I want to fast and I need to concentrate on simple websites 
with seaside first and the problems of exercism and let the problems of 
Advent of Code to a later point when I have more experience.  I know 
that the problems of  Exercism are from easy to hard and maybe that is a 
better way.


Roelof



Op 5-1-2020 om 03:34 schreef tbrunz:

Sean, I hope your comment doesn't discourage Roelof!  I might agree that
"mastery" of a given programming language could take a decade of working
with it, but it doesn't take anywhere near that long to "learn" a
programming language.

There are other factors, such as whether or not you already know at least
one language: you'll associate what you already know with the new ways of
doing the same sorts of things.  And you'll know to look for things that you
can reasonably expect a new language to provide.  But the first language you
learn will probably take the longest time, as expected.

I think learning Smalltalk/Pharo will take longer than you might expect if
the other languages you know are procedural or functional, rather than
object-oriented: You need to learn a new way of thinking when learning OOP
for the first time.  And that can be hard!  As humans, we're probably
"hard-wired" to think procedurally, which can be a bit of a handicap you
when starting OOP.

You don't need to, and shouldn't expect to be able to learn everything about
a programming language immediately, as you begin learning it.  Once you
learn the basics (enough to start writing programs that "do something"), you
need to begin writing programs --frequently-- and then begin the process of
incrementally adding to your understanding and knowledge of "the finer
details".  You learn as you go.  Reading up on the subject, including
reading others' code, helps a lot as well.  Today we have GitHub to help
there!

Don't give up, Roelof.  The struggles you go through now tell you that
you've progressed to the stage of "being aware of what you don't know",
which is good: It leads you to ask the right questions that will expand your
knowledge.  Finding the answers will sometimes be a challenge, but "mastery"
of a language pretty much always requires that you work through the kinds of
problems you've been having.  It's what gives you "insight", summed up as
"been there, done that".  Otherwise your knowledge of the language would
only be superficial (e.g., you would be able to read code examples, but you
wouldn't be able to code the examples on your own).

We've all been through these kinds of struggles you're having now.  It's
part of the process, not an indication of "you can't do it".  As Sean says,
after a year of working with Pharo, you'll be offering the same kinds of
advice to others that will follow you in getting started.  Just keep at it!



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html





--- End Message ---


Re: [Pharo-users] why is my css not found in a seaside project

2020-01-05 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Oke
  
  if I understand that article  I have to put this : 
  
  initialize
  (WAAdmin register: self asApplicationAt: 'reddit')
preferenceAt: #sessionClass put: RedditSession;
addLibrary: RedditFileLibrary 

in the class side of the library and not at the class side of the class that descrives the thing I want
to display.

Roelof


  
  
  
  Op 4-1-2020 om 23:44 schreef Sven Van Caekenberghe:


  You might want to read the following article:

  https://medium.com/concerning-pharo/reddit-st-in-10-cool-pharo-classes-1b5327ca0740

sections 7 & 8 are about the Seaside app, but it is simple enough to read completely.

It is a bit old, but as far as I know, it should still work, especially the part that you have trouble with (the CSS/WAComponent interaction). Maybe this helps a bit.

BTW, you can also add a #style method to any component returning a string with CSS.


  
On 4 Jan 2020, at 23:16, Roelof Wobben  wrote:

Op 4-1-2020 om 22:48 schreef Sven Van Caekenberghe:


  | app |
app := WAAdmin register: YourWAComponent asApplicationAt: 'my-app'.
app addLibrary: YourLibrary;




Oke, so like I did in my last commit here : https://github.com/RoelofWobben/paintings

but still I do not understand why the css is not used.

Roelof


  
  




  


--- End Message ---


Re: [Pharo-users] why is my css not found in a seaside project

2020-01-05 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 5-1-2020 om 11:36 schreef Roelof Wobben via Pharo-users:

hmm,

It looks like I had to do it like this : 
https://github.com/RoelofWobben/paintings
for registering the project but I see then that the rootcomponent is not 
changed and that still the css is not found or used.



So please help.

Roelof


--- End Message ---


Re: [Pharo-users] can I make this so the vm would not be not responsibe when running the tests

2020-01-05 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello Ricard.

You mean when I calcualate the total of a board.
That is because on when I had to calculate the number of a particular 
field there were tests where the number was lower then zero or higher 
then 64 which makes no sense.


But im open for a solution where on a particular field I could check for 
that and for the total I do not need that part.


Roelof



Op 5-1-2020 om 13:58 schreef Richard O'Keefe:

Time microsecondsToRun: [
 |n|
 n := (2 raisedToInteger: 8 * 8) - 1.
 Transcript
 nextPutAll: 'The number of grains on an 8x8 chessboard is ';
print: n; cr; endEntry].

On my laptop, this reports 194 microseconds.

Why would you use recursion, anyway?

Time microsecondsToRun: [
 |n|
 n := (1 to: 8 * 8) inject: 0 into: [:acc :each | acc+acc+1].
 Transcript
 nextPutAll: 'The number of grains on an 8x8 chessboard is ';
print: n; cr; endEntry].

On the same laptop, this reports 118 microseconds.

One of the lessons of 'functional' languages, promptly adopted by Smalltalk, is
to encapsulate control structures into reusable methods, such as #inject:into:,
more commonly known as `foldl` in functional languages.  It's then none of
my business whether such a method works by recursion, iteration, or gangs
of otherwise seasonally unemployed Christmas elves.

In my own Smalltalk library,
   (GeometricSeries new: 64 from: 1 byFactor: 2) sum
only takes 15 microseconds.

I do note that you are calling validateInput repeatedly.  Why?


On Sun, 5 Jan 2020 at 07:41, Roelof Wobben via Pharo-users
 wrote:

Oke,

So I can better not use recursion for this problem if I understand you well,  
Richard.

Roelof



Op 4-1-2020 om 19:02 schreef Richard Sargent:

On Sat, Jan 4, 2020 at 9:47 AM Roelof Wobben via Pharo-users 
 wrote:

Hello,

For a exercism challenge I need to calculate the total grains on a
chessboard.
So I did :

atSquare: anInteger
  self validateInput: anInteger.
  ^ anInteger = 1
  ifTrue: [ 1 ]
  ifFalse: [ 2 * (self atSquare: anInteger - 1) ]


but when I run the tests , the vm seems to be not responsive for some 4
- 5 seconds.

Is there a way I can use this code and take care that the vm stays
responsive.


What do you want the VM to do in addition to calculating that sum while it is 
calculating that sum?


The best way to keep the VM responsive is to take a page from Gauss' notebook 
and pay attention to the numbers[1]. Let's consider the first four squares and 
extrapolate from there.

In binary, the squares hold the following grains: 2r1, 2r10, r2100, and 2r1000. 
When we add them up, we get 2r. If we use Gauss' tricks, we can notice that 
2r is equal to 2r1 - 1. So, the sum of the grains on the first 4 
squares is 2^5 - 1. You can easily generalize that pattern, of course. Then 
your program can calculate the answer quickly.


[1] The story goes that Gauss' teacher was frustrated with his student's 
abilities and set him a challenge to occupy him for some time: sum the numbers 
from 1 through 100. Gauss immediately answered 5,050, much to his teacher's 
chagrin.


Regards,

Roelof





--- End Message ---


Re: [Pharo-users] can I make this so the vm would not be not responsibe when running the tests

2020-01-05 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

There you are right but the hint we get was thinking about recursion

but your lessons showed me other ways to do it which I think are more 
the way smalltalk works,

Thanks for that.

Roelof




Op 5-1-2020 om 14:24 schreef Richard O'Keefe:

I did not ask why you were validating input.
I asked about why you *repeatedly* validated input.

Think of it this way:
publicMethod: arg1 also: arg2
   ... check arg1 ...
   ... check arg2 ...
  ^self privateMethod: arg1 also: arg2

 privateMethod: arg1 also: arg2
   ... trust that arg1 and arg2 are valide ...
   ... recursive calls use #privateMethod:andAlso: ...
   ... not #publicMethod:andAlso: and must ensure ...
   ... that arguments are valid by construction ...

In my solution to the "Grains" exercism, I have
   atSquare: n   -- checks its argument
   total ^(1 bitShift: 64) - 1
You are required to implement these two methods, true.
You are NOT required to implement #total by calling #atSquare:.
Not even once.  Nor is #atSquare: required to be recursive.

On Mon, 6 Jan 2020 at 02:05, Roelof Wobben  wrote:

Hello Ricard.

You mean when I calcualate the total of a board.
That is because on when I had to calculate the number of a particular
field there were tests where the number was lower then zero or higher
then 64 which makes no sense.

But im open for a solution where on a particular field I could check for
that and for the total I do not need that part.

Roelof



Op 5-1-2020 om 13:58 schreef Richard O'Keefe:

Time microsecondsToRun: [
  |n|
  n := (2 raisedToInteger: 8 * 8) - 1.
  Transcript
  nextPutAll: 'The number of grains on an 8x8 chessboard is ';
print: n; cr; endEntry].

On my laptop, this reports 194 microseconds.

Why would you use recursion, anyway?

Time microsecondsToRun: [
  |n|
  n := (1 to: 8 * 8) inject: 0 into: [:acc :each | acc+acc+1].
  Transcript
  nextPutAll: 'The number of grains on an 8x8 chessboard is ';
print: n; cr; endEntry].

On the same laptop, this reports 118 microseconds.

One of the lessons of 'functional' languages, promptly adopted by Smalltalk, is
to encapsulate control structures into reusable methods, such as #inject:into:,
more commonly known as `foldl` in functional languages.  It's then none of
my business whether such a method works by recursion, iteration, or gangs
of otherwise seasonally unemployed Christmas elves.

In my own Smalltalk library,
(GeometricSeries new: 64 from: 1 byFactor: 2) sum
only takes 15 microseconds.

I do note that you are calling validateInput repeatedly.  Why?


On Sun, 5 Jan 2020 at 07:41, Roelof Wobben via Pharo-users
 wrote:

Oke,

So I can better not use recursion for this problem if I understand you well,  
Richard.

Roelof



Op 4-1-2020 om 19:02 schreef Richard Sargent:

On Sat, Jan 4, 2020 at 9:47 AM Roelof Wobben via Pharo-users 
 wrote:

Hello,

For a exercism challenge I need to calculate the total grains on a
chessboard.
So I did :

atSquare: anInteger
   self validateInput: anInteger.
   ^ anInteger = 1
   ifTrue: [ 1 ]
   ifFalse: [ 2 * (self atSquare: anInteger - 1) ]


but when I run the tests , the vm seems to be not responsive for some 4
- 5 seconds.

Is there a way I can use this code and take care that the vm stays
responsive.

What do you want the VM to do in addition to calculating that sum while it is 
calculating that sum?


The best way to keep the VM responsive is to take a page from Gauss' notebook 
and pay attention to the numbers[1]. Let's consider the first four squares and 
extrapolate from there.

In binary, the squares hold the following grains: 2r1, 2r10, r2100, and 2r1000. 
When we add them up, we get 2r. If we use Gauss' tricks, we can notice that 
2r is equal to 2r1 - 1. So, the sum of the grains on the first 4 
squares is 2^5 - 1. You can easily generalize that pattern, of course. Then 
your program can calculate the answer quickly.


[1] The story goes that Gauss' teacher was frustrated with his student's 
abilities and set him a challenge to occupy him for some time: sum the numbers 
from 1 through 100. Gauss immediately answered 5,050, much to his teacher's 
chagrin.


Regards,

Roelof





--- End Message ---


Re: [Pharo-users] why is my css not found in a seaside project

2020-01-05 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

I think I found the answer myself

when I put this in the RootComponent

updateRoot: anHtmlRoot
    super updateRoot: anHtmlRoot.
    anHtmlRoot stylesheet url: (PaintingLibrary  urlOf: #mainCss)

and this on the class side of the RootComponent


initialize
    | app |
    app := WAAdmin
        register: #stRootComponent
        asApplicationAt: 'Paintings2'.
    app addLibrary: PaintingLibrary


then I see some css. The page looks not what I expect but that can be 
changed.


So does the code I have now on my github page well or do I use the 
components still the wrong way ?


Roelof



Op 5-1-2020 om 12:48 schreef Roelof Wobben:

Op 5-1-2020 om 11:36 schreef Roelof Wobben via Pharo-users:

hmm,

It looks like I had to do it like this : 
https://github.com/RoelofWobben/paintings
for registering the project but I see then that the rootcomponent is 
not changed and that still the css is not found or used.



So please help.

Roelof




--- End Message ---


[Pharo-users] is this better regarding naming thigs

2020-01-05 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello

In a earlier question I get a remark to think better about naming things.
Now I did  a challene where I have to find anagrams of a given word in a 
collection,


So I did this :

findAnagramsCandidates: aCollection subject: aWord
    | charBag |
    charBag := aWord asLowercase asBag.
    ^ aCollection
        reject:
            [ :word | (word sameAs: aWord) or: [ word asLowercase asBag 
~= charBag ] ]



is my naming here better or can i improved and if so how ?

Regards,

Roelof


--- End Message ---


[Pharo-users] [seaside] how can I now make the best work to display all the paiintings which are in the paintings collection

2020-01-05 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

Im a little bit further on my first project but now I fail to see how I 
can use the ListComponent to display all the paintings that are in the 
paintings collection on the Paintings class.


Anyone who can give me hints on this ?

Roelof




--- End Message ---


Re: [Pharo-users] is this better regarding naming thigs

2020-01-05 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

Nice to see that someone who ask another question on my question but do 
i get a answer on my question too.

So if the naming is better now.

Roelof



Op 6-1-2020 om 02:18 schreef xap:

"but all objects respond to value..."; thx, Santiago -- that makes more
sense, that or: cares only about its receiver/argument evaluable as a
Boolean, no matter they started as blocks, expressions, or something else
(makes me wonder if a bare-value is a degenerate case of a block ... but
don't mind me, I'm just talking aloud). separately, point taken re
expressions being evaluated, and blocks possibly not.



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html





--- End Message ---


Re: [Pharo-users] is this better regarding naming thigs

2020-01-06 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 6-1-2020 om 09:34 schreef xap:

hi Roelof, i didn't mean to hijack your thread, sorry -- my question was
directed at you, then kinda took on a life of its own.

That said, Sven had/has responded to your op (original post), no?

One additional change I would make: rename "findAnagramsCandidates" -->
"findAnagrams" : it's shorter, and possibly more correct since what's
returned are true anagrams rather than candidates-that-may-be-anagrams ?



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html




NP,

And if my question was answered , I miss it.

That name was given by the challenge so if I would change it, Im afraid 
that I also have to change all tests included by the challenge.


But thanks for answering.

Roelof


--- End Message ---


Re: [Pharo-users] is this better regarding naming thigs

2020-01-06 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Thanks.

I have missed that one.
Thanks for pointing it to me.

Roelof


Op 6-1-2020 om 13:13 schreef xap:

Here's the permalink to Sven's response (in case it still isn't visible to
you):
http://forum.world.st/is-this-better-regarding-naming-thigs-tp5109389p5109392.html



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html





--- End Message ---


[Pharo-users] mentor wanted

2020-04-23 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

I like Pharo a lot but I hit a wall very often.
With complex problems I do not see how to solve things in small steps.

Is there somewhere who is willing to mentor me in how I can overcome 
that problem.


Roelof


--- End Message ---


Re: [Pharo-users] mentor wanted

2020-04-23 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 23-4-2020 om 20:52 schreef Richard
  Sargent:


  
  

  On Thu, Apr 23, 2020 at 3:32
AM Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
wrote:
  
  Hello,

I like Pharo a lot but I hit a wall very often.
With complex problems I do not see how to solve things in
small steps.
  
  
  
  I would be happy to help with the Smalltalk and problem
analysis aspects. Unfortunately, I don't use Pharo much, so
I cannot help with it.
   
  
  

Is there somewhere who is willing to mentor me in how I can
overcome 
that problem.

Roelof


  

  


Pity, 


but if you could help me to learn how to divide a complex problem in
smaller steps , then I think I can make it work in Pharo.   My
problem is more that then how to do it in Pharo. 

Do you then use gemtalk a lot.
Pity that I cannot make exercism challenges on that.
And AdventOfCode do seem to difficult for a beginner. 

Roelof

  


--- End Message ---


Re: [Pharo-users] mentor wanted

2020-04-23 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 23-4-2020 om 21:09 schreef Richard
  Sargent:


  
  

  On Thu, Apr 23, 2020 at
12:00 PM Roelof Wobben <r.wob...@home.nl> wrote:
  
  

  Op 23-4-2020 om 20:52 schreef Richard Sargent:
  
  

  
On Thu, Apr 23,
  2020 at 3:32 AM Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
  wrote:

Hello,
  
  I like Pharo a lot but I hit a wall very often.
  With complex problems I do not see how to solve
  things in small steps.



I would be happy to help with the Smalltalk and
  problem analysis aspects. Unfortunately, I don't
  use Pharo much, so I cannot help with it.
 

 
  Is there somewhere who is willing to mentor me in
  how I can overcome 
  that problem.
  
  Roelof
  
  

  

  
  
  Pity, 
  
  
  but if you could help me to learn how to divide a complex
  problem in smaller steps , then I think I can make it work
  in Pharo.   My problem is more that then how to do it in
  Pharo. 
  
  Do you then use gemtalk a lot.
  Pity that I cannot make exercism challenges on that.
  And AdventOfCode do seem to difficult for a beginner. 

  
  
  
  Yes, I can help with those areas. I've been programming
professionally and virtually exclusively in Smalltalk since
1991. 
  
  
  
  I've been using GemStone/S since 2009 and now work for
the manufacturer. I've been working with VA Smalltalk and
its predecessors since 1994 and with VisualWorks since 2009.
  
  
  I hear you about using GemStone/S. For most of its life,
the assumption was that you would use a client Smalltalk
like VA Smalltalk or VisualWorks to do your development
work. Although, recently we've been working on Jadeite (https://github.com/GemTalk/Jadeite)
to provide a development environment independent of GBS
(which is what we used to connect VA Smalltalk and
VisualWorks to GemStone/S).
  
  
  
 
  Roelof
  

  

  



Oke, I have heard of it  but because I could not find a course or
book about gemstone and found a mooc about Pharo I choose that one.


But is there then much difference between Pharo and Gemstone or can
I make a solution to a problem and use the same code for both. 

For me programming is a hobby. In the Netherlands most companies use
c#  and with 53 and no XP I do not think its wise to  think I find a
job as developer. 

Roelof

  


--- End Message ---


Re: [Pharo-users] mentor wanted

2020-04-23 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 23-4-2020 om 23:00 schreef Richard
  Sargent:


  
  

  On Thu, Apr 23, 2020 at
12:14 PM Roelof Wobben <r.wob...@home.nl> wrote:
  
  

  Op 23-4-2020 om 21:09 schreef Richard Sargent:
  
  

  
On Thu, Apr 23,
  2020 at 12:00 PM Roelof Wobben <r.wob...@home.nl>
  wrote:


  
Op 23-4-2020 om 20:52 schreef Richard
  Sargent:


  

  On Thu,
Apr 23, 2020 at 3:32 AM Roelof Wobben
        via Pharo-users <pharo-users@lists.pharo.org>
wrote:
  
  Hello,

I like Pharo a lot but I hit a wall very
often.
With complex problems I do not see how
to solve things in small steps.
  
  
  
  I would be happy to help with the
Smalltalk and problem analysis aspects.
Unfortunately, I don't use Pharo much,
so I cannot help with it.
   
  
   
Is there somewhere who is willing to
mentor me in how I can overcome 
that problem.

Roelof


  

  


Pity, 


but if you could help me to learn how to divide
a complex problem in smaller steps , then I
think I can make it work in Pharo.   My problem
is more that then how to do it in Pharo. 

Do you then use gemtalk a lot.
Pity that I cannot make exercism challenges on
that.
And AdventOfCode do seem to difficult for a
beginner. 
  



Yes, I can help with those areas. I've been
  programming professionally and virtually
  exclusively in Smalltalk since 1991. 



I've been using GemStone/S since 2009 and now
  work for the manufacturer. I've been working with
  VA Smalltalk and its predecessors since 1994 and
  with VisualWorks since 2009.


I hear you about using GemStone/S. For most of
  its life, the assumption was that you would use a
  client Smalltalk like VA Smalltalk or VisualWorks
  to do your development work. Although, recently
  we've been working on Jadeite (https://github.com/GemTalk/Jadeite)
  to provide a development environment independent
  of GBS (which is what we used to connect VA
  Smalltalk and VisualWorks to GemStone/S).



   
Roelof

  

  

  
  
  
  Oke, I have heard of it  but because I could not find a
  course or book about gemstone and found a mooc about Pharo
  I choose that one. 

  
  
  
  Pharo is an excellent choice and the MOOC should help.
  
  
  
 
  But is there then much difference between Pharo and
  Gemstone or can I make a solution to a problem and use the
  same code for both. 

  
  
  
  There a

Re: [Pharo-users] mentor wanted

2020-04-23 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 23-4-2020 om 23:53 schreef Richard
  Sargent:


  
  

  On Thu, Apr 23, 2020 at 2:42
PM Roelof Wobben <r.wob...@home.nl> wrote:
  
  

  Op 23-4-2020 om 23:00 schreef Richard Sargent:
  
  

  
On Thu, Apr 23,
  2020 at 12:14 PM Roelof Wobben <r.wob...@home.nl>
  wrote:


  
Op 23-4-2020 om 21:09 schreef Richard
  Sargent:


  

  On Thu,
Apr 23, 2020 at 12:00 PM Roelof Wobben
<r.wob...@home.nl>
wrote:
  
  

  Op 23-4-2020 om 20:52 schreef
Richard Sargent:
  
  

  
On Thu, Apr
  23, 2020 at 3:32 AM Roelof
          Wobben via Pharo-users <pharo-users@lists.pharo.org>
  wrote:

Hello,
  
  I like Pharo a lot but I hit a
  wall very often.
  With complex problems I do not
  see how to solve things in
  small steps.



I would be happy to help
  with the Smalltalk and problem
  analysis aspects.
  Unfortunately, I don't use
  Pharo much, so I cannot help
  with it.
 


  
  Is there somewhere who is
  willing to mentor me in how I
  can overcome 
  that problem.
  
  Roelof
  
  

  

  
  
  Pity, 
  
  
  but if you could help me to learn how
  to divide a complex problem in smaller
  steps , then I think I can make it
  work in Pharo.   My problem is more
  that then how to do it in Pharo. 
  
  Do you then use gemtalk a lot.
  Pity that I cannot make exercism
  challenges on that.
  And AdventOfCode do seem to difficult
  for a beginner. 

  
  
  
  Yes, I can help with those areas.
I've been programming professionally and
virtually exclusively in Smalltalk since
1991. 
  
  
  
  I've been using GemStone/S since 2009
and now work for the manufacturer. I've
been working with VA Smalltalk and its
predecessors since 1994 and with
  

Re: [Pharo-users] mentor wanted

2020-04-24 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 24-4-2020 om 09:49 schreef Hilaire:

Find it.

It is a chapter of the book Squeak, Open Personal Computing and 
Multimedia 


http://sdmeta.gforge.inria.fr/FreeBooks/GuzdialBookDrafts/DesignObjects-ch4.pdf 



Le 24/04/2020 à 09:39, Hilaire a écrit :
I remember about a Smalltalk book presenting the CRC concept 
precisely used to cut complex problem in small chunks.




Hilaire and Cedric thanks, I will also study those.



--- End Message ---


Re: [Pharo-users] mentor wanted

2020-04-25 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 25-4-2020 om 08:30 schreef Richard
  Sargent:


  
  

  
On Fri, Apr 24, 2020,
  22:25 Richard O'Keefe 
  wrote:

Roelof,
  I don't think CRC cards or the GRASP patterns or anything
  like that
  addresses your immediate needs.  Based on other questions
  of yours it
  seems to me that your problem is not *organising* the
  responsibilities in an
  OO program, but decomposing a problem into
  responsibilities in the first
  place.  I think this is perhaps the most important part of
  programming, and
  the hardest to learn, not least because very few of us are
  good at teaching
  it.  We're not very good at teaching it in mathematics
  either.  I do not think
  your issues are anything to do with Pharo, Smalltalk, OOP,
  or programming
  as such.
  
  One symptom of the general problem that I've noticed is
  that I see code as
  a very fluid sort of thing where pieces can be moved
  around and recombined,
  while many people think of code as something solid and
  rather brittle.
  
  I was thinking of writing up a short description of what I
  was thinking for a
  RosettaCode example anyway.  Would that help?

  



Thank you, Richard. I appreciate your offering
  this. I am not a teacher, so your help is truly appreciated!



  


Moment,  I have to look if  I understand you right.
I think you have some strong points but the last one I did not
understand well. 
 
Do I have to write  for example for a exercism challenge  a short
description of that problem like people do with rosetta code
challenges and example code ? 

Roelof

  


--- End Message ---


[Pharo-users] mentor question 1

2020-04-25 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Hello, 

Im doing the OOP book written by Ducassse and im now stuck at the
network-simulator.
Code so far can be found here :
https://github.com/RoelofWobben/Network-simulator

Im stuck at 2 places 

1) What for datatype is loopback ?  Is it a string or something
else. 
    The book is not telling that.

2)  I have to make this method/function 

linksTowards: anAddress do: aBlock
    "Simple flood algorithm: route via all outgoing links.
   However, just loopback if the receiver node is the routing
destination."
   (address destination == loopback)
   ifTrue: [self send:  via: loopback ]; 
   ifFalse: [self send: via: anAddress]

but I do not have a clue what the aBlock is  and if im on the right
path.
I know the solutions can be found online but then I do not learn
anything. 

This is what is stated in the book : 

This method has to rely on some routing
  algorithm to identify which links will transmit the packet
  closer to its destination. Since some routing algorithms select
  more than one link, we will implement routing as an iteration method,
  which evaluates the given block for each selected link.
KANetworkNode >> send: aPacket
  "Send aPacket, leaving the responsibility of routing to the node."
  self
  linksTowards: aPacket destinationAddress
  do: [ :link | self send: aPacket via: link ]
One of the simplest routing
  algorithm is flooding: just send the packet via every outgoing link.
  Obviously, this is a waste of bandwidth, but it works without any
  knowledge of the network topology
  beyond the list of outgoing links.
  However, there is one case where we know how to route the packet:
  if the destination address
  matches the one of the current node, we can select the loopback
  link. The logic of linksTowards:do:
is then: compare the packet’s
  destination address with the one of the node, if it is the same,
  we
  execute the block using the loopback link, else we simply iterate
  on the outgoing links of the receiver.
KANetworkNode >> linksTowards:
  anAddress do: aBlock
  "Simple flood algorithm: route via all outgoing links.
  However, just loopback if the receiver node is the routing
  destination."
  ... Your code ... 


I hope someone can help me on the way or let me see which steps I
had to take to solve this on my own. 

Roelof


  


--- End Message ---


Re: [Pharo-users] mentor question 1

2020-04-25 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 25-4-2020 om 20:04 schreef tbrunz:

1. 'loopback' is a node, just like 'source' and 'destination'.  A network is
a mesh of 'nodes' joined by 'links'.  Your Pharo program represents one of
those nodes: It is the 'loopback' node.


oke, so I can do : loopback := KNetworkNode new.


2. The block in the #linksTowards:do: method is the action to take on a
packet, depending on whether its destination is "you" (loopback), or
something else.

The flood algorithm is the simplest algorithm: "If the destination is not
me, send the packet to everyone else (except the one who sent it to me)."



and that part I still do not see. I "fail"  to see what the block 
exactly is.



However, there is the possibility of loops in the network, so a slightly
better algorithm is to check "have I seen this packet before?" and if the
answer is "yes", then drop it; otherwise send it via my links.  This will
prevent endless packet sending loops in your network.

-t




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html




--- End Message ---


Re: [Pharo-users] mentor question 1

2020-04-25 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 25-4-2020 om 20:17 schreef Roelof Wobben:

Op 25-4-2020 om 20:04 schreef tbrunz:
1. 'loopback' is a node, just like 'source' and 'destination'.  A 
network is
a mesh of 'nodes' joined by 'links'.  Your Pharo program represents 
one of

those nodes: It is the 'loopback' node.


oke, so I can do : loopback := KNetworkNode new.


2. The block in the #linksTowards:do: method is the action to take on a
packet, depending on whether its destination is "you" (loopback), or
something else.

The flood algorithm is the simplest algorithm: "If the destination is 
not
me, send the packet to everyone else (except the one who sent it to 
me)."



and that part I still do not see. I "fail"  to see what the block 
exactly is.



However, there is the possibility of loops in the network, so a slightly
better algorithm is to check "have I seen this packet before?" and if 
the

answer is "yes", then drop it; otherwise send it via my links. This will
prevent endless packet sending loops in your network.

-t




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html







Oke,

Did some thinking and see how things are working if the loopback is not 
used :


linksTowards: anAddress do: aBlock
    "Simple flood algorithm: route via all outgoing links.
However, just loopback if the receiver node is the routing destination."

    address = anAddress
        ifTrue: [  ]
        ifFalse: [ outgoingLinks do: aBlock ]

but still I "fail"  to see what need to be done when the loopback is 
used with the block.


Roelof


--- End Message ---


Re: [Pharo-users] mentor wanted

2020-04-26 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 26-4-2020 om 06:30 schreef Richard O'Keefe:

Roelof, *I* was offering to write something.

On Sat, 25 Apr 2020 at 19:47, Roelof Wobben via Pharo-users
 wrote:

Op 25-4-2020 om 08:30 schreef Richard Sargent:

On Fri, Apr 24, 2020, 22:25 Richard O'Keefe  wrote:

Roelof, I don't think CRC cards or the GRASP patterns or anything like that
addresses your immediate needs.  Based on other questions of yours it
seems to me that your problem is not *organising* the responsibilities in an
OO program, but decomposing a problem into responsibilities in the first
place.  I think this is perhaps the most important part of programming, and
the hardest to learn, not least because very few of us are good at teaching
it.  We're not very good at teaching it in mathematics either.  I do not think
your issues are anything to do with Pharo, Smalltalk, OOP, or programming
as such.

One symptom of the general problem that I've noticed is that I see code as
a very fluid sort of thing where pieces can be moved around and recombined,
while many people think of code as something solid and rather brittle.

I was thinking of writing up a short description of what I was thinking for a
RosettaCode example anyway.  Would that help?


Thank you, Richard. I appreciate your offering this. I am not a teacher, so 
your help is truly appreciated!



Moment,  I have to look if  I understand you right.
I think you have some strong points but the last one I did not understand well.

Do I have to write  for example for a exercism challenge  a short description 
of that problem like people do with rosetta code challenges and example code ?

Roelof




oke, I also accept this offer also.
The more angles I learn to solve this , the more I can use that in later 
challenges.



and if I understand everything right , the solution is very simple

linksTowards: anAddress do: aBlock
    "Simple flood algorithm: route via all outgoing links.
However, just loopback if the receiver node is the routing destination."

    address = anAddress
        ifTrue: [ aBlock evaluate: loopback ]
        ifFalse: [ outgoingLinks do: aBlock ]


and the flow is this :

send: aPacket
    "Send aPacket, leaving the responsibility of routing to the node."

    self
        linksTowards: aPacket destinationAddress
        do: [ :link | self send: aPacket via: link ]

so for linkTwowards the anAddress is  the `aPacket destinationAdress `  
and the aBlock  is ` [:link | self send: aPacket via: link `


so if the address is the loopback one  it would be ` self send: aPacket 
via: loopback `


and send is this :

send: aPacket via: aLink
    aLink emit: aPacket

so that would be  ` loopback emit : aPackage  `

and that would lead to :

emit: aPacket
    "Packets are not transmitted right away, but stored.
Transmission is explicitly triggered later, by sending #transmit:."

    packetsToTransmit add: aPacket

where packetsToTransmit is a OrderedCollection
where the packet is added

Waiting till the transmit method is called where the sending of a 
package is simulated.


Roelof



--- End Message ---


[Pharo-users] mentor question 2.

2020-04-26 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

I have to make some code that convert a binary to a decimal and im not 
allowed to use the convert methods that Pharo has.


So I have written this :


decimalFromBinary: aString
    | result isValid |
    isValid = self isValidBinary: aString.
    isValid
        ifTrue: [ result := 0.
            aString reverse
                withIndexDo:
                    [ :digit :index | result := result + (digit 
digitValue * (2 raisedTo: index - 1)) ].

            ^ result ]
        ifFalse: [ ^ nil ]

isValidBinary: aString
    ^ aString allSatisfy: [ :c | c = 0 or: [ c = 1 ] ]


but on the first method I see a message that the temp variables are read 
before written.
and the second one I see a message that I use a or instead of searching 
literals.


Where did  I think wrong here ?

Roelof


--- End Message ---


Re: [Pharo-users] mentor question 2.

2020-04-26 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 26-4-2020 om 20:17 schreef Sven Van Caekenberghe:



On 26 Apr 2020, at 20:10, Gabriel Cotelli  wrote:

In the first method you aren't doing an assignment, are sending the message = 
to the temp isValid, if you change the method to:
decimalFromBinary: aString
  | result isValid |
  isValid := self isValidBinary: aString.
  isValid
  ifTrue: [ result := 0.
  aString reverse
  withIndexDo:
  [ :digit :index | result := result + (digit
digitValue * (2 raisedTo: index - 1)) ].
  ^ result ]
  ifFalse: [ ^ nil ]
it should work.

There is a #reverseWithIndexDo: method

Also, #digitValue might be considered a builtin method that you are not allowed 
to use. Since you already did the #isValidBinary: test, you could say

   (digit charCode - $0 charCode)


In the second one you're comparing characters with numbers, this will always 
return false because the number 0 is not the same as the character 0.
Use
isValidBinary: aString
  ^ aString allSatisfy: [ :c | c = $0 or: [ c = $1 ] ]
or something like

isValidBinary: aString
  ^ aString allSatisfy: [ :c | '01' includes: c ]

On Sun, Apr 26, 2020 at 2:52 PM Roelof Wobben via Pharo-users 
 wrote:
Hello,

I have to make some code that convert a binary to a decimal and im not
allowed to use the convert methods that Pharo has.

So I have written this :


decimalFromBinary: aString
  | result isValid |
  isValid = self isValidBinary: aString.
  isValid
  ifTrue: [ result := 0.
  aString reverse
  withIndexDo:
  [ :digit :index | result := result + (digit
digitValue * (2 raisedTo: index - 1)) ].
  ^ result ]
  ifFalse: [ ^ nil ]

isValidBinary: aString
  ^ aString allSatisfy: [ :c | c = 0 or: [ c = 1 ] ]


but on the first method I see a message that the temp variables are read
before written.
and the second one I see a message that I use a or instead of searching
literals.

Where did  I think wrong here ?

Roelof







Thanks,  this problem is solved.

Roelof

--- End Message ---


[Pharo-users] how can I test this

2020-04-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

I have to test the server which should return the string but then in 
uppercase.


So far I have this : 
https://github.com/RoelofWobben/Network-simulator/blob/master/src/NetworkSimulator-Tests/KANetworkTest.class.st#L79


but I fail to see how I can test that the package sending back is a 
uppercase string.


Regards,

Roelof




--- End Message ---


Re: [Pharo-users] mentor question 2.

2020-04-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 27-4-2020 om 13:16 schreef
  PBKResearch:


  
  
  
  
Roelof
 
You maybe have enough mentors already, but
  there are some important features of this problem which can be
  of use in future. Your code solves the problem, but it could
  be improved in two ways, which make it simpler and clearer.
 

  What is the
purpose of the local variable ‘isValid’? It provides
somewhere to remember the result of your validity test. But
you have no need to remember it; all you want to do is
evaluate it, use it to determine the course of the program
and then forget it. If you write:

(self
  isValidBinary: aString)
 ifTrue:
  [….]
  
  ifFalse: [^nil]
you will achieve
  the same result without introducing the local variable. It
  probably reads more clearly, revealing the intention of the
  code. (You can simplify further by replacing the ifFalse:
  clause with an unconditional ^nil; if the code reaches this
  point, we know it’s false.) The general principle is: only
  introduce a named local variable if you need to remember
  something for later re-use.
 

  It is not
necessary to reverse the string in order to evaluate it; it
is in fact easier to evaluate it from left to right. You
have used the withIndexDo: method to supply the index and
know the appropriate power of two to use. Instead you could
multiply by two as you process each digit, which will
automatically use the right power of two without ever
needing to know what it is. You could write:

result := 0.
aString do:
   [:digit| result := result * 2 + digit digitValue].
^result.
This is a
  special case of a very useful general procedure for evaluating
  a polynomial. The digits of a binary number are the
  coefficients of a polynomial in x which is evaluated at x=2;
  similarly, a decimal number is a polynomial evaluated at x=10.
 
I hope this is helpful.
 
Peter Kenny
 

  From:
  Pharo-users  On
Behalf Of Roelof Wobben via Pharo-users
  Sent: 26 April 2020 19:52
  To: pharo-users@lists.pharo.org
  Cc: Roelof Wobben 
  Subject: Re: [Pharo-users] mentor question 2.
   
  Op 26-4-2020 om 20:17
  schreef Sven Van Caekenberghe:
  > 
  >> On 26 Apr 2020, at 20:10,
Gabriel Cotelli <g.cote...@gmail.com> wrote:
  >> 
  >> In the first method you
aren't doing an assignment, are sending the message = to the
temp isValid, if you change the method to:
  >> decimalFromBinary: aString
  >>   | result isValid |
  >>   isValid := self
isValidBinary: aString.
  >>   isValid
  >>   ifTrue: [ result :=
0.
  >>   aString reverse
  >>  
withIndexDo:
  >>   [
:digit :index | result := result + (digit 
  >> digitValue * (2 raisedTo:
index - 1)) ].
  >>   ^ result ]
  >>   ifFalse: [ ^ nil ]
  >> it should work.
  > There is a #reverseWithIndexDo:
method
  > 
  > Also, #digitValue might be
considered a builtin method that you are 
  > not allowed to use. Since you
already did the #isValidBinary: test, 
  > you could say
  > 
  >    (digit charCode - $0 charCode)
  > 
  >> In the second one you're
comparing characters with numbers, this will always return
false because the number 0 is not the same as the character
0.
  >> Use
  >> isValidBinary: aString
  >>   ^ aString allSatisfy: [
:c | c = $0 or: [ c = $1 ] ] or 
  >> something like
  >> 
  >> isValidBinary: aString
  >>   ^ aString allSatisfy: [
:c | '01' includes: c ]
  >> 
  >> On Sun, Apr 26, 2020 at 2:52
PM Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
wrote:
  >> Hello,
  >> 
 

Re: [Pharo-users] mentor question 2.

2020-04-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Not any problems. 
  I take the points out of it and forget the things I do not
  understand.
  
  Roelof
  
  
  Op 27-4-2020 om 13:50 schreef PBKResearch:


  
  
  
  
Roelof
 
Sorry if I introduced unnecessary
  technicalities. Your solution to the problem was in fact using
  a polynomial explicitly; that’s what all the powers of 2 were
  doing. But as long as you can follow how my version works,
  that’s all that matters.
 
Peter
 

  From:
  Pharo-users  On
Behalf Of Roelof Wobben via Pharo-users
  Sent: 27 April 2020 12:23
  To: pharo-users@lists.pharo.org
  Cc: Roelof Wobben 
  Subject: Re: [Pharo-users] mentor question 2.

 
Op 27-4-2020 om 13:16 schreef PBKResearch:
Roelof
 
You maybe have enough mentors already, but
  there are some important features of this problem which can be
  of use in future. Your code solves the problem, but it could
  be improved in two ways, which make it simpler and clearer.
 

  What is the
purpose of the local variable ‘isValid’? It provides
somewhere to remember the result of your validity test. But
you have no need to remember it; all you want to do is
evaluate it, use it to determine the course of the program
and then forget it. If you write:

(self
  isValidBinary: aString)
 ifTrue:
  [….]
  
  ifFalse: [^nil]
you will achieve
  the same result without introducing the local variable. It
  probably reads more clearly, revealing the intention of the
  code. (You can simplify further by replacing the ifFalse:
  clause with an unconditional ^nil; if the code reaches this
  point, we know it’s false.) The general principle is: only
  introduce a named local variable if you need to remember
  something for later re-use.
 

  It is not
necessary to reverse the string in order to evaluate it; it
is in fact easier to evaluate it from left to right. You
have used the withIndexDo: method to supply the index and
know the appropriate power of two to use. Instead you could
multiply by two as you process each digit, which will
automatically use the right power of two without ever
needing to know what it is. You could write:

result := 0.
aString do:
  
[:digit| result := result * 2 + digit digitValue].
^result.
This is a
  special case of a very useful general procedure for evaluating
  a polynomial. The digits of a binary number are the
  coefficients of a polynomial in x which is evaluated at x=2;
  similarly, a decimal number is a polynomial evaluated at x=10.
 
I hope this is helpful.
 
Peter Kenny
 
From: Pharo-users

On Behalf Of Roelof Wobben via Pharo-users
Sent: 26 April 2020 19:52
To: pharo-users@lists.pharo.org
Cc: Roelof Wobben 
Subject: Re: [Pharo-users] mentor question 2.
 
Op 26-4-2020 om 20:17
schreef Sven Van Caekenberghe:
> 
>> On 26 Apr 2020, at 20:10,
  Gabriel Cotelli <g.cote...@gmail.com> wrote:
>> 
>> In the first method you aren't
  doing an assignment, are sending the message = to the temp
  isValid, if you change the method to:
>> decimalFromBinary: aString
>>   | result isValid |
>>   isValid := self
  isValidBinary: aString.
>>   isValid
>>   ifTrue: [ result :=
  0.
>>   aString reverse
>>   withIndexDo:
>>   [ :digit
  :index | result := result + (digit 
>> digitValue * (2 raisedTo: index
  - 1)) ].
>>   ^ result ]
>>   ifFalse: [ ^ nil ]
>> it should work.
> There is a #reverseWithIndexDo:
  method
> 
> Also, #digitValue might be
  considered a builtin method that you are 
> not allowed to use. Since you
  already did the #isValidBinary: test, 
> you could say
> 
>    (digit charCode - $0 charCode)
> 
>> In the second one you're
  compari

[Pharo-users] can I divide a string into part of exactly n length

2020-04-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

I wonder if it is possible in Pharo to divide a string in lets say part 
of 3.

so this :  'abcdefgh'

would be  'abc def gh`

Regards,

Roelof


--- End Message ---


Re: [Pharo-users] how can I test this

2020-04-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 27-4-2020 om 18:28 schreef Richard
  Sargent:


  
  

  On Mon, Apr 27, 2020 at 1:56
AM Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
wrote:
  
  Hello,

I have to test the server which should return the string but
then in 
uppercase.

So far I have this : 
https://github.com/RoelofWobben/Network-simulator/blob/master/src/NetworkSimulator-Tests/KANetworkTest.class.st#L79

but I fail to see how I can test that the package sending
back is a 
uppercase string.
  
  
  
  I think you need to rephrase this question. Either the
String class hierarchy has a method named something like
#isUppercase or Character does. If only Character has it,
you would need to iterate over the received string testing
each individual character.
  
  
  Or is your question more about getting the response back
to the sending node?
  

  


yep, I want to test if the response back to the sending node is the
same string as the sending node is but then all uppercased. 

Roelof

  


--- End Message ---


Re: [Pharo-users] can I divide a string into part of exactly n length

2020-04-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 27-4-2020 om 19:05 schreef Richard
  Sargent:


  
  

  On Mon, Apr 27, 2020 at 9:27
AM Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
wrote:
  
  Hello,

I wonder if it is possible in Pharo to divide a string in
lets say part 
of 3.
so this :  'abcdefgh'

would be  'abc def gh`
  
  
  
  Do you really want a single string with spaces inserted
or do you want a collection of substrings, each three
characters (or less, for the last one)?
  

  


I need a single string with spaces inserted.
So maybe I have formulate my question wrong. Very difficult if
English is not your mother language and you were bad at school in
languages a very very long ago.

Roelof

  


--- End Message ---


Re: [Pharo-users] how can I test this

2020-04-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 27-4-2020 om 19:16 schreef Richard
  Sargent:


  
  

  On Mon, Apr 27, 2020 at 9:30
AM Roelof Wobben <r.wob...@home.nl> wrote:
  
  

  Op 27-4-2020 om 18:28 schreef Richard Sargent:
  
  

  
On Mon, Apr 27,
  2020 at 1:56 AM Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
  wrote:

Hello,
  
  I have to test the server which should return the
  string but then in 
  uppercase.
  
  So far I have this : 
  https://github.com/RoelofWobben/Network-simulator/blob/master/src/NetworkSimulator-Tests/KANetworkTest.class.st#L79
  
  but I fail to see how I can test that the package
  sending back is a 
  uppercase string.



I think you need to rephrase this question.
  Either the String class hierarchy has a method
  named something like #isUppercase or Character
  does. If only Character has it, you would need to
  iterate over the received string testing each
  individual character.


Or is your question more about getting the
  response back to the sending node?

  

  
  
  yep, I want to test if the response back to the sending
  node is the same string as the sending node is but then
  all uppercased. 

  
  
  
  Assuming you have the code written that sends a request
packet to a server, then makes the server process it and
send a response packet back to the original node, the
following pseudo-code should show you one way.
  
  
  | requestPacket responsePacket |
  requestPacket := ...
  ... send the request and get a response back ...
  responsePacket := self sendingNode nextReceivedPacket.
  
  
  self assert: responsePacket payload isUppercase
description: 'Response should have been uppercase'.
  self assert: (requestPacket payload equals:
responsePacket payload ignoreCase: true) description:
'Response is not the same string'.
  
  
  Those methods probably exist in Pharo, or something very
similar. e.g. it might be #equalsIgnoreCase:.
  
  

  


oke, 

I think I can move forward. 
I have some ideas how to make this work but have to try some things.


Thanks

Roelof

  


--- End Message ---


Re: [Pharo-users] how can I test this

2020-04-27 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 27-4-2020 om 19:50 schreef Roelof Wobben via Pharo-users:


This seems to be working


testKaNetWorkServer
    | srcNode destNode link packet link2 packet2 recievedPackage |
    srcNode := KANetworkNode withAddress: #src.
    destNode := KANetworkServer withAddress: #dest.
    link := (KANetworkLink from: srcNode to: destNode)
        attach;
        yourself.
    link2 := (KANetworkLink from: destNode to: srcNode)
        attach;
        yourself.
    packet := KANetworkPacket from: #src to: #dest payload: 'test'.
    srcNode send: packet via: link.
    destNode consume: packet.
    packet2 := link2 packetsToTransmit first.
    srcNode receive: packet2 from: destNode.
    recievedPackage := srcNode arrivedPackets first.
    self assert: recievedPackage payload equals: 'TEST'

I hope it is a good one.



--- End Message ---


[Pharo-users] mentor question 3 is there a formula for this

2020-04-28 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Hello, 

I try now to solve this one : 

ntroduction

  The diamond kata takes as its input a letter, and outputs it in
a diamond
shape. Given a letter, it prints a diamond starting with 'A',
with the
supplied letter at the widest point.
  Requirements
  
The first row contains one 'A'.
The last row contains one 'A'.
All rows, except the first and last, have exactly two
  identical letters.
All rows have as many trailing spaces as leading spaces.
  (This might be 0).
The diamond is horizontally symmetric.
The diamond is vertically symmetric.
The diamond has a square shape (width equals height).
The letters form a diamond shape.
The top half has the letters in ascending order.
The bottom half has the letters in descending order.
The four corners (containing the spaces) are triangles.
  
  Examples
  In the following examples, spaces are indicated by ·
characters.
  Diamond for letter 'A':
  A

  Diamond for letter 'C':
  ··A··
·B·B·
C···C
·B·B·
··A··


I noticed that if you take a quarter of it. you see this pattern 

001
010
100

where a 0 is a space and a 1 is the character.

Is there a easy way to make some sort of formula so I can make a output of this ? 


Roelof



  


--- End Message ---


Re: [Pharo-users] mentor question 3 is there a formula for this

2020-04-28 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Thanks, 
  
  And the 5 can also be calculated by   2 * (char - $a)  + 1 
  
  Roelof
  
  
  
  Op 28-4-2020 om 18:31 schreef Richard Sargent:


  
  
Formula? Well, it's pretty straight forward.


Let's start with the size of the diamond (it field,
  actually). In the example, there are two lines above and two
  lines below the "C" line. 

C-A = 2. This number looks useful.
The dimension is 2+1+2 square.


How many spaces before a letter? C-letter i.e. C-A = 2 C-B
  = 1 and C-C = 0
The same number of spaces after the second/last occurrence
  of the letter on the line.
The number of spaces between the letters on a line is the
  size minus the number of spaces before and after plus the two
  copies of the current line's letter. For the "B" line, there
  is one space before and after, 2x"B", leaving 5 - 1 -1 - 2 = 1
  space between. For the "A" line, the simple arithmetic would
  give you -1, which also confirms that just one "A" is
  appropriate with no space between first and last letter on the
  line. (For "A", it is first and last, once only.)


After that, you just need to iterate ($A to: $C), ($(C-1)
  to: $A by: -1) and do the arithmetic.

    
      
      
  
On Tue, Apr 28, 2020 at 1:23
  AM Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
  wrote:


   Hello, 

I try now to solve this one : 

ntroduction

  The diamond kata takes as its input a letter, and
outputs it in a diamond shape. Given a letter, it prints
a diamond starting with 'A', with the supplied letter at
the widest point.
  Requirements
  
The first row contains one 'A'.
The last row contains one 'A'.
All rows, except the first and last, have exactly
  two identical letters.
All rows have as many trailing spaces as leading
  spaces. (This might be 0).
The diamond is horizontally symmetric.
The diamond is vertically symmetric.
The diamond has a square shape (width equals
  height).
The letters form a diamond shape.
The top half has the letters in ascending order.
The bottom half has the letters in descending order.
The four corners (containing the spaces) are
  triangles.
  
  Examples
  In the following examples, spaces are indicated by ·
characters.
  Diamond for letter 'A':
  A

  Diamond for letter 'C':
  ··A··
·B·B·
C···C
·B·B·
··A··


I noticed that if you take a quarter of it. you see this pattern 

001
010
100

where a 0 is a space and a 1 is the character.

Is there a easy way to make some sort of formula so I can make a output of this ? 


Roelof



  

  


  


--- End Message ---


Re: [Pharo-users] mentor question 3 is there a formula for this

2020-04-29 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Am I right here or terrible wrong ?
  
  Roelof
  
  
  
  Op 28-4-2020 om 20:53 schreef Roelof Wobben:


  
  Thanks, 

And the 5 can also be calculated by   2 * (char - $a)  + 1 

Roelof



Op 28-4-2020 om 18:31 schreef Richard Sargent:
  
  


  Formula? Well, it's pretty straight forward.
  
  
  Let's start with the size of the diamond (it field,
actually). In the example, there are two lines above and two
lines below the "C" line. 
  
  C-A = 2. This number looks useful.
  The dimension is 2+1+2 square.
  
  
  How many spaces before a letter? C-letter i.e. C-A = 2
C-B = 1 and C-C = 0
  The same number of spaces after the second/last
occurrence of the letter on the line.
  The number of spaces between the letters on a line is the
size minus the number of spaces before and after plus the
two copies of the current line's letter. For the "B" line,
there is one space before and after, 2x"B", leaving 5 - 1 -1
- 2 = 1 space between. For the "A" line, the simple
arithmetic would give you -1, which also confirms that just
one "A" is appropriate with no space between first and last
letter on the line. (For "A", it is first and last, once
only.)
  
  
  After that, you just need to iterate ($A to: $C), ($(C-1)
to: $A by: -1) and do the arithmetic.
  
  
    
    
        
      On Tue, Apr 28, 2020 at 1:23
AM Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
wrote:
  
  
 Hello, 
  
  I try now to solve this one : 
  
  ntroduction
  
The diamond kata takes as its input a letter, and
  outputs it in a diamond shape. Given a letter, it
  prints a diamond starting with 'A', with the supplied
  letter at the widest point.
Requirements

  The first row contains one 'A'.
  The last row contains one 'A'.
  All rows, except the first and last, have exactly
two identical letters.
  All rows have as many trailing spaces as leading
spaces. (This might be 0).
  The diamond is horizontally symmetric.
  The diamond is vertically symmetric.
  The diamond has a square shape (width equals
height).
  The letters form a diamond shape.
  The top half has the letters in ascending order.
  The bottom half has the letters in descending
order.
  The four corners (containing the spaces) are
triangles.

Examples
In the following examples, spaces are indicated by ·
  characters.
Diamond for letter 'A':
A

Diamond for letter 'C':
··A··
·B·B·
C···C
·B·B·
··A··


I noticed that if you take a quarter of it. you see this pattern 

001
010
100

where a 0 is a space and a 1 is the character.

Is there a easy way to make some sort of formula so I can make a output of this ? 


Roelof


  

  

  
  


  


--- End Message ---


[Pharo-users] mentor question 4

2020-04-29 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Hello, 

I hope I can discuss my approch to this problem : 

Given a number determine whether or not it is valid per the Luhn
  formula.
The Luhn algorithm is
  a simple checksum formula used to validate a variety of
  identification
  numbers, such as credit card numbers and Canadian Social Insurance
  Numbers.
The task is to check if a given string is valid.
Validating a Number
Strings of length 1 or less are not valid. Spaces are allowed in
  the input,
  but they should be stripped before checking. All other non-digit
  characters
  are disallowed.
Example 1: valid credit card number
4539 1488 0343 6467

The first step of the Luhn algorithm is to double every second
  digit,
  starting from the right. We will be doubling
4_3_ 1_8_ 0_4_ 6_6_

If doubling the number results in a number greater than 9 then
  subtract 9
  from the product. The results of our doubling:
8569 2478 0383 3437

Then sum all of the digits:
8+5+6+9+2+4+7+8+0+3+8+3+3+4+3+7 = 80

If the sum is evenly divisible by 10, then the number is valid.
  This number is valid!


my idea was to do these steps 

1)  reverse the input. 

2)   use this to double every second  digit and calculate the sum
  of all the numbers :   

checkNumber :=  (collection reverse selectwith index: [:item
  :index | (index % 2 == 0) . IfTrue: [item *2]] )  sumNumbers 

3) check if its a valid  number by doing this : 
   
^ (checkNumber % 10 == 0)  



is this a good game plan or has it flaws or can I do it better ?
Regards, 


  Roelof


  


--- End Message ---


Re: [Pharo-users] mentor question 4

2020-04-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 30-4-2020 om 10:31 schreef Ben Coman:

collection := '8569 2478 0383 3437'.
(collection reverse selectWithIndex: [:item :index | (index % 2 == 0) 
ifTrue: [item *2]] )  inspect



I see a error and the non-even numbers are nill now.

but after some figgeling this seems to work :

collection := '8569247803833437'asArray.
checkNumber := (collection reverse withIndexCollect: [:item :index | 
(index % 2 == 0) ifTrue: [item asInteger *2] ifFalse: [item asInteger]] 
) sum inspect

^ checkNumber isDivisibleBy: 10




--- End Message ---


Re: [Pharo-users] mentor question 4

2020-04-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 30-4-2020 om 10:57 schreef Ben
  Coman:


  
  




  On Thu, 30 Apr 2020 at
16:46, Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
wrote:
  
  Op 30-4-2020 om 10:31
schreef Ben Coman:
> collection := '8569 2478 0383 3437'.
> (collection reverse selectWithIndex: [:item :index |
(index % 2 == 0) 
> ifTrue: [item *2]] )  inspect


I see a error and the non-even numbers are nill now.

but after some figgeling this seems to work :
  
  
  
  Great that you worked it out for yourself !!!  
  "figgeling" is a very important part of programming. 
  
  
   
  

collection := '8569247803833437' asArray.
checkNumber := (collection reverse withIndexCollect: [:item
:index | 
(index % 2 == 0) ifTrue: [item asInteger *2] ifFalse: [item
asInteger]] 
) sum inspect
^ checkNumber isDivisibleBy: 10
  
  
  
  That looks like it would work, but the inspect is
redundant now you know how it works.
  An important take away from this is that when you are
confused by what is happening, 
  you need to LOOK at each spot you data is transformed,
where "inspect" is your friend, particular running it from
the debugger.   
  
  
  
  Now there is another path you might try, but first I want
to stress  
  that I didn't know this answer a minute ago - I only just
discovered it !! 
  So this answer is not based on something magic I knew
directly, but on my approach to guess, search and test
within the system.
  
  
  I was considering how you were dealing with "every second
digit" and considered a general description of this was
"pairs".
I _wondered_ whether Pharo had any methods dealing with
"pairs" ?
  
  
  Spotter is a good place to ask this question, so I...
       Pressed  
       Typed... pair #i
  
  to see if there were any implementors containing the word
"pair" and discovered
SequenceableCollection>>#pairsCollect:
  
  
  3. First time I've seen that method, I wonder how it
works?
  The method comment gives a clue that the block takes two
arguments.
  So lets try-the-simplest-possible-thing...
      ( '123456' pairsCollect: [  :a :b | a ] ) inspect
  ==> #($1 $3 $5)
  
  
  So that looks useful. 
  Try experimenting with it yourself. 
  
  
  cheers -ben

  




I will do and till  now I did not find a way to update the second
one with it and keep the first one.
It seems I will loose the first number and then I cannot use it to
calculate the sum.

Roelof

  


--- End Message ---


Re: [Pharo-users] mentor question 4

2020-04-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 30-4-2020 om 15:10 schreef Stéphane
  Ducasse:


  
  
It looks like a cool problem
from where did you take it?

  

   I hope I can discuss my approch to this
problem : 

Given a number determine whether or not it
  is valid per the Luhn formula.
The Luhn
algorithm is a simple checksum formula used to
  validate a variety of identification numbers, such as
  credit card numbers and Canadian Social Insurance
  Numbers.
The task is to check if a given string is
  valid.


  

  
  
  
  I like people that are always thinking in string as if a
  collection of number would not make it :)

  

  
Validating a Number
Strings of length 1 or less are not valid.
  Spaces are allowed in the input, but they should be
  stripped before checking. All other non-digit
  characters are disallowed.
Example 1: valid credit card number
4539 1488 0343 6467

The first step of the Luhn algorithm is to
  double every second digit, starting from the right. We
  will be doubling
4_3_ 1_8_ 0_4_ 6_6_

If doubling the number results in a number
  greater than 9 then subtract 9 from the product. The
  results of our doubling:
8569 2478 0383 3437

Then sum all of the digits:
8+5+6+9+2+4+7+8+0+3+8+3+3+4+3+7 = 80

If the sum is evenly divisible by 10, then
  the number is valid. This number is valid!


my idea was to do these steps 

1)  reverse the input. 

2)   use this to double every second  digit
  and calculate the sum of all the numbers :   

checkNumber :=  (collection reverse
  selectwith index: [:item :index | (index % 2 == 0) .
  IfTrue: [item *2]] )  sumNumbers 

  

  
  
  
  
  
  you can also 
1 to: xx by: 2 do: 
  

  
 
3) check if its a valid  number by doing
  this : 
   
^ (checkNumber % 10 == 0)  



is this a good game plan or has it flaws or
  can I do it better ?
Regards, 


  Roelof


  
  
  

  



  

  

  

Stéphane Ducasse
http://stephane.ducasse.free.fr
  / http://www.pharo.org 
03 59 35 87 52
Assistant: Julie Jonas 
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne,
  Bât.A, Park Plaza

  Villeneuve d'Ascq 59650
  France

  

  

  


  


The last problems I posted here are all from the exercism pharo
track. 


  


--- End Message ---


Re: [Pharo-users] mentor question 4

2020-04-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 30-4-2020 om 15:10 schreef Stéphane
  Ducasse:


  
  
It looks like a cool problem
from where did you take it?

  

   I hope I can discuss my approch to this
problem : 

Given a number determine whether or not it
  is valid per the Luhn formula.
The Luhn
algorithm is a simple checksum formula used to
  validate a variety of identification numbers, such as
  credit card numbers and Canadian Social Insurance
  Numbers.
The task is to check if a given string is
  valid.


  

  
  
  
  I like people that are always thinking in string as if a
  collection of number would not make it :)

  

  
Validating a Number
Strings of length 1 or less are not valid.
  Spaces are allowed in the input, but they should be
  stripped before checking. All other non-digit
  characters are disallowed.
Example 1: valid credit card number
4539 1488 0343 6467

The first step of the Luhn algorithm is to
  double every second digit, starting from the right. We
  will be doubling
4_3_ 1_8_ 0_4_ 6_6_

If doubling the number results in a number
  greater than 9 then subtract 9 from the product. The
  results of our doubling:
8569 2478 0383 3437

Then sum all of the digits:
8+5+6+9+2+4+7+8+0+3+8+3+3+4+3+7 = 80

If the sum is evenly divisible by 10, then
  the number is valid. This number is valid!


my idea was to do these steps 

1)  reverse the input. 

2)   use this to double every second  digit
  and calculate the sum of all the numbers :   

checkNumber :=  (collection reverse
  selectwith index: [:item :index | (index % 2 == 0) .
  IfTrue: [item *2]] )  sumNumbers 

  

  
  
  
  
  
  you can also 
1 to: xx by: 2 do: 
  

  
 

  

  

  



Hmm, I looks like #do does not change the collection and I need to 

collection := '4539148803436467'.
1 to: (collection size + 1) by: 2 do: [:item | item asInteger * 2 ].
^ collection


  


--- End Message ---


Re: [Pharo-users] mentor question 4

2020-04-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 30-4-2020 om 16:06 schreef Richard O'Keefe:

This sounds very much like the Luhn test task at RosettaCode.
https://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
except that there it is described as working on the digits of an
integer.

(1) There are two approaches to traversing a sequence in reverse.
 (A) Reverse the sequence, then traverse the copy forward.
 aString reverse do: [:each | ...]
 (B) Just traverse the sequence in reverse
 aString reverseDo: [:each | ...]
 My taste is for the second.

(2) There are two approaches to deleting spaces.
 (A) Make a copy of the string without spaces.
 x := aString reject: [:each | each = Character space].
 x do: ...
 (B) Ignore spaces as you go:
 (i) aString do: [:each | each = Character space ifFalse: [...]]
 (ii) aString select: [:each | each ~= Character space] thenDo:
[:each | ...]

Combining (1A) and (2A) you get very obvious code:
 (aString reject: [:each | each = Character space]) reverse do:
[:digit } ...]
Combining (1B) and (2Bi) you get more efficient code:
 aString reverseDo: [:digit |
 digit = Character space ifFalse: [ ...]]

By the way, let's start by checking that the character in the string *are*
digits or spaces:
 (aString allSatisfy: [:each | each isDigit or: [each = Character s[ace]])
 ifFalse: [^false],

(3) There are two approaches to doubling the even digits.
 (A) Make a new string that starts as a copy and change every second
  digit from the right.
 (B) Simply *act* as if this has been done; keep track of whether the
 current digit position is even or odd and multiply by 1 or 2 as
 appropriate.
 nextIsOdd := true.
 aString reverseDo: [:digit |
 digit = Character space ifFalse: [
 nextIsOdd
 ifTrue:  [oddSum := ...]
 ifFalse: [evenSum := ...].
 nextIsOdd := nextIsOdd not]].

I *like* code that traverses a data structure exactly once and
allocates no intermediate garbage, so I'd be making (B) choices.




For me  , I use this to practice solving problems  and doing the "right" 
steps.

So I love it , that so many people share there way of solving it.
I can learn a lot from it
Expecially when they explain there thinking process so detailed.

I like this code also a lot.
Am  I correct for testing if it is a valid string by doing this ^ 
(oddSum + evenSum) dividedBy: 10


Roelof


--- End Message ---


Re: [Pharo-users] mentor question 4

2020-04-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 30-4-2020 om 16:16 schreef Roelof Wobben:

nextIsOdd := true.
 aString reverseDo: [:digit |
 digit = Character space ifFalse: [
 nextIsOdd
 ifTrue:  [oddSum := ...]
 ifFalse: [evenSum := ...].
 nextIsOdd := nextIsOdd not]].


hmm,

Still no luck with this code :

cardNumber := '4539 1488 0343 6467'.
oddSum := 0.
evenSum := 0.
nextIsOdd := true.
 cardNumber reverseDo: [:digit |
 digit = Character space ifFalse: [
 nextIsOdd
 ifTrue:  [oddSum := oddSum + digit asInteger ]
 ifFalse: [evenSum := ((digit asInteger * 2) > 9)
    ifTrue: [evenSum + ((digit asInteger * 2) - 9) ]
    ifFalse: [ evenSum + (digit asInteger * 2) ]].
        nextIsOdd := nextIsOdd not]].
^ oddSum + evenSum

the answer schould be 57 where I get 1157

So some debugging to do


--- End Message ---


Re: [Pharo-users] mentor question 4

2020-04-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

and also not with this one :

cardNumber := '4539 1488 0343 6467'.
oddSum := 0.
evenSum := 0.
nextIsOdd := false.
 cardNumber reverseDo: [:digit |
 digit = Character space ifFalse: [
 nextIsOdd
 ifFalse:  [oddSum := oddSum + (digit asString asInteger ) ]
 ifTrue: [(((digit asString asInteger) * 2) > 9)
    ifTrue: [evenSum := evenSum + ((digit asString asInteger)  * 2) - 9 ]
    ifFalse: [ evenSum := evenSum + (digit asString asInteger)  * 2 ]].
    nextIsOdd := nextIsOdd not]].
^ evenSum




Op 30-4-2020 om 18:30 schreef Roelof Wobben:

Op 30-4-2020 om 16:16 schreef Roelof Wobben:

nextIsOdd := true.
 aString reverseDo: [:digit |
 digit = Character space ifFalse: [
 nextIsOdd
 ifTrue:  [oddSum := ...]
 ifFalse: [evenSum := ...].
 nextIsOdd := nextIsOdd not]].


hmm,

Still no luck with this code :

cardNumber := '4539 1488 0343 6467'.
oddSum := 0.
evenSum := 0.
nextIsOdd := true.
 cardNumber reverseDo: [:digit |
 digit = Character space ifFalse: [
 nextIsOdd
 ifTrue:  [oddSum := oddSum + digit asInteger ]
 ifFalse: [evenSum := ((digit asInteger * 2) > 9)
    ifTrue: [evenSum + ((digit asInteger * 2) - 9) ]
    ifFalse: [ evenSum + (digit asInteger * 2) ]].
        nextIsOdd := nextIsOdd not]].
^ oddSum + evenSum

the answer schould be 57 where I get 1157

So some debugging to do




--- End Message ---


Re: [Pharo-users] mentor question 4

2020-04-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 30-4-2020 om 20:19 schreef Richard
  Sargent:


  
  
See below.



  On Thu, Apr 30, 2020 at
10:58 AM Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
wrote:
  
  and also not with this
one :

cardNumber := '4539 1488 0343 6467'.
oddSum := 0.
evenSum := 0.
nextIsOdd := false.
  cardNumber reverseDo: [:digit |
  digit = Character space ifFalse: [
  nextIsOdd
  ifFalse:  [oddSum := oddSum + (digit asString
asInteger ) ]
  ifTrue: [(((digit asString asInteger) * 2)
> 9)
 ifTrue: [evenSum := evenSum + ((digit asString
asInteger)  * 2) - 9 ]
 ifFalse: [ evenSum := evenSum + (digit asString
asInteger)  * 2 ]].
 nextIsOdd := nextIsOdd not]].
^ evenSum




Op 30-4-2020 om 18:30 schreef Roelof Wobben:
> Op 30-4-2020 om 16:16 schreef Roelof Wobben:
>> nextIsOdd := true.
>>  aString reverseDo: [:digit |
>>  digit = Character space ifFalse: [
>>  nextIsOdd
>>  ifTrue:  [oddSum := ...]
>>  ifFalse: [evenSum := ...].
>>  nextIsOdd := nextIsOdd not]].
>
> hmm,
>
> Still no luck with this code :
>
> cardNumber := '4539 1488 0343 6467'.
> oddSum := 0.
> evenSum := 0.
> nextIsOdd := true.
>  cardNumber reverseDo: [:digit |
>  digit = Character space ifFalse: [
>  nextIsOdd
>  ifTrue:  [oddSum := oddSum + digit
asInteger ]
>  ifFalse: [evenSum := ((digit asInteger *
2) > 9)
>     ifTrue: [evenSum + ((digit asInteger * 2) - 9) ]
>     ifFalse: [ evenSum + (digit asInteger * 2) ]].
>         nextIsOdd := nextIsOdd not]].
> ^ oddSum + evenSum
  
  
  
  With the one change to use #digitValue instead of
#asInteger (which answers the code point), the above
example  works.

| evenSum oddSum |
cardNumber := '4539 1488 0343 6467'.
oddSum := evenSum := 0.
nextIsOdd := true.
cardNumber reverseDo: [:digit |
  

   digit = Character space
  ifFalse: [
  


  
 nextIsOdd

  


  

   ifTrue:  [oddSum :=
  oddSum + digit digitValue ]
 ifFalse:
  [evenSum := ((digit digitValue * 2) > 9)
  

  


  

   ifTrue: [evenSum +
  ((digit digitValue * 2) - 9) ]
 ifFalse: [
  evenSum + (digit digitValue * 2) ]].
  

  


  
 nextIsOdd :=
nextIsOdd not]].

  


  
  ^ oddSum + evenSum
  
  gives me 80 for the answer.
  
  
  A few (mostly) minor points:
  - I don't see why "reverse" is necessary. Of course if
you use #do:, nextIsOdd needs to start with true.
  - repeating the "digit digitValue" or other variations
adds clutter and reduces clarity
  - 
((digit digitValue * 2) - 9) is not unreasonable, but could
be simplified. What is the largest integer X such that
2xX<=9?
  
  
  
  
  

  



Reverse is necessary because  the  * 2  needs  to be all even index
from the right.

oke, can I then make a temp variable digit which holds the value and
rename digit to character because it holding a character instead of
a digit 

when x is 5 or larger then  2 times the value will be greater then
10. 

so the code will be then : 

|
evenSum oddSum |
car

Re: [Pharo-users] mentor question 4

2020-04-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 1-5-2020 om 02:51 schreef Richard O'Keefe:

(oddSum + evenSum) dividedBy: 10

You previously had _ isDivisibleBy: 10
which certainly works.

Squeak, Pharo, and ST/X have #isDivisibleBy:
VisualWorks. Dolphin, and GNU Smalltalk do not.

Here's the code from Number.st in ST/X.
isDivisibleBy:aNumber
 "return true, if the receiver can be divided by the argument,
aNumber without a remainder.
  Notice, that the result is only worth trusting, if the receiver
is an integer."

 aNumber = 0 ifTrue: [^ false].
 aNumber isInteger ifFalse: [^ false].
 ^ (self \\ aNumber) = 0

The comment is wrong: the question makes sense for any combination
of exact numbers.
When, as in this case, aNumber is a literal integer, all
#isDivisibleBy: really adds is overhead.

(oddSum + evenSum) \\ 10 = 0

is quite clear, and completely portable.



On Fri, 1 May 2020 at 02:16, Roelof Wobben  wrote:

Op 30-4-2020 om 16:06 schreef Richard O'Keefe:

This sounds very much like the Luhn test task at RosettaCode.
https://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
except that there it is described as working on the digits of an
integer.

(1) There are two approaches to traversing a sequence in reverse.
  (A) Reverse the sequence, then traverse the copy forward.
  aString reverse do: [:each | ...]
  (B) Just traverse the sequence in reverse
  aString reverseDo: [:each | ...]
  My taste is for the second.

(2) There are two approaches to deleting spaces.
  (A) Make a copy of the string without spaces.
  x := aString reject: [:each | each = Character space].
  x do: ...
  (B) Ignore spaces as you go:
  (i) aString do: [:each | each = Character space ifFalse: [...]]
  (ii) aString select: [:each | each ~= Character space] thenDo:
[:each | ...]

Combining (1A) and (2A) you get very obvious code:
  (aString reject: [:each | each = Character space]) reverse do:
[:digit } ...]
Combining (1B) and (2Bi) you get more efficient code:
  aString reverseDo: [:digit |
  digit = Character space ifFalse: [ ...]]

By the way, let's start by checking that the character in the string *are*
digits or spaces:
  (aString allSatisfy: [:each | each isDigit or: [each = Character s[ace]])
  ifFalse: [^false],

(3) There are two approaches to doubling the even digits.
  (A) Make a new string that starts as a copy and change every second
   digit from the right.
  (B) Simply *act* as if this has been done; keep track of whether the
  current digit position is even or odd and multiply by 1 or 2 as
  appropriate.
  nextIsOdd := true.
  aString reverseDo: [:digit |
  digit = Character space ifFalse: [
  nextIsOdd
  ifTrue:  [oddSum := ...]
  ifFalse: [evenSum := ...].
  nextIsOdd := nextIsOdd not]].

I *like* code that traverses a data structure exactly once and
allocates no intermediate garbage, so I'd be making (B) choices.



For me  , I use this to practice solving problems  and doing the "right"
steps.
So I love it , that so many people share there way of solving it.
I can learn a lot from it
Expecially when they explain there thinking process so detailed.

I like this code also a lot.
Am  I correct for testing if it is a valid string by doing this ^
(oddSum + evenSum) dividedBy: 10

Roelof




oke,

so this is better

cardNumber := '8273 1232 7352 0569'.
oddSum := 0.
evenSum := 0.
nextIsOdd := false.
 cardNumber reverseDo: [:character |
      digit := character digitValue.
 character = Character space ifFalse: [
 nextIsOdd
 ifFalse:  [oddSum := oddSum + digit ]
 ifTrue: [(digit >= 5 )
    ifTrue: [evenSum := evenSum + (digit * 2) - 9 ]
    ifFalse: [ evenSum := evenSum + (digit * 2) ]].
    nextIsOdd := nextIsOdd not]].
^ evenSum + oddSum // 10 == 0.


where I could even make a seperate method of the ifTrue branch when the 
digit is greater then 5.




--- End Message ---


Re: [Pharo-users] mentor question 4

2020-05-02 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 1-5-2020 om 08:35 schreef Roelof Wobben:

Op 1-5-2020 om 02:51 schreef Richard O'Keefe:

(oddSum + evenSum) dividedBy: 10

You previously had _ isDivisibleBy: 10
which certainly works.

Squeak, Pharo, and ST/X have #isDivisibleBy:
VisualWorks. Dolphin, and GNU Smalltalk do not.

Here's the code from Number.st in ST/X.
isDivisibleBy:aNumber
 "return true, if the receiver can be divided by the argument,
aNumber without a remainder.
  Notice, that the result is only worth trusting, if the receiver
is an integer."

 aNumber = 0 ifTrue: [^ false].
 aNumber isInteger ifFalse: [^ false].
 ^ (self \\ aNumber) = 0

The comment is wrong: the question makes sense for any combination
of exact numbers.
When, as in this case, aNumber is a literal integer, all
#isDivisibleBy: really adds is overhead.

(oddSum + evenSum) \\ 10 = 0

is quite clear, and completely portable.



On Fri, 1 May 2020 at 02:16, Roelof Wobben  wrote:

Op 30-4-2020 om 16:06 schreef Richard O'Keefe:

This sounds very much like the Luhn test task at RosettaCode.
https://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
except that there it is described as working on the digits of an
integer.

(1) There are two approaches to traversing a sequence in reverse.
  (A) Reverse the sequence, then traverse the copy forward.
  aString reverse do: [:each | ...]
  (B) Just traverse the sequence in reverse
  aString reverseDo: [:each | ...]
  My taste is for the second.

(2) There are two approaches to deleting spaces.
  (A) Make a copy of the string without spaces.
  x := aString reject: [:each | each = Character space].
  x do: ...
  (B) Ignore spaces as you go:
  (i) aString do: [:each | each = Character space ifFalse: 
[...]]
  (ii) aString select: [:each | each ~= Character space] 
thenDo:

[:each | ...]

Combining (1A) and (2A) you get very obvious code:
  (aString reject: [:each | each = Character space]) reverse do:
[:digit } ...]
Combining (1B) and (2Bi) you get more efficient code:
  aString reverseDo: [:digit |
  digit = Character space ifFalse: [ ...]]

By the way, let's start by checking that the character in the 
string *are*

digits or spaces:
  (aString allSatisfy: [:each | each isDigit or: [each = 
Character s[ace]])

  ifFalse: [^false],

(3) There are two approaches to doubling the even digits.
  (A) Make a new string that starts as a copy and change every 
second

   digit from the right.
  (B) Simply *act* as if this has been done; keep track of 
whether the
  current digit position is even or odd and multiply by 1 
or 2 as

  appropriate.
  nextIsOdd := true.
  aString reverseDo: [:digit |
  digit = Character space ifFalse: [
  nextIsOdd
  ifTrue:  [oddSum := ...]
  ifFalse: [evenSum := ...].
  nextIsOdd := nextIsOdd not]].

I *like* code that traverses a data structure exactly once and
allocates no intermediate garbage, so I'd be making (B) choices.


For me  , I use this to practice solving problems  and doing the 
"right"

steps.
So I love it , that so many people share there way of solving it.
I can learn a lot from it
Expecially when they explain there thinking process so detailed.

I like this code also a lot.
Am  I correct for testing if it is a valid string by doing this ^
(oddSum + evenSum) dividedBy: 10

Roelof




oke,

so this is better

cardNumber := '8273 1232 7352 0569'.
oddSum := 0.
evenSum := 0.
nextIsOdd := false.
 cardNumber reverseDo: [:character |
      digit := character digitValue.
 character = Character space ifFalse: [
 nextIsOdd
 ifFalse:  [oddSum := oddSum + digit ]
 ifTrue: [(digit >= 5 )
    ifTrue: [evenSum := evenSum + (digit * 2) - 9 ]
    ifFalse: [ evenSum := evenSum + (digit * 2) ]].
    nextIsOdd := nextIsOdd not]].
^ evenSum + oddSum // 10 == 0.


where I could even make a seperate method of the ifTrue branch when 
the digit is greater then 5.




nobody who can say if this is a good solution ?

Roelof

--- End Message ---


Re: [Pharo-users] mentor question 4

2020-05-02 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 2-5-2020 om 19:33 schreef Ben Coman:


  
  




  On Sat, 2 May 2020 at 15:52,
Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org>
wrote:
  
  Op 1-5-2020 om 08:35
schreef Roelof Wobben:
>> On Fri, 1 May 2020 at 02:16, Roelof Wobben <r.wob...@home.nl> wrote:
>>> Op 30-4-2020 om 16:06 schreef Richard O'Keefe:
>>>> This sounds very much like the Luhn test
task at RosettaCode.
>>>> https://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
>>>> except that there it is described as
working on the digits of an
>>>> integer.
>>>>
>>>> (1) There are two approaches to traversing
a sequence in reverse.
>>>>   (A) Reverse the sequence, then
traverse the copy forward.
>>>>   aString reverse do: [:each | ...]
>>>>   (B) Just traverse the sequence in
reverse
>>>>   aString reverseDo: [:each | ...]
>>>>   My taste is for the second.
>>>>
>>>> (2) There are two approaches to deleting
spaces.
>>>>   (A) Make a copy of the string without
spaces.
>>>>   x := aString reject: [:each |
each = Character space].
>>>>   x do: ...
>>>>   (B) Ignore spaces as you go:
>>>>   (i) aString do: [:each | each =
Character space ifFalse: 
>>>> [...]]
>>>>   (ii) aString select: [:each |
each ~= Character space] 
>>>> thenDo:
>>>> [:each | ...]
>>>>
>>>> Combining (1A) and (2A) you get very
obvious code:
>>>>   (aString reject: [:each | each =
Character space]) reverse do:
>>>> [:digit } ...]
>>>> Combining (1B) and (2Bi) you get more
efficient code:
>>>>   aString reverseDo: [:digit |
>>>>   digit = Character space ifFalse:
[ ...]]
>>>>
>>>> By the way, let's start by checking that
the character in the 
>>>> string *are*
>>>> digits or spaces:
>>>>   (aString allSatisfy: [:each | each
isDigit or: [each = 
>>>> Character s[ace]])
>>>>   ifFalse: [^false],
>>>>
>>>> (3) There are two approaches to doubling
the even digits.
>>>>   (A) Make a new string that starts as
a copy and change every 
>>>> second
>>>>    digit from the right.
>>>>   (B) Simply *act* as if this has been
done; keep track of 
>>>> whether the
>>>>   current digit position is even or
odd and multiply by 1 
>>>> or 2 as
>>>>   appropriate.
>>>>   nextIsOdd := true.
>>>>   aString reverseDo: [:digit |
>>>>   digit = Character space ifFalse:
[
>>>>   nextIsOdd
>>>>   ifTrue:  [oddSum := ...]
>>>>   ifFalse: [evenSum := ...].
>>>>   nextIsOdd := nextIsOdd not]].
>>>>
>>>> I *like* code that traverses a data
structure exactly once and
>>>> allocates no intermediate garbage, so I'd
be making (B) choices.
>>>>
>>>>
>>> For me  , I use this to practice solving
problems  and doing the 
>>> "right"
>>> steps.
>>> So I love it , that so many people share there
way of solving it.
>>> I can learn a lot from it
>>> Expecially when they explain there thinking

Re: [Pharo-users] mentor question 4

2020-05-02 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 2-5-2020 om 21:09 schreef Roelof Wobben via Pharo-users:


but this seems to work :

cardNumber := '4539 1488 0343 6467'.
cleanDigits := cardNumber copyWithout: Character space.
preWrapDigits := (cleanDigits asArray reverse collectWithIndex: [ :char 
:idx | (idx even) ifTrue: [ 2 * char digitValue ] ifFalse:[char 
digitValue]]).
wrappedDigits :=  preWrapDigits collect: [ :d | d > 9 ifFalse: [ d ] 
ifTrue: [ d-9 ] ].

^ wrappedDigits sum isDivisibleBy: 10.

Can the code be more improved ?

Roelof


--- End Message ---


Re: [Pharo-users] mentor question 4

2020-05-03 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 3-5-2020 om 04:24 schreef Ben Coman:


  
  

  
  
  
  
On Sun, 3 May 2020 at
  03:09, Roelof Wobben <r.wob...@home.nl> wrote:


  
Op 2-5-2020 om 19:33 schreef Ben Coman:


  




  On Sat, 2 May
2020 at 15:52, Roelof Wobben via Pharo-users
<pharo-users@lists.pharo.org>
wrote:
  
  Op 1-5-2020
om 08:35 schreef Roelof Wobben:
>> On Fri, 1 May 2020 at 02:16, Roelof
Wobben <r.wob...@home.nl>
wrote:
>>> Op 30-4-2020 om 16:06 schreef
Richard O'Keefe:
>>>> This sounds very much like the
Luhn test task at RosettaCode.
>>>> https://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
>>>> except that there it is
described as working on the digits of an
>>>> integer.
>>>>
>>>> (1) There are two approaches to
traversing a sequence in reverse.
>>>>   (A) Reverse the sequence,
then traverse the copy forward.
>>>>   aString reverse do:
[:each | ...]
>>>>   (B) Just traverse the
sequence in reverse
>>>>   aString reverseDo:
[:each | ...]
>>>>   My taste is for the
second.
>>>>
>>>> (2) There are two approaches to
deleting spaces.
>>>>   (A) Make a copy of the
string without spaces.
>>>>   x := aString reject:
[:each | each = Character space].
>>>>   x do: ...
>>>>   (B) Ignore spaces as you
go:
>>>>   (i) aString do:
[:each | each = Character space ifFalse: 
>>>> [...]]
>>>>   (ii) aString select:
[:each | each ~= Character space] 
>>>> thenDo:
>>>> [:each | ...]
>>>>
>>>> Combining (1A) and (2A) you get
very obvious code:
>>>>   (aString reject: [:each |
each = Character space]) reverse do:
>>>> [:digit } ...]
>>>> Combining (1B) and (2Bi) you
get more efficient code:
>>>>   aString reverseDo:
[:digit |
>>>>   digit = Character
space ifFalse: [ ...]]
>>>>
>>>> By the way, let's start by
checking that the character in the 
>>>> string *are*
>>>> digits or spaces:
>>>>   (aString allSatisfy:
[:each | each isDigit or: [each = 
>>>> Character s[ace]])
>>>>   ifFalse: [^false],
>>>>
>>>> (3) There are two approaches to
doubling the even digits.
>>>>   (A) Make a new string
that starts as a copy and change every 
>>>> second
>>>>    digit from the
right.
>>>>   (B) Simply *act* as if
this has been done; keep t

Re: [Pharo-users] mentor question 4

2020-05-03 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 3-5-2020 om 12:32 schreef Ben Coman:


  
  

  


  On Sun., 3 May 2020,
3:48 pm Roelof Wobben, <r.wob...@home.nl> wrote:
  
  

  Op 3-5-2020 om 04:24 schreef Ben Coman:
  
  

  




  On Sun, 3
May 2020 at 03:09, Roelof Wobben <r.wob...@home.nl>
wrote:
  
  

  Op 2-5-2020 om 19:33 schreef Ben
Coman:
  
  

  
  
  
  
On
  Sat, 2 May 2020 at 15:52, Roelof
          Wobben via Pharo-users <pharo-users@lists.pharo.org>
  wrote:

Op
  1-5-2020 om 08:35 schreef Roelof
  Wobben:
  >> On Fri, 1 May 2020 at
  02:16, Roelof Wobben <r.wob...@home.nl>
  wrote:
  >>> Op 30-4-2020 om 16:06
  schreef Richard O'Keefe:
  >>>> This sounds very
  much like the Luhn test task at
  RosettaCode.
  >>>> https://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
  >>>> except that there
  it is described as working on the
  digits of an
  >>>> integer.
  >>>>
  >>>> (1) There are two
  approaches to traversing a
  sequence in reverse.
  >>>>   (A) Reverse
  the sequence, then traverse the
  copy forward.
  >>>>   aString
  reverse do: [:each | ...]
  >>>>   (B) Just
  traverse the sequence in reverse
  >>>>   aString
  reverseDo: [:each | ...]
  >>>>   My taste is
  for the second.
  >>>>
  >>>> (2) There are two
  approaches to deleting spaces.
  >>>>   (A) Make a
  copy of the string without spaces.
  >>>>   x :=
  aString reject: [:each | each =
  Character space].
  >>>>   x do:
  ...
  >>>>   (B) Ignore
  spaces as you go:
  >>>>   (i)
  aString do: [:each | each =
  Character space ifFalse: 
  >>>> [...]]
  >>>>   (ii)
  aString select: [:each | each ~=
  Character space] 
  >>>> thenDo:
  >>>> [:each | ...]
  >>>>
  >>>> Combining (1A)
  

[Pharo-users] mentor help continued

2020-07-14 Thread Roelof Wobben via Pharo-users
--- Begin Message ---
Sorry that you did not hear from me a long time but I was in a dark 
place for a long time.


but im back and have a question

I have to make a clock so the seconds and minutes schould not be above 60,

How can I take care of that ?

and can I put the code here on the class side on this given method

hour: anInteger minute: anInteger2
    self shouldBeImplemented

or schould I use that to make a call to the instance side and take care 
of there that the seconds and minutes are always valid.


Roelof


--- End Message ---


[Pharo-users] How can I do this. Put files on the right place on a repo

2020-08-24 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Hello, 

I have a repo and in that repo I have a directory named
/src/concepts where all the concept challenges must be placed
 

  later on there
will also a directory named /src/practice where all the practice
challenges are placed

 
I can in the IDE make a concept exercise but I do not see how I can
make it work that its placed in the right dire

This is for the new version of exercism 

Roelof

  


--- End Message ---


[Pharo-users] how to structure this project

2020-08-29 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

I want to make my first app with seaside and a database,
as database I use Postgres with the P3 driver of Glorp.

So I have a class Customer with the instance variables.
And  I have a Descriptorclass which takes care of the database.
And  I want to make a class which holds the layout.

But now I wonder if  I want to make a function that adds a customer from 
a form.

Or a page where I display all customers  or details of a customer.

Do I have to place them in the database layer and call that function or 
can I use the customer class for that.


Regards,

Roelof


--- End Message ---


[Pharo-users] mentoring continued I hope

2020-08-30 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

I have this challenge from exercism : 
https://github.com/exercism/pharo-smalltalk/tree/master/exercises/clock


and this function is given :

hour: anInteger minute: anInteger2
    self shouldBeImplemented


Schould I make it on this class method work that the minutes will not 
exceed the 59 minutes
So when for example when 70 min are given so hour:0  minute:70 it will 
be converted to hour: 1 minutes: 10

or can I better do this on the instance side.

Regards,

Roelof


--- End Message ---


[Pharo-users] mentoring contined I hope

2020-08-31 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  

  

  I would argue against that approach. Make it a
requirement that a given API must be used with correct
values.
  e.g. #hours:minutes: requires hours between 00 and 23 and
minutes between 00 and 59.
  
  
  If you want to convert equivalent time values, use a
specific API. For example, many time implementations
publicly define a seconds-based API, such as Time
class>>#fromSeconds:. You can do the same with your
implementation with a class-side #fromMinutes: method. (The
corresponding instance methods would be #asSeconds and
#asMinutes or something similar.)
  
  
  

  


Moment, I do not know if I understand you right. 

so I would use the given method and use on the instance another
function that takes care of the converting to or a valid time object
or for example convert it to minutes and on display take care that a
valid time is shown. 

Do I understand you right ? 

I send this personal because I cannot send to the mailing list
according to some spam list
  


--- End Message ---


Re: [Pharo-users] mentoring contined I hope

2020-08-31 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 1-9-2020 om 00:22 schreef Richard
  Sargent:


  
  

  On Mon, Aug 31, 2020 at 3:10
PM Roelof Wobben  wrote:
  
  

  Op 31-8-2020 om 23:45 schreef Richard Sargent:
  
  

  
On Mon, Aug 31,
  2020 at 1:57 PM Roelof Wobben 
  wrote:


  

  

  I would argue against that approach.
Make it a requirement that a given API
must be used with correct values.
  e.g. #hours:minutes: requires hours
between 00 and 23 and minutes between 00
and 59.
  
  
  If you want to convert equivalent
time values, use a specific API. For
example, many time implementations
publicly define a seconds-based API,
such as Time class>>#fromSeconds:.
You can do the same with your
implementation with a class-side
#fromMinutes: method. (The corresponding
instance methods would be #asSeconds and
#asMinutes or something similar.)
  
  
  

  


Moment, I do not know if I understand you right.


so I would use the given method and use on the
instance another function that takes care of the
converting to or a valid time object or for
example convert it to minutes and on display
take care that a valid time is shown. 

Do I understand you right ? 
  



I don't think you do, but it's a little
  difficult to determine.


Time hours: 0 minutes: 70 should throw
  an out of range exception on the second argument.
Time fromMinutes: 70 "should" answer an
  instance equivalent to 01:00. (I say should in
  quotes, because Time is a point in time. Duration
  is something that makes more sense to have Duration
minutes: 70 be acceptable.)


This discussion assumes your model of
  time uses just hours and minutes. Normally, Time
  includes seconds, and often fractions of seconds.
  But, you are working on an exercise, so a reduced
  scope Time may be appropriate.


Rather than talking about Time
  class>>#fromMinutes:, let's go a little more
  extreme and discuss a hypothetical Time
  class>>#fromHours: method. We understand and
  agree that Time can represent hours from 0 through
  23. There is no 24 o'clock. So, if you wrote Time
fromHours: 25, what would you expect to get
  for a result? What would someone who comes along
  later and uses your code expect to get? It's not
  well defined. So extrapolate from that case to the
  other cases. 70 minutes is not a time. "I'll meet
  you at 70 minutes" said no one ever. :-)
  ["in 70 minutes" is a duration from the
  present moment, implying a time 70 minutes in the
  future.]



I have come across a lot of code in my life.
  The hardest code to work with and to enhance is
  code that says it will try to accept whatever it's
  given. If it wants a number, it will accept a
  string of digits and "figure out" what nu

Re: [Pharo-users] mentoring contined I hope

2020-09-01 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
oke, then I would work with hour and minutes as the challenge
wanted,

  

  
 So still on the class side make code that convert any
  given hour and minute to a valid one ? 

  
  
  
  Yes. Such code would also be used when doing arithmetic
with Times. e.g. if you were to implement an instance method
named #addMinutes:, its implementation would be as simple as
^Time hours: self hours minutes: self minutes + anInteger
(assuming the argument has that name). The instance creation
method would normalize the new requested time, just like
Time hours: 0 minutes: 70 would do.
  
 
  Roelof
  

  

  



On some way I think or I do something wrong or I did misunderstood
you. 

 I did this in Pharo 

Object subclass: #Clock
    instanceVariableNames: 'hour minute'
    classVariableNames: ''
    package: 'Exercise@Clock'

I made a asscesors on the instance side. 

then I did this on the class side : 

hour: anInteger minute: anInteger2
    self hour: anInteger2 % 60 + anInteger;
    self minute: anInteger2 / 60; 
    yourself. 

but I see a message that hour and minutes are not known. 

Roelof

  


--- End Message ---


Re: [Pharo-users] mentoring contined I hope

2020-09-01 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Op 1-9-2020 om 21:11 schreef Richard Sargent:
You will discover an error when you write your tests, but that's fine. 
It's why you write tests. :-)


#validateTime:minute: is a poor name choice for a few reasons.
- there is no validation going on. Validation would report an error 
for invalid data.
- there is nothing to suggest what the first argument is, the 
counterpart to "minute:".

- it doesn't suggest there will be a new Time ("Clock") created.
- it's a "verb phrase" saying it will *do* something rather than 
answer something (I'm being vague here. Sorry.)


I suggest #normalizedForHour:minute:.
It explains that it will normalize the values and that it will answer 
a normalized result (it still isn't great, as it doesn't explain what).

Perhaps better would be #newNormalizedForHour:minute:.





Thanks,

I think I found the error

and solved it

hour: anInteger minute: anInteger2
    ^ self new
        hour: (anInteger2 // 60 + anInteger) % 24;
        minute: anInteger2 % 60;
        yourself

instance side :

printOn: aStream
    ^ aStream
        nextPutAll: self hour asTwoCharacterString;
        nextPut: $:;
        nextPutAll: self minute asTwoCharacterString

and the tests are green

now time to sleep and tomorrow time to figure out how to add and 
substract minutes.
As I remember it right you gave already the answer to me somewhere in 
our conversation


Roelof





I

--- End Message ---


Re: [Pharo-users] mentoring contined I hope

2020-09-01 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

  
  
Op 1-9-2020 om 21:40 schreef Roelof
  Wobben:

Op
  1-9-2020 om 21:11 schreef Richard Sargent:
  
  You will discover an error when you write
your tests, but that's fine. It's why you write tests. :-)


#validateTime:minute: is a poor name choice for a few reasons.

- there is no validation going on. Validation would report an
error for invalid data.

- there is nothing to suggest what the first argument is, the
counterpart to "minute:".

- it doesn't suggest there will be a new Time ("Clock") created.

- it's a "verb phrase" saying it will *do* something rather than
answer something (I'm being vague here. Sorry.)


I suggest #normalizedForHour:minute:.

It explains that it will normalize the values and that it will
answer a normalized result (it still isn't great, as it doesn't
explain what).

Perhaps better would be #newNormalizedForHour:minute:.



  
  
  
  Thanks,
  
  
  I think I found the error
  
  
  and solved it
  
  
  hour: anInteger minute: anInteger2
  
      ^ self new
  
          hour: (anInteger2 // 60 + anInteger) % 24;
  
          minute: anInteger2 % 60;
  
          yourself
  
  
  instance side :
  
  
  printOn: aStream
  
      ^ aStream
  
          nextPutAll: self hour asTwoCharacterString;
  
          nextPut: $:;
  
          nextPutAll: self minute asTwoCharacterString
  
  
  and the tests are green
  
  
  now time to sleep and tomorrow time to figure out how to add and
  substract minutes.
  
  As I remember it right you gave already the answer to me somewhere
  in our conversation
  
  
  Roelof
  
  


Making it a class method makes things very difficult 


  

--- End Message ---


[Pharo-users] Can it do this way ?

2020-09-01 Thread Roelof Wobben via Pharo-users
--- Begin Message ---

Hello,

I have now a challenge where I have to validate a ISBN number.

Can I do something like this on the class side :

(string isEmpty)
   ifTrrue: [ ^ false]
  ifFalse:  [ digits:= something.
   controlDigit := something.
   self validateISBNNumber]

where on the validateISBNNumber I use the instance variables digits and 
controlDigit to validate the ISBN number on the instance side.


Roelof







--- End Message ---


Re: [Pharo-users] Can it do this way ?

2020-09-02 Thread Roelof Wobben via Pharo-users
--- Begin Message ---
Yep, I know that isValidIsbn is the method that must output if a isbn is 
valid or not.


What I want to do is take the first 9 characters out so I can convert 
them to a array of numbers where I can do the calculation on.
And take out the last char so I can seperate test if that is a valid 
char. So between the 0 and 9 or a X


I do not think I would have do all the checks in that only method 
because it would be a very big method then.


but if I understand you well  also the test if a string is empty should 
be called from the isValidIsbn method or even checked there.


Roelof



--- End Message ---


  1   2   >