[Pharo-users] subpackages in P7

2018-11-27 Thread Roelof Wobben

Hello,

Right now I have three seperate packages.

Project
Project-test
Project-Actions


Is it possible in P7 to have something like this

Project
---   Tests
  Actions

and if so, how to I make it work,





Re: [Pharo-users] Tracking method in and out with MetaLinks

2018-11-27 Thread Marcus Denker
>>> 
>>> I am working now on making the #after work so that one can get with #value 
>>> the return of the method… 
>>> 
>>> I now have a version where it works for Message Sends correctly *and* were 
>>> #after on Method works better (the compilation errors should be fixed).
>>> 
>>> But  #value for #after on Method needs some more work… soon!
>>> 
> 
> #value for methods should now work with this PR loaded:
> 
>   https://github.com/pharo-project/pharo/pull/2012
> 
> This is implemented by compiling a wrapped method for #after (just as we do 
> for primitives).
> 
tests are green, so I merged it… 

But I keep 
https://pharo.fogbugz.com/f/cases/22681/Metalink-on-message-may-break-compilation
 open for now:

TODO for that issue:

- test if the use case shown in this issue now works

- write a test with the meta link from this issue to make sure this will not 
break in the future 
(the test should just apply it to an example, not  a whole package, though. For 
speed)

Marcus


Re: [Pharo-users] subpackages in P7

2018-11-27 Thread Esteban Lorenzano
Yes, you can :)
(But I would recommend it doing it with tests)

Usually, what you do is to create your package “Project” and then inside that 
package you can add the tags “test” and “Actions”,

But now you already have three packages, and you want to move, for example 
“Project-Actions” into “Project”. To do this you need to select 
“Project-Action” and with right click select the option “extras” in your 
context menu. From there, you need to select “demote to package with tag”. This 
will move all Project-Action package into “Project” package, “Action” tag.

Cheers, 
Esteban


> On 27 Nov 2018, at 09:33, Roelof Wobben  wrote:
> 
> Hello,
> 
> Right now I have three seperate packages.
> 
> Project
> Project-test
> Project-Actions
> 
> 
> Is it possible in P7 to have something like this
> 
> Project
> ---   Tests
>   Actions
> 
> and if so, how to I make it work,
> 
> 
> 




Re: [Pharo-users] Playing with Pharo 7

2018-11-27 Thread Steffen Märcker

Great!

Am .11.2018, 21:47 Uhr, schrieb Cyril Ferlicot D.  
:



Le 26/11/2018 à 16:57, Konrad Hinsen a écrit :


Thanks for the pointer! Unfortunately all the documentation there
assumes way more familiarity with Smalltalk than I have. And even a lot
of familiarity with Metacello itself, as the documentation only explains
the latest functionality.

The good news is that it refers to "Deep into Pharo", so I will download
that book and see if answers my questions.

Konrad.



Hello,

There is also a recent guide here:
https://github.com/pharo-tips-and-tricks/pharo-tips-and-tricks/blob/master/General/Baselines.md

I don't know if it is more beginner friendly. Feedback is welcome.







[Pharo-users] Do you have Pharo + SQLite experience?

2018-11-27 Thread Juraj Kubelka via Pharo-users
--- Begin Message ---
Hi all,

I would like to play with SQLite using Pharo. Does anyone use SQLite in Pharo 
(version 7)?
What library is recommended to use? And what is your experience (pros and cons) 
of the existing solutions? 
Do you have a project using SQLite in Pharo that I can download and look at it?

Thank you,
Juraj


--- End Message ---


Re: [Pharo-users] Do you have Pharo + SQLite experience?

2018-11-27 Thread Sven Van Caekenberghe
http://www.samadhiweb.com/tags/SQLite

> On 27 Nov 2018, at 13:16, Juraj Kubelka via Pharo-users 
>  wrote:
> 
> 
> From: Juraj Kubelka 
> Subject: Do you have Pharo + SQLite experience?
> Date: 27 November 2018 at 13:16:00 GMT+1
> To: Any question about pharo is welcome 
> 
> 
> Hi all,
> 
> I would like to play with SQLite using Pharo. Does anyone use SQLite in Pharo 
> (version 7)?
> What library is recommended to use? And what is your experience (pros and 
> cons) of the existing solutions? 
> Do you have a project using SQLite in Pharo that I can download and look at 
> it?
> 
> Thank you,
> Juraj
> 
> 
> 
> 




