Re: [Pharo-users] mentor question 4

2020-05-15 Thread Ben Coman
On Fri, 15 May 2020 at 20:43, Richard O'Keefe wrote: > Why does it make no sense? > To a first approximation, > aCollection asWHATEVER > = > WHATEVER withAll: aCollection > > Consider > 'CAB' asSet > 'CAB' asArray > 'CAB' asSortedCollection > 'CAB' asBag > and so on. They all mean "an inst

Re: [Pharo-users] mentor question 4

2020-05-15 Thread Richard O'Keefe
PS: I should make it clear that I do not expect anArray asString to work for *all* arrays. In my Smalltalk, #(true false) asString raises an exception, and so does #(65 66 67) asString. On Sat, 16 May 2020 at 00:42, Richard O'Keefe wrote: > Why does it make no sense? > To a first approximation

Re: [Pharo-users] mentor question 4

2020-05-15 Thread Richard O'Keefe
Why does it make no sense? To a first approximation, aCollection asWHATEVER = WHATEVER withAll: aCollection Consider 'CAB' asSet 'CAB' asArray 'CAB' asSortedCollection 'CAB' asBag and so on. They all mean "an instance of the class named in the selector with the elements of the receiver." Wh

Re: [Pharo-users] mentor question 4

2020-05-14 Thread Stéphane Ducasse
thanks this is interesting. S. > On 12 May 2020, at 07:12, Richard O'Keefe wrote: > > For what it's worth, here's a moderately thorough examination of several > different Smalltalk systems. > Let A = astc, D = Dolphin, G = GNU Smalltalk, Q = Squeak, > S = ANSI standard, T = Strongtalk, V

Re: [Pharo-users] mentor question 4

2020-05-14 Thread Stéphane Ducasse
> On 11 May 2020, at 23:48, Richard Sargent wrote: > > > > On May 11, 2020 2:19:49 PM PDT, Richard O'Keefe wrote: >> I was saying that I expected #($a $b $c) asString ==> 'abc'. > > Over the years, I found myself being opposed to the idea that all objects can > sensibly have an #asString i

Re: [Pharo-users] mentor question 4

2020-05-14 Thread Stéphane Ducasse
> On 11 May 2020, at 23:19, Richard O'Keefe wrote: > > I was saying that I expected #($a $b $c) asString ==> 'abc’. To me it makes no sense. I do not understand what is asString in fact. > If you want something that can be read back, that's what #storeString is for, > > On Tue, 12 May 202

Re: [Pharo-users] mentor question 4

2020-05-12 Thread Richard Sargent
Richard, your diligence is awesome! I'm left feeling that, generally, objects should not implement nor understand #asString. I realize there is a lot of room for debate on this subject. On May 11, 2020 10:12:10 PM PDT, Richard O'Keefe wrote: >For what it's worth, here's a moderately thorough

Re: [Pharo-users] mentor question 4

2020-05-11 Thread Richard O'Keefe
For what it's worth, here's a moderately thorough examination of several different Smalltalk systems. Let A = astc, D = Dolphin, G = GNU Smalltalk, Q = Squeak, S = ANSI standard, T = Strongtalk, V = VisualWorks, X = ST/X #asString ADGPQST!X Character => String with: self ADGPQSTVX String =>

Re: [Pharo-users] mentor question 4

2020-05-11 Thread Jerry Kott
Hi all, I’ve been lurking so far, but I must add my voice here and agree with Richard. The malleability of Smalltalk tempts people into implementing #asString, #name, and similar semantically ambiguous method names. Like Richard, I regretted every single time I (or someone else on my team befor

Re: [Pharo-users] mentor question 4

2020-05-11 Thread Richard Sargent
On May 11, 2020 2:19:49 PM PDT, Richard O'Keefe wrote: >I was saying that I expected #($a $b $c) asString ==> 'abc'. Over the years, I found myself being opposed to the idea that all objects can sensibly have an #asString implementation. When it's been done, it ultimately caused more problem

Re: [Pharo-users] mentor question 4

2020-05-11 Thread Richard O'Keefe
I was saying that I expected #($a $b $c) asString ==> 'abc'. If you want something that can be read back, that's what #storeString is for, On Tue, 12 May 2020 at 01:28, Stéphane Ducasse wrote: > > > > On 5 May 2020, at 16:16, Richard O'Keefe wrote: > > By the way, while playing with this problem

Re: [Pharo-users] mentor question 4

2020-05-11 Thread Stéphane Ducasse
> By the way, while playing with this problem, I ran into a moderately > painful issue. > > There is a reason that Smalltalk has both #printString (to get a > printable representation of an object) and #asString (to convert a > sequence to another kind of sequence with the same elements.) If I >

