Pharo-users
By thread
pharo-users@lists.pharo.org
By month
Messages by month
- ----- 2026 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
May 2020
- 70 participants
- 337 messages
Re: [Pharo-users] mentor question 4
by Stéphane Ducasse
check with the finder and example
S.
> On 2 May 2020, at 21:09, Roelof Wobben <r.wobben(a)home.nl> wrote:
>
>
> From: Roelof Wobben <r.wobben(a)home.nl>
> Subject: Re: [Pharo-users] mentor question 4
> Date: 2 May 2020 at 21:09:12 CEST
> To: Ben Coman <btc(a)openinworld.com>, Any question about pharo is welcome <pharo-users(a)lists.pharo.org>
>
>
> 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(a)lists.pharo.org <mailto: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.wobben(a)home.nl <mailto:r.wobben@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 <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 ?
>>
>> You didn't actually ask a question :)
>>
>> btw, Its good you are stretching yourself to do it the most complicated way,
>> but pay attention that when Richard says HE "likes code that traverses a data structure exactly once"
>> its because he is starting with the philosophy to OPTIMISE for EFFICIENCY.
>> Often in programming that is the LAST thing you should do because to do so your code often becomes more complex,
>> and Kernagan's law applies...
>> https://talixa.com/blog/why-i-write-simple-code/ <https://talixa.com/blog/why-i-write-simple-code/>
>>
>> In general, you want to avoid premature optimization.
>> https://effectiviology.com/premature-optimization/ <https://effectiviology.com/premature-optimization/>
>>
>> The catch-phrase I see around this forum priorities things in this order:
>> 1. Make it work.
>> 2. Make it right.
>> 3. Make it fast.
>> and often you can stop at 2 because it is already "fast enough".
>>
>> Considering your code above, if I take TIME to go through it, I can evaluate that it seems right
>> but I remain feeling that I could have missed something.
>>
>> Something like Richard's (A) examples without loops I would consider to be "more good".
>> since each line can be dealt with individually.
>>
>> cardNumber := '4539 1488 0343 6467'.
>> cleanDigits := cardNumber copyWithout: Character space.
>> preWrapDigits := cleanDigits asArray collectWithIndex: [ :char :idx | (idx\\2 + 1) * char digitValue ].
>> wrappedDigits := preWrapDigits collect: [ :d | d > 9 ifFalse: [ d ] ifTrue: [ d-9 ] ].
>> ^ wrappedDigits sum isDivisibleBy: 10.
>>
>> A side benefit is having full result of each transformation available to be reviewed,
>> rather than having only pieces of it in view when you debug a loop.
>>
>> In the end though, yours is a good solution first and foremost because tried a more detailed way and you got it working!!
>> Remember there is more than one "good way" to do it depending on what you are optimising for - efficiency or readability.
>>
>> cheers -ben
>>
>
> I think I find readability more important then efficieny.
>
> But I think I have to alter your code. At first look it does not look like that every second value from the right is multiplied by 2.
>
> When the index is for example 7 .
>
> 7 // 2 gives 3.
> Maybe it needs to be %.
>
> 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
May 2, 2020
Re: [Pharo-users] Thinking aloud about project at hand
by Stéphane Ducasse
>
>> I'm thinking about implementing a software solution in Pharo (as one of the
> candidate environments), it's
>> a project that I'm dealing with professionally. The goal is to develop a
>> financial planning/simulation
>> application on the country level, which is at present developed as a set
>> of interrelated Excel spreadsheets.
>> The requirement is that the solution should be more "manageable",
>> resilient and straightforward than
>> Excel permits, that it should present a workflow to the user - i.e. , that
>> the tasks the user should do are
>> suggested through the GUI.
>
> Thanks again for all the ideas regarding my project. So far I prepared the
> domain model and all the calculations. The model might be changed in the
> future, but that's basically it. Now I'm going to focus on the user's
> workflow and GUI.
>
> I have to say that I'm positively surprised by Pharo. Besides Pharo, I
> explored the feasibility of using other environments for the same project,
> namely VBA, .NET, Python. What took me in VBA and C#.NET roughly two weeks -
> and these are my 'native' programming environments - I finished in five days
> in Pharo. If GUI and finalization will go smoothly, this will be a success.
> I'm playing with Pharo for some time, but until now I haven't done any
> serious work with it. Nice!
>
Thanks Tomaz.
This is a really interesting story.
Let us know and we will do our best to help you.
Spec20 has still some rough edges. But one step at a time.
I think that we will get to a point where we can start to breath a bit around Spec2.0.
S.
May 2, 2020
Re: [Pharo-users] mentor question 4
by Roelof Wobben
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
May 2, 2020
Re: [Pharo-users] mentor question 4
by Ben Coman
On Sat, 2 May 2020 at 15:52, Roelof Wobben via Pharo-users <
pharo-users(a)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.wobben(a)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 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 ?
>
You didn't actually ask a question :)
btw, Its good you are stretching yourself to do it the most complicated
way,
but pay attention that when Richard says HE "likes code that traverses a
data structure exactly once"
its because he is starting with the philosophy to OPTIMISE for EFFICIENCY.
Often in programming that is the LAST thing you should do because to do so
your code often becomes more complex,
and Kernagan's law applies...
https://talixa.com/blog/why-i-write-simple-code/
In general, you want to avoid premature optimization.
https://effectiviology.com/premature-optimization/
The catch-phrase I see around this forum priorities things in this order:
1. Make it work.
2. Make it right.
3. Make it fast.
and often you can stop at 2 because it is already "fast enough".
Considering your code above, if I take TIME to go through it, I can
evaluate that it seems right
but I remain feeling that I could have missed something.
Something like Richard's (A) examples without loops I would consider to be
"more good".
since each line can be dealt with individually.
cardNumber := '4539 1488 0343 6467'.
cleanDigits := cardNumber copyWithout: Character space.
preWrapDigits := cleanDigits asArray collectWithIndex: [ :char :idx |
(idx\\2 + 1) * char digitValue ].
wrappedDigits := preWrapDigits collect: [ :d | d > 9 ifFalse: [ d ]
ifTrue: [ d-9 ] ].
^ wrappedDigits sum isDivisibleBy: 10.
A side benefit is having full result of each transformation available to be
reviewed,
rather than having only pieces of it in view when you debug a loop.
In the end though, yours is a good solution first and foremost because
tried a more detailed way and you got it working!!
Remember there is more than one "good way" to do it depending on what you
are optimising for - efficiency or readability.
cheers -ben
May 2, 2020
Re: [Pharo-users] mentor question 4
by Richard Sargent
It's a good solution.
On Sat, May 2, 2020, 00:52 Roelof Wobben via Pharo-users <
pharo-users(a)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: 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 <r.wobben(a)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 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
>
>
May 2, 2020
Re: [Pharo-users] Thinking aloud about project at hand
by eftomi
> I'm thinking about implementing a software solution in Pharo (as one of the
candidate environments), it's
> a project that I'm dealing with professionally. The goal is to develop a
> financial planning/simulation
> application on the country level, which is at present developed as a set
> of interrelated Excel spreadsheets.
> The requirement is that the solution should be more "manageable",
> resilient and straightforward than
> Excel permits, that it should present a workflow to the user - i.e. , that
> the tasks the user should do are
> suggested through the GUI.
Thanks again for all the ideas regarding my project. So far I prepared the
domain model and all the calculations. The model might be changed in the
future, but that's basically it. Now I'm going to focus on the user's
workflow and GUI.
I have to say that I'm positively surprised by Pharo. Besides Pharo, I
explored the feasibility of using other environments for the same project,
namely VBA, .NET, Python. What took me in VBA and C#.NET roughly two weeks -
and these are my 'native' programming environments - I finished in five days
in Pharo. If GUI and finalization will go smoothly, this will be a success.
I'm playing with Pharo for some time, but until now I haven't done any
serious work with it. Nice!
Best wishes,
Tomaz
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
May 2, 2020
Spec2 SpStringTableColumn
by Tomaž Turk
Dear all,
I'm exploring the new Spec2, looking for possibilities to create an
'editable grid'. Tables are very close to this concept, and I wonder
what exactly is SpStringTableColumn>>#beEditable supposed to do - I
cannot find any references to variable 'editable', so it looks like it's
not implemented yet?
Could editable grid be mimicked somehow with SpCompositeTableColumn?
Besides this, I wonder whether Spec2 could control keyboard events?
Many thanks and best wishes,
Tomaz
May 2, 2020
Re: [Pharo-users] mentor question 4
by Roelof Wobben
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 <r.wobben(a)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 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
May 2, 2020
Re: [Pharo-users] Package Browser (AKA 6-paned Browser) and Pharo package organization
by ducasse
In the past when hovering the package list, we could see the package mini description and it would be good to resurrect it.
Now stephen I suggest you try Pharo and see because many times when I reopened VW it looks like my fingers
were cut. Because I could not go super fast navigation.
Pharo is far from perfect but this is what we have and we take care of it. Now if you give us some thousands of Euros
you will not recognise it :).
So learn and have fun and you can improve Pharo with us.
S.
> Hi Stefen,
>
> Welcome to Pharo :-)
>
> Here are 2 tips that whould help you find your way :
> - Spotter (open it with Shift+Enter). It searches the whole image for names (classes, methods...) that include the given substring
> - Finder (Menu Tools) : Allows various kinds of searches. Searching with examples does allow finding a message that provides a given outcome given a receiver, and parameters.
>
> Please note that the image does include only a small subset of what you can do with Pharo. There's much more out there. One way to discover cool stuff, is to visit this catalog:
> https://github.com/pharo-open-documentation/awesome-pharo <https://github.com/pharo-open-documentation/awesome-pharo>
>
> Cheers,
> Noury
>
>> On 30 Apr 2020, at 21:00, stephen(a)heaveneverywhere.com <mailto:stephen@heaveneverywhere.com> wrote:
>>
>>
>> Hello friends,
>>
>> Iâm getting started with Pharo after decades using VisualWorks and Squeak; itâs pretty wonderful what you all have assembled!
>>
>> My question is related to what we used to teach as the first law of software reuse: âYou canât reuse it if you canât find it,â and the related software engineering "principle of least astonishment."
>>
>> When I fire up Pharo, the system browser presents me with a list of several hundred categories (from AST to Zodiac) in a system with over 8000 classes. The system categorization makes no sense since I donât know the naming conventions and so many packages have cute but quite non-descriptive names (Zinc? Metacello? Calypso?).
>>
>> In Smalltalk-80, the class category names were organized as a 2-level hierarchy where the top-level were items such as Magnitudes, Collections, Streams, Graphics, Text, System, Tools, Files, etc. This made it easy to find (e.g.,) the browser source code by looking in the Tools package for the class category Tools-Browser. Even packages with cute names (like my own âSirenâ), were categorized for ease of finding; e.g., the Siren classes were in class categories like Music-Events and Music-Magnitudes.
>>
>> Parsing the class category names on the first instance of $- made it possible to build 6-paned Browsers (called package pane browser in Squeak). (We acknowledged that this violates the âzero/one/infinity" rule.) Is something like this available for Pharo? I looked through the Calypso browser code and itâs so over-engineered (IMHO) that itâd take me several days to figure out how to implement this (it was about 1.5 pages of code in Smalltalk-80).
>>
>> If Pharo had a browser that scaled better and a reorganization/simplification of the class categories to use names that were more self-explanatory, it would be *much* easier for new users (in fact, for all users) to find their way around.
>>
>> I apologize for the stepping on toes...
>>
>> Stephen Pope
>>
>>
>> --
>>
>> Stephen Travis Pope Santa Barbara, California, USA
>> <pastedGraphic.tiff> http://HeavenEverywhere.com <http://heaveneverywhere.com/> http://FASTLabInc.com <http://fastlabinc.com/>
>> https://vimeo.com/user19434036/videos <https://vimeo.com/user19434036/videos> http://heaveneverywhere.com/Reflections <http://heaveneverywhere.com/Reflections>
>>
>> --
>>
>>
>>
>
May 1, 2020