Re: [Pharo-users] Do you have Pharo + SQLite experience?

2018-11-27 Thread Juraj Kubelka via Pharo-users
--- Begin Message ---
That’s great. Thank you :-)

Juraj

> On Nov 27, 2018, at 09:40, Sven Van Caekenberghe  wrote:
> 
> http://www.samadhiweb.com/tags/SQLite
> 
>> On 27 Nov 2018, at 13:16, Juraj Kubelka via Pharo-users 
>>  wrote:
>> 
>> 
>> From: Juraj Kubelka 
>> Subject: Do you have Pharo + SQLite experience?
>> Date: 27 November 2018 at 13:16:00 GMT+1
>> To: Any question about pharo is welcome 
>> 
>> 
>> Hi all,
>> 
>> I would like to play with SQLite using Pharo. Does anyone use SQLite in 
>> Pharo (version 7)?
>> What library is recommended to use? And what is your experience (pros and 
>> cons) of the existing solutions? 
>> Do you have a project using SQLite in Pharo that I can download and look at 
>> it?
>> 
>> Thank you,
>> Juraj
>> 
>> 
>> 
>> 
> 


--- End Message ---


Re: [Pharo-users] subpackages in P7

2018-11-27 Thread Roelof Wobben

Thanks,

So better is leave it this way. So three seperate packages as I 
understand you well.


Roelof




Op 27-11-2018 om 10:47 schreef Esteban Lorenzano:

Yes, you can :)
(But I would recommend it doing it with tests)

Usually, what you do is to create your package “Project” and then inside that 
package you can add the tags “test” and “Actions”,

But now you already have three packages, and you want to move, for example 
“Project-Actions” into “Project”. To do this you need to select 
“Project-Action” and with right click select the option “extras” in your 
context menu. From there, you need to select “demote to package with tag”. This 
will move all Project-Action package into “Project” package, “Action” tag.

Cheers,
Esteban



On 27 Nov 2018, at 09:33, Roelof Wobben  wrote:

Hello,

Right now I have three seperate packages.

Project
Project-test
Project-Actions


Is it possible in P7 to have something like this

Project
---   Tests
  Actions

and if so, how to I make it work,











Re: [Pharo-users] Do you have Pharo + SQLite experience?

2018-11-27 Thread Offray Vladimir Luna Cárdenas
Hi Juraj

I used UDBC, that is documented in the blog referred by Sven. You can
find a Pharo project that uses it at [1]

[1] https://mutabit.com/offray/blog/en/entry/panama-papers-1

Cheers,

Offray

On 27/11/18 8:09, Juraj Kubelka via Pharo-users wrote:



Re: [Pharo-users] subpackages in P7

2018-11-27 Thread Esteban Lorenzano



> On 27 Nov 2018, at 15:03, Roelof Wobben  wrote:
> 
> Thanks,
> 
> So better is leave it this way. So three seperate packages as I understand 
> you well.

I just said I would keep “tests” separated. The rest I do not have any opinion 
:)

Esteban

> 
> Roelof
> 
> 
> 
> 
> Op 27-11-2018 om 10:47 schreef Esteban Lorenzano:
>> Yes, you can :)
>> (But I would recommend it doing it with tests)
>> 
>> Usually, what you do is to create your package “Project” and then inside 
>> that package you can add the tags “test” and “Actions”,
>> 
>> But now you already have three packages, and you want to move, for example 
>> “Project-Actions” into “Project”. To do this you need to select 
>> “Project-Action” and with right click select the option “extras” in your 
>> context menu. From there, you need to select “demote to package with tag”. 
>> This will move all Project-Action package into “Project” package, “Action” 
>> tag.
>> 
>> Cheers,
>> Esteban
>> 
>> 
>>> On 27 Nov 2018, at 09:33, Roelof Wobben  wrote:
>>> 
>>> Hello,
>>> 
>>> Right now I have three seperate packages.
>>> 
>>> Project
>>> Project-test
>>> Project-Actions
>>> 
>>> 
>>> Is it possible in P7 to have something like this
>>> 
>>> Project
>>> ---   Tests
>>>   Actions
>>> 
>>> and if so, how to I make it work,
>>> 
>>> 
>>> 
>> 
>> 
> 
> 