Re: [Pharo-users] mentor question 4

2020-05-05 Thread Richard O'Keefe
By the way, while playing with this problem, I ran into a moderately painful issue. There is a reason that Smalltalk has both #printString (to get a printable representation of an object) and #asString (to convert a sequence to another kind of sequence with the same elements.) If I *want* #printS

Re: [Pharo-users] mentor question 4

2020-05-04 Thread Richard O'Keefe
As a coding experiment, I adapted Trygve Reenskoug's code to my Smalltalk compiler, put in my code slightly tweaked, and benchmarked them on randomly generated data. Result: a factor of 6.3. In Squeak it was a factor of ten. I had not, in all honesty, expected it to to be so high. On Tue, 5 Ma

Re: [Pharo-users] mentor question 4

2020-05-04 Thread Trygve Reenskaug
* A coding experiment.* Consider a Scrum development environment. Every programming team has an end user as a member. The team's task is to code a credit card validity check. A first goal is that the user representative shall read the code and agree that it is a correct rendering of their code

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, wrote:

Re: [Pharo-users] mentor question 4

2020-05-03 Thread Ben Coman
On Sun., 3 May 2020, 3:48 pm Roelof Wobben, wrote: > Op 3-5-2020 om 04:24 schreef Ben Coman: > > > > On Sun, 3 May 2020 at 03:09, Roelof Wobben 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.

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 wrote:

Re: [Pharo-users] mentor question 4

2020-05-02 Thread Ben Coman
On Sun, 3 May 2020 at 03:09, Roelof Wobben 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

Re: [Pharo-users] mentor question 4

2020-05-02 Thread Richard Sargent
On Sat, May 2, 2020 at 12:38 PM Roelof Wobben via Pharo-users < pharo-users@lists.pharo.org> wrote: > 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. > preW

Re: [Pharo-users] mentor question 4

2020-05-02 Thread Stéphane Ducasse
check with the finder and example S. > On 2 May 2020, at 21:09, Roelof Wobben wrote: > > > From: Roelof Wobben > Subject: Re: [Pharo-users] mentor question 4 > Date: 2 May 2020 at 21:09:12 CEST > To: Ben Coman , Any question about pharo is welcome > > >

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) ifTr

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 wrote: Op 1-5-2020 om

Re: [Pharo-users] mentor question 4

2020-05-02 Thread 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 wrote: > >>> Op 30-4-2020 om 16:06 schreef Richard O'Keefe: > This sounds very much like the Luhn tes

Re: [Pharo-users] mentor question 4

2020-05-02 Thread Richard Sargent
It's a good solution. On Sat, May 2, 2020, 00:52 Roelof Wobben via Pharo-users < pharo-users@lists.pharo.org> wrote: > 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:

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

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

Re: [Pharo-users] mentor question 4

2020-04-30 Thread 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 divid

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 wrote:

Re: [Pharo-users] mentor question 4

2020-04-30 Thread 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 =

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 asI

Re: [Pharo-users] mentor question 4

2020-04-30 Thread Pablo Navarro
I proposed as alternative to Luhn check. In special to validation problems like credit card number validation. El jue., 30 abr. 2020 11:11, Richard O'Keefe escribió: > I'm sure you could fit regular expressions into the Luhn check, > but I am rather mystified as to what one could possibly gain b

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]

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

Re: [Pharo-users] mentor question 4

2020-04-30 Thread Richard O'Keefe
I'm sure you could fit regular expressions into the Luhn check, but I am rather mystified as to what one could possibly gain by doing so. How do you do the equivalent of #(0 2 4 6 8 1 3 5 7 9) at: char digitValue + 1 in a regular expression and why would you want to? On Fri, 1 May 2020 at 01:31,

Re: [Pharo-users] mentor question 4

2020-04-30 Thread 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

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 :

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 :

Re: [Pharo-users] mentor question 4

2020-04-30 Thread Pablo Navarro
Hello!. For this problem is possible to use Regular Expressions too. https://ci.inria.fr/pharo-contribution/job/UpdatedPharoByExample/lastSuccessfulBuild/artifact/book-result/Regex/Regex.html Saludos, Pablo. El 30 de abr. de 2020 10:11 -0300, Stéphane Ducasse , escribió: > It looks like a cool p

Re: [Pharo-users] mentor question 4

2020-04-30 Thread 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 t

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 wrote: Op 30-4

Re: [Pharo-users] mentor question 4

2020-04-30 Thread 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

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

Re: [Pharo-users] mentor question 4

2020-04-30 Thread Ben Coman
On Thu, 30 Apr 2020 at 14:33, Roelof Wobben via Pharo-users < pharo-users@lists.pharo.org> wrote: > 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

[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