Re: [Pharo-users] Problems with NeoCSV Package

2018-11-27 Thread Peter Uhnak
Hi,

> Instance of ByteString doesn’t understand #atEnd.

This is a very typical error when you have accidentally passed a String
instead of a Stream.

... which you did here:
> stream := workingDir/myFileName readStreamDo: [ :stream | stream
contents].

You can either operate directly on the file stream, e.g.

file := 'D:\tmp\rules.csv' asFileReference.

result := file readStreamDo: [ :stream | |reader|
reader := NeoCSVReader new.
reader on: stream.
reader upToEnd.
].

Or if you already have a string, then ask it for its readStream

file := 'D:\tmp\rules.csv' asFileReference.

contents := file contents.
reader := NeoCSVReader new.
reader on: contents readStream.
reader upToEnd.



On Mon, Nov 26, 2018 at 11:27 PM William L. Cleveland 
wrote:

> I need to manually tag a large number of sentences choosing between a
> small, fixed number of short strings as tags for each sentence. I would
> like to do this with a Pharo GUI that displays sentences one at a time and
> permit choice of tags using radio buttons. The results need to be saved as
> a CSV file on the hard drive for further manipulations with python.
>
> As a first step, I used Excel to create a test CSV file with two sentences
> that was saved on the disk drive in the Pharo working directory.
>
> I have subsequently tried to import the sentences into Pharo 6.1 32 bit
> stable. This was done as follows.
>
> |workingDir reader result|
>
> workingDir := FileSystem disk workingDirectory.
>
> myFileName := 'MoonCSV.csv'.
>
> stream := workingDir/myFileName readStreamDo: [ :stream | stream
> contents].
>
>
>
> reader := (NeoCSVReader new) separator: Character cr.The separator
> was changed from a comma to a cr because the inspector showed a cr, not a
> comma separating the two imported sentences.
>
> result := (reader on: stream).
>
> result upToEnd.
>
>  This failed with the following error:
>
> Instance of ByteString doesn’t understand #atEnd.
>
>
> I don’t see how to proceed further. Also I am not clear on the best way to
> export the sentence and tags to the disk drive..
>
>
> Any help would be appreciated.
>
> Lou Cleveland
>


Re: [Pharo-users] subpackages in P7

2018-11-27 Thread Peter Uhnak
The main benefit of using separate packages instead of tags is that you can
choose what to load.

That's why MyPackage-Test is best kept separate, because when other project
is loading your project, they don't need to load such package (which can
speed up dependency loading and makes for smaller images).

As changing it in either direction is usually simple, don't worry about not
using the "right" style.

Peter

On Tue, Nov 27, 2018 at 3:36 PM Esteban Lorenzano 
wrote:

>
>
> > On 27 Nov 2018, at 15:03, Roelof Wobben  wrote:
> >
> > Thanks,
> >
> > So better is leave it this way. So three seperate packages as I
> understand you well.
>
> I just said I would keep “tests” separated. The rest I do not have any
> opinion :)
>
> Esteban
>
> >
> > Roelof
> >
> >
> >
> >
> > Op 27-11-2018 om 10:47 schreef Esteban Lorenzano:
> >> Yes, you can :)
> >> (But I would recommend it doing it with tests)
> >>
> >> Usually, what you do is to create your package “Project” and then
> inside that package you can add the tags “test” and “Actions”,
> >>
> >> But now you already have three packages, and you want to move, for
> example “Project-Actions” into “Project”. To do this you need to select
> “Project-Action” and with right click select the option “extras” in your
> context menu. From there, you need to select “demote to package with tag”.
> This will move all Project-Action package into “Project” package, “Action”
> tag.
> >>
> >> Cheers,
> >> Esteban
> >>
> >>
> >>> On 27 Nov 2018, at 09:33, Roelof Wobben  wrote:
> >>>
> >>> Hello,
> >>>
> >>> Right now I have three seperate packages.
> >>>
> >>> Project
> >>> Project-test
> >>> Project-Actions
> >>>
> >>>
> >>> Is it possible in P7 to have something like this
> >>>
> >>> Project
> >>> ---   Tests
> >>>   Actions
> >>>
> >>> and if so, how to I make it work,
> >>>
> >>>
> >>>
> >>
> >>
> >
> >
>
>
>


[Pharo-users] how to write this without a if then

2018-11-27 Thread Roelof Wobben

Hello,

Yesterday I had a talk with luc frabresse about using if then.
He said if I understand it right, Its the best to not using a if then or 
a ifTrue/ifFalse.


Can anyone help me figure out how to rewrite this project so I will not 
use the ifTrue in the basement function.


my code so far can be found here : https://github.com/RoelofWobben/AOC2015

Roelof




Re: [Pharo-users] Pharo 7 - RFB

2018-11-27 Thread Sanjay Minni
thanks all
 



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



Re: [Pharo-users] how to write this without a if then

2018-11-27 Thread Dale Henrichs

Roelof,

One technique to eliminating the use of #ifTrue:ifFalse: is to use 
double dispatching. There are some good examples of using double 
dispatching in Ralph Johnson's paper "ARITHMETIC AND DOUBLE DISPATCHING 
IN SMALLTALK-80"[1].  you should be able to get the basic idea by 
skimming the smalltalk code examples.


I used double dispatching fairly extensively in Metacello ...

In practice you may not eliminate all use of #ifTrue:ifFalse:, but 
double dispatching works quite well in places where you are tempted to 
do type checking...


Dale

[1] 
https://www.researchgate.net/publication/239578755_Arithmetic_and_double-_dispatching_in_smalltalk-80


On 11/27/18 8:40 AM, Roelof Wobben wrote:

Hello,

Yesterday I had a talk with luc frabresse about using if then.
He said if I understand it right, Its the best to not using a if then 
or a ifTrue/ifFalse.


Can anyone help me figure out how to rewrite this project so I will 
not use the ifTrue in the basement function.


my code so far can be found here : 
https://github.com/RoelofWobben/AOC2015


Roelof




Re: [Pharo-users] Problems with Firmata & Arduino UNO Clone

2018-11-27 Thread Denis Kudriashov
Hi William.

I think Serial port does not work in MacOS VM.

пн, 26 нояб. 2018 г. в 21:59, William L. Cleveland :

> I have been unsuccessful in using an Arduino board with Pharo 6.1(32bit)
> and the Firmata package.
>
>
>
> The board is an Arduino Uno clone (ELEGOO UNO R3). The board appears to
> work fine with the Arduino IDE, which was tested with the BLINK program.
> The Standard Firmata Library appears to have been successfully uploaded to
> the board using the Arduino IDE.
>
>
>
> COM ports have been closed using
>
> SerialPort allInstancesDo: [:port|port close].
>
> On Windows 10, SerialPort inspect shows that ports are closed. However,
> firmata := Firmata onPort: ‘COM3’ baudRate: 576000 failed due to failure to
> open COM3. The serial port name was obtained from the Arduino IDE Tools
> menu. The board choice was “Arduino Uno”.
>
>
>
>
>
> In MacOS 10.11.6, the same code generated a Cannot open comport message.
>
>
>
> Independently of Firmata, the following line of code SerialPort
> allInstancesDo: [:port| port close] generated the following error message:
> “Instance of BlockClosure did not understand #SerialPort. The same code
> worked fine in Windows.
>
>
>
> I am wondering if the SerialPort code in Pharo6.1 is sufficiently robust
> for a nonexpert programmer like myself, who only occasionally writes code
> for his own use. Previously, I wrote an application for a robotics project
> in 2008 using VisualWorks and the DLL&CConnect tool, which was quite
> successful. No more coding until just recently, when I started using
> Python.  Would like to go back to Smalltalk if it is sufficiently robust.
>
>
>
> Any help would be appreciated.
>
>
> Lou Cleveland
>


Re: [Pharo-users] Problems with Firmata & Arduino UNO Clone

2018-11-27 Thread Ben Coman
On Tue, 27 Nov 2018 at 05:59, William L. Cleveland 
wrote:

> I have been unsuccessful in using an Arduino board with Pharo 6.1(32bit)
> and the Firmata package.
>
>
>
> The board is an Arduino Uno clone (ELEGOO UNO R3). The board appears to
> work fine with the Arduino IDE, which was tested with the BLINK program.
> The Standard Firmata Library appears to have been successfully uploaded to
> the board using the Arduino IDE.
>
>
>
> COM ports have been closed using
>
> SerialPort allInstancesDo: [:port|port close].
>
> On Windows 10, SerialPort inspect shows that ports are closed. However,
> firmata := Firmata onPort: ‘COM3’ baudRate: 576000 failed due to failure to
> open COM3. The serial port name was obtained from the Arduino IDE Tools
> menu. The board choice was “Arduino Uno”.
>

Was the Arduino IDE closed before you started Pharo?
Or further, try Pharo immediately after booting your PC.

cheers -ben

>


Re: [Pharo-users] Playing with Pharo 7

2018-11-27 Thread Vitor Medina Cruz
The documentation on the book has much more information than needed to use
Metacello with Iceberg, it can confuse you more than help I am afraid, at
least this happened to me. The guide provided by Cyril is what you want.


Livre
de vírus. www.avg.com
.
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Tue, Nov 27, 2018 at 8:01 AM Steffen Märcker  wrote:

> Great!
>
> Am .11.2018, 21:47 Uhr, schrieb Cyril Ferlicot D.
> :
>
> > Le 26/11/2018 à 16:57, Konrad Hinsen a écrit :
> >>
> >> Thanks for the pointer! Unfortunately all the documentation there
> >> assumes way more familiarity with Smalltalk than I have. And even a lot
> >> of familiarity with Metacello itself, as the documentation only explains
> >> the latest functionality.
> >>
> >> The good news is that it refers to "Deep into Pharo", so I will download
> >> that book and see if answers my questions.
> >>
> >> Konrad.
> >>
> >
> > Hello,
> >
> > There is also a recent guide here:
> >
> https://github.com/pharo-tips-and-tricks/pharo-tips-and-tricks/blob/master/General/Baselines.md
> >
> > I don't know if it is more beginner friendly. Feedback is welcome.
> >
>
>
>
>


[Pharo-users] Loading Metacello with Seaside

2018-11-27 Thread Vitor Medina Cruz
Hello!

WIndows 10 here with Pharo 7 32 bits. Here is my baseline:


baseline: spec
>
> 
>
> spec for: #'common' do: [
> spec blessing: #'baseline';
>  repository: 'gitlab://vitormcruz/employees:master/pharo/';
>
>  project: 'Magritte3' with: [ spec repository:
> 'github://magritte-metamodel/magritte:v3.5.3/source';
>   className:
> 'ConfigurationOfMagritte3';
> loads: #(Seaside Core)
> ];
>
>   package: 'Employees' with: [ spec requires: #('Magritte3').
> ];
>
>group: 'default' with: #('core');
>   group: 'core' with: #('Employees')



When I execute:

Metacello new baseline: #Employees;
>   repository:
> 'gitlab://vitormcruz/employees:master/pharo/'; load: #(core)
>

I got:

"project group, or package named: 'Seaside-Pharo-Development' not found
> when used in requires: or includes: field of package:
> 'Seaside-Tests-Pharo-Development' for version: baseline of
> BaselineOfSeaside3."
>


It seems there is a problem with Magrite ConfigurationOf, am I correct?


Some general information:

1- Using https://github.com/magritte-metamodel/magritte instead
/magritte:v3.5.3/ of 'github://magritte-metamodel/magritte:v3.5.3/source
don't work;

2- You must provide className otherwise it does no work, even if docs says
itis not needed;

3- Metacello fail in ways it is hard to understand what happened;

4- On Pharo 64bits, Iceberg commit fails.


Livre
de vírus. www.avg.com
.
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>


Re: [Pharo-users] Loading Metacello with Seaside

2018-11-27 Thread Cyril Ferlicot D.
Le 28/11/2018 à 00:08, Vitor Medina Cruz a écrit :
> Hello!
> 
> WIndows 10 here with Pharo 7 32 bits. Here is my baseline:
> 
> 
> baseline: spec
>    
>     
>    
>     spec for: #'common' do: [
>         spec blessing: #'baseline';
>          repository: 'gitlab://vitormcruz/employees:master/pharo/';
>                                                            
>          project: 'Magritte3' with: [ spec repository:
> 'github://magritte-metamodel/magritte:v3.5.3/source';
>           className:
> 'ConfigurationOfMagritte3';
>                                                     loads: #(Seaside
> Core) ];
>                                                    
>               package: 'Employees' with: [ spec requires:
> #('Magritte3'). ];
>                                                    
>            group: 'default' with: #('core');
>               group: 'core' with: #('Employees')
> 
> 
> 
> When I execute:
> 
> Metacello new baseline: #Employees;
>                   repository:
> 'gitlab://vitormcruz/employees:master/pharo/'; load: #(core)
> 
> 
> I got:
> 
> "project group, or package named: 'Seaside-Pharo-Development' not
> found when used in requires: or includes: field of package:
> 'Seaside-Tests-Pharo-Development' for version: baseline of
> BaselineOfSeaside3."
> 
> 
> 
> It seems there is a problem with Magrite ConfigurationOf, am I correct?
> 
> 
> Some general information:
> 
> 1- Using https://github.com/magritte-metamodel/magritte instead
> /magritte:v3.5.3/ of 'github://magritte-metamodel/magritte:v3.5.3/source
> don't work;
> 
> 2- You must provide className otherwise it does no work, even if docs
> says itis not needed;
> 
> 3- Metacello fail in ways it is hard to understand what happened;
> 
> 4- On Pharo 64bits, Iceberg commit fails.
> 
> 
>   Livre de vírus. www.avg.com
> .
> 
> 
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Hi,

Personally I declare my Magritte dependency with the Seaside group this way:

spec
  baseline: 'Magritte'
  with: [ spec
loads: #('Seaside');
repository: 'github://magritte-metamodel/magritte:v3.5.3/source' ].

If it can help you, here is a recent guide to Baselines:
https://github.com/pharo-tips-and-tricks/pharo-tips-and-tricks/blob/master/General/Baselines.md

-- 
Cyril Ferlicot
https://ferlicot.fr



signature.asc
Description: OpenPGP digital signature


Re: [Pharo-users] how to write this without a if then

2018-11-27 Thread Richard O'Keefe
The idea of a flat ban on #ifTrue:ifFalse: is ridiculous.
Number>>abs
   ^self negative ifTrue: [self negated] ifFalse: [self]

Is there any better way to do this?  Not really, you can
only move the #ifTrue:ifFalse: somewhere else.

The main argument against #ifTrue:ifFalse: is NOT TO USE
IT FOR TYPE TESTS.  If you want to do different things
depending on the class of x, ask x to do it.  (The irony
is that in Smalltalk, #ifTrue:ifFalse: *is* in principle
an object-oriented dispatch.)  If you want to do
different things depending on the state of x, and this
requires revealing internal details that would not
otherwise be revealed, ask x to do it.

Two key ideas in software engineering are coupling
(lots of interdependencies makes things hard to re-use)
and cohesion (modules/types/classes should be "about"
one thing).  You have to balance the "use OO dispatch"
idea against this: you have a method in class A that
depends on an object of class B, and you don't want
A to have to know too much about B, but on the other
hand, you don't want B to have to depend too much on
what A is up to.  If it makes sense to have a B without
any A around, then changes to A should not really
require changes to B.

So eliminating #ifTrue:ifFalse: from your code can make
it WORSE.  You have to THINK about each task and decide
where it REALLY belongs.  Is this bit of code entirely
about B?  Then it belongs in B.  Is that bit of code
about already public information concerning B and also
tied to A's needs and wants?  Then it belongs in A.  And
if that means using some sort of "if", go ahead!

The Pharo 6 sources contain about 5800 classes and
over 4 ifTrue:/ifFalse:/ifNil:/ifNotNil: uses.
The Dolphin core contains about 2100 clases and
over 12600 ifs.
My Smalltalk has about 13 ifs per class.
Smalltalk/X (JV) has about 6500 classes and
over 127000 ifs, nearly 20 per class.



On Wed, 28 Nov 2018 at 05:41, Roelof Wobben  wrote:

> Hello,
>
> Yesterday I had a talk with luc frabresse about using if then.
> He said if I understand it right, Its the best to not using a if then or
> a ifTrue/ifFalse.
>
> Can anyone help me figure out how to rewrite this project so I will not
> use the ifTrue in the basement function.
>
> my code so far can be found here : https://github.com/RoelofWobben/AOC2015
>
> Roelof
>
>
>


Re: [Pharo-users] how to write this without a if then

2018-11-27 Thread Sven Van Caekenberghe



> On 28 Nov 2018, at 06:15, Richard O'Keefe  wrote:
> 
> The idea of a flat ban on #ifTrue:ifFalse: is ridiculous.
> Number>>abs
>^self negative ifTrue: [self negated] ifFalse: [self]
> 
> Is there any better way to do this?  Not really, you can
> only move the #ifTrue:ifFalse: somewhere else.
> 
> The main argument against #ifTrue:ifFalse: is NOT TO USE
> IT FOR TYPE TESTS.  If you want to do different things
> depending on the class of x, ask x to do it.  (The irony
> is that in Smalltalk, #ifTrue:ifFalse: *is* in principle
> an object-oriented dispatch.)  If you want to do
> different things depending on the state of x, and this
> requires revealing internal details that would not
> otherwise be revealed, ask x to do it.
> 
> Two key ideas in software engineering are coupling
> (lots of interdependencies makes things hard to re-use)
> and cohesion (modules/types/classes should be "about"
> one thing).  You have to balance the "use OO dispatch"
> idea against this: you have a method in class A that
> depends on an object of class B, and you don't want
> A to have to know too much about B, but on the other
> hand, you don't want B to have to depend too much on
> what A is up to.  If it makes sense to have a B without
> any A around, then changes to A should not really
> require changes to B.
> 
> So eliminating #ifTrue:ifFalse: from your code can make
> it WORSE.  You have to THINK about each task and decide
> where it REALLY belongs.  Is this bit of code entirely
> about B?  Then it belongs in B.  Is that bit of code
> about already public information concerning B and also
> tied to A's needs and wants?  Then it belongs in A.  And
> if that means using some sort of "if", go ahead!

Very well written, thanks.

> The Pharo 6 sources contain about 5800 classes and
> over 4 ifTrue:/ifFalse:/ifNil:/ifNotNil: uses.
> The Dolphin core contains about 2100 clases and
> over 12600 ifs.
> My Smalltalk has about 13 ifs per class.
> Smalltalk/X (JV) has about 6500 classes and
> over 127000 ifs, nearly 20 per class.
> 
>  
> 
> On Wed, 28 Nov 2018 at 05:41, Roelof Wobben  wrote:
> Hello,
> 
> Yesterday I had a talk with luc frabresse about using if then.
> He said if I understand it right, Its the best to not using a if then or 
> a ifTrue/ifFalse.
> 
> Can anyone help me figure out how to rewrite this project so I will not 
> use the ifTrue in the basement function.
> 
> my code so far can be found here : https://github.com/RoelofWobben/AOC2015
> 
> Roelof
> 
> 




Re: [Pharo-users] how to write this without a if then

2018-11-27 Thread Tim Mackinnon


> The idea of a flat ban on #ifTrue:ifFalse: is ridiculous.
> Number>>abs
>^self negative ifTrue: [self negated] ifFalse: [self]
> 
> Is there any better way to do this?  Not really, you can
> only move the #ifTrue:ifFalse: somewhere else.

But still it’s always a good thought experiment to think about how to do it 
without the if, as many more interesting objects and approaches can come out of 
it.

From above - it might be interesting if positive numbers were different from 
negative ones ... I’m not saying you would do it (there are often trade offs) 
but it’s too easy to stick in an if and miss out on a richer domain.

Tim



[Pharo-users] [ANN] Teapot was moved to GitHub

2018-11-27 Thread Attila Magyar
Hi,

I just want to let you know that the source code of Teapot was moved from
Smalltalkhub to GitHub.

The new repository is located at:

https://github.com/zeroflag/teapot   

Attila



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



Re: [Pharo-users] how to write this without a if then

2018-11-27 Thread Richard O'Keefe
In Advent-of-Code 2015, the first problem is
really quite simple.  There are at least two
ways to think about it.
"CS101":
   set a counter to 0
   for each character of the string
 if it is '(' increment the counter
 if it is ')' decrement the counter
   report the counter

"Higher level":
   report the difference between
 (the number of '(' characters in the string) and
 (the number of ')' characters in the string).

Expressed in Smalltalk this looks something like
  Transcript print:
(s occurrencesOf: $() - (s occurrencesOf: $)); cr.

Make no mistake: you *cannot* tell the difference
between $( and $) using class-based dispatch because
they belong to the same class.  There has to be an
"if" somewhere, the question is not whether but where.
In this case, counting the number of occurrences of an
object in a collection is has been a standard Collection
method for nearly 40 years; it's one of the basic
operations you need to learn.

The "higher level" approach can be less efficient that
the "CS101" approach, but in a case like this we really
do not care.  We want the code to be *clear*.

What about the second part of the problem?
Not having submitted any answers, I can't actually
see the second part on the AOC site, but luckily you
have included it in your program.

We want to
   [find the first place] where
  [the cumulative sum] of (c=$()
  [minus]
  [the cumulative sum] of (c=$))
  equals -1.

The "CS101" approach is
   n := i := 0.
   while n >= 0 and i < size(s) do
  i +:= 1
  if s[i] = $( then n := n + 1
  if s[i] = $) then n := n - 1
   report n

The "higher level" approach looks something like
  n := (s cumCount: [:each | each = $(]) -
   (s cumCount: [:each | each = $)])
   indexOf: -1.
-- although it gives 0 instead of s size + 1 when
-1 is never reached.

Here #indexOf: is standard, #- is defined on sequences
in Squeak and Pharo, but #cumCount: does not
exist.  So we need something like

cumCount: aBlock
  |c a|
  a := Array new: self size.
  c := 0.
  self withIndexDo: [:each :i |
(aBlock value: each) ifTrue: [c := c + 1].
a at: i put: c].
  ^a
This is *not* coupled to the particular use we have
in mind for it; it is in no way tied to characters
or strings.  It's quite general.

Note: we do not need any new classes, except maybe
a place to put one problem-specific method.

While this answer, with no loop and no if in the
problem-specific code, is quite pretty, it has a
problem.  Suppose the string to have M characters
and the desired step to be number K.  The CS101
approach takes O(K) time and no allocations, but
the higher level approach takes O(M) time and
allocates three M-element Arrays.  (In a non-strict
functional language like Haskell, the higher level
version *also* takes O(K) time, and with a good
enough "deforesting" compiler should allocate no
data structures.)

For a problem like this, I really don't care about
the efficiency aspect.  If I *do* care about that,
then starting from a higher level version gives me
something to test a lower level version against.

To get an efficient answer to the second part,
we still don't need a new semantic class, just
some place to put the code.

Day1
  class methods:
indexOfFirstBasementTime: steps
  |floor|
  floor := 0.
  steps keysAndValuesDo: [:i :each |
each = $( ifTrue: [floor := floor + 1].
each = $) ifTrue: [floor := floor - 1].
floor = -1 ifTrue: [^i]].
  ^0 "same convention as #indexOf:"

Does this contain "if"?  Why yes, it does.
Is there any problem with that?  Why no, there isn't.
You need to treat members of the same class (left
parenthesis, right parenthesis, others) differently.
You need to treat members of the same class (minus
one, all other integers) differently.
Would there be any gain in clarity or maintainability
if these ifs were somehow eliminated?  Certainly NOT.

Quite the reverse, in fact.
input2 withIndexDo: [ :element :index | |action|
action:= SantaAction getActionFor: element. floor := action  doMovementFor:
floor .
self hasReachedBasement
ifTrue: [^ index]].
^ '-2'.

There is only one word for this: obfuscated.
I was initially puzzled by your returning -2
instead of the conventional 0 if the basement
is not reached, and then *deeply confused* by
the fact that you are returning a *string* in
this case.

Looking at your code, I was further confused
by variables called 'aSymbol' whose value is
always and only a Character, never a Symbol.
And if I am wrong that
IllegalMoveSanta class>> canHandleInput:
in Smalltalk is to return 0 when something is

approach



We want to find the first place where something
becomes true.  There are again at least to approaches.

On Wed, 28 Nov 2018 at 05:41, Roelof Wobben  wrote:

> Hello,
>
> Yesterday I had a talk with luc frabresse about using if then.
> He said if I understand it right, Its the best to not using a if then or
> a ifTrue/ifFalse