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

2018-11-28 Thread Attila Magyar
Esteban A. Maringolo wrote
> Excellent material.
> I also liked that you not only provided instructions for installation,
> but also to set Teapot as a dependency.
> 
> Please add the `pharo` tag to the repository, so it gets listed in the
> topics section [1] and also helps bumping Pharo topic to the home of
> the Topics page.
> 
> [1] https://github.com/topics/pharo?o=desc=updated
> 
> Esteban A. Maringolo

Yeah, many of these were added by a contributor @fortizpenaloza, so big
thanks to him. 

Sure, I added the tags. 



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



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

2018-11-28 Thread Attila Magyar
Esteban A. Maringolo wrote
> Excellent material.
> I also liked that you not only provided instructions for installation,
> but also to set Teapot as a dependency.
> 
> Please add the `pharo` tag to the repository, so it gets listed in the
> topics section [1] and also helps bumping Pharo topic to the home of
> the Topics page.

Yeah, many of these were added by a contributor @fortizpenaloza, so big
thanks to him.

Sure, I added the tags.




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



Re: [Pharo-users] Reify RBLiteralNode and RBBlockNode args/return with MetaLink?

2018-11-28 Thread Manuel Leuenberger
Awesome, thanks for the effort Marcus! 

I was wondering if it would be useful to use matrix-testing for MetaLinks. I 
imagine having example methods which employ all features of the Smalltalk 
syntax (syntax on a postcard?), for which all intermediate results of 
expressions are known, then apply MetaLinks in all possible combinations 
(arguments x control) and check the reifications and side-effects against the 
oracle. Then the tests would generate a matrix of which combinations work and 
which don't. This should cover most of the possible executions.

Cheers,
Manuel

> On 28 Nov 2018, at 11:55, Marcus Denker  wrote:
> 
>> 
>> 
 iii) How are cascaded message sends reified? Am I supposed to instrument 
 the cascade node or the individual message sends?
 
>> 
>> https://pharo.fogbugz.com/f/cases/22702/support-before-after-intead-on-RBCascadeNode
>>  
>> 
>> 
>> It turns out this is just not implemented. Single message sends *inside* 
>> should work (as it calls the same code as a normal send to emit code).
>> But even that needs tests.
>> 
>> Cascade itself needs some code for links, then it will be easy to add 
>> reifications for #receiver and #value (and #operation).
>> 
> 
> Done:
> 
>   https://github.com/pharo-project/pharo/pull/2018 
> 
> 
> 
>   Marcus



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

2018-11-28 Thread Esteban Maringolo
El mié., 28 nov. 2018 a las 16:01, Sven Van Caekenberghe
() escribió:
>
> Nice docs, thank you.

+1

I couldn't avoid reading the whole getting started doc. Excellent material.
I also liked that you not only provided instructions for installation,
but also to set Teapot as a dependency.

Please add the `pharo` tag to the repository, so it gets listed in the
topics section [1] and also helps bumping Pharo topic to the home of
the Topics page.

[1] https://github.com/topics/pharo?o=desc=updated

Esteban A. Maringolo



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

2018-11-28 Thread Sven Van Caekenberghe
Nice docs, thank you.

> On 28 Nov 2018, at 08:49, Attila Magyar  wrote:
> 
> 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] Loading Metacello with Seaside

2018-11-28 Thread Vitor Medina Cruz
>
> "I tried to load magritte only and I got the same problem. Maybe I do not
> have it in my project because I load seaside before with an other group?"
>

Probably

"You can try to add seaside yourself in your project. Something like:"
>

I will try that :(


On Wed, Nov 28, 2018 at 3:22 PM Cyril Ferlicot D. 
wrote:

> Le 28/11/2018 à 17:38, Vitor Medina Cruz a écrit :
> > Tried now, didn't work, same error. It is working for you?
> >
>
> I tried to load magritte only and I got the same problem. Maybe I do not
> have it in my project because I load seaside before with an other group?
>
> I think there was an issue that is fixed in the dev version of Seaside
> about that. It should be in the next release.
>
> You can try to add seaside yourself in your project. Something like:
>
> baseline: spec
>   
>   spec
> for: #common
> do: [
> spec
> baseline: 'Seaside3' with: [ spec repository:
> 'github://SeasideSt/Seaside/repository' ];
> baseline: 'Magritte'
> with: [ spec
> loads: #('Seaside' 'Core');
> repository:
> 'github://magritte-metamodel/magritte:v3.5.3/source' ].
>   spec package: 'Employees' with: [ spec requires: #('Seaside3'
> 'Magritte') ] ]
>
>
>
> --
> Cyril Ferlicot
> https://ferlicot.fr
>
>


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

2018-11-28 Thread Norbert Hartl via Pharo-users
--- Begin Message ---
Great! Thanks!

Norbert

> Am 28.11.2018 um 08:49 schrieb 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
> 

--- End Message ---


Re: [Pharo-users] Loading Metacello with Seaside

2018-11-28 Thread Cyril Ferlicot D.
Le 28/11/2018 à 17:38, Vitor Medina Cruz a écrit :
> Tried now, didn't work, same error. It is working for you?
> 

I tried to load magritte only and I got the same problem. Maybe I do not
have it in my project because I load seaside before with an other group?

I think there was an issue that is fixed in the dev version of Seaside
about that. It should be in the next release.

You can try to add seaside yourself in your project. Something like:

baseline: spec
  
  spec
for: #common
do: [
spec
baseline: 'Seaside3' with: [ spec repository:
'github://SeasideSt/Seaside/repository' ];
baseline: 'Magritte'
with: [ spec
loads: #('Seaside' 'Core');
repository:
'github://magritte-metamodel/magritte:v3.5.3/source' ].
  spec package: 'Employees' with: [ spec requires: #('Seaside3'
'Magritte') ] ]



-- 
Cyril Ferlicot
https://ferlicot.fr



signature.asc
Description: OpenPGP digital signature


Re: [Pharo-users] Loading Metacello with Seaside

2018-11-28 Thread Vitor Medina Cruz
Tried now, didn't work, same error. It is working for you?

On Wed, Nov 28, 2018 at 8:34 AM Vitor Medina Cruz 
wrote:

> I tried with Baseline also, but it didn't work. I will try again as I can
> have made some mistake and I will report here.
>
> On Tue, Nov 27, 2018 at 9:19 PM Cyril Ferlicot D. <
> cyril.ferli...@gmail.com> wrote:
>
>> 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.
>> >
>> > <
>> http://www.avg.com/email-signature?utm_medium=email_source=link_campaign=sig-email_content=webmail
>> >
>> >   Livre de vírus. www.avg.com
>> > <
>> http://www.avg.com/email-signature?utm_medium=email_source=link_campaign=sig-email_content=webmail
>> >.
>> >
>> >
>> > <#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
>>
>>


Re: [Pharo-users] Unable to compile myself Pharo

2018-11-28 Thread teso...@gmail.com
Hi Alexandre,

  as Cédrick said there is no need to generate a new image from scratch.
Pharo is basically divided in two parts an image (that is the one that it
is generated by the process you want to run) and a virtual machine to run
the image.
The image is multi-OS you can download a 32 bits image and run it in any of
the supported operating systems.
Usually the VM will run in different OSs, there is a VM for  Mac OS, one
for Windows and one for Unix(es).
The VM came in 32 and 64 bits flavors.

You should try to run the pre built version of the pack. And again using
the Pharo Launcher will be the simpler option.

Cheers,
Pablo


On Wed, Nov 28, 2018 at 1:02 PM Cédrick Béler  wrote:

> Hi Alexandre,
>
> Do you really want to « bootstrap » an image ? You don’t need to (just use
> an official image).
>
> Try here, either through the launcher or the curl command line:
>
> https://pharo.org/download (Linux for thé launcher or at the end of the
> page from the command line.
>
> HTH,
>
> Cedrick
>
> Envoyé de mon iPhone
>
> Le 28 nov. 2018 à 11:23, Garreau, Alexandre  a
> écrit :
>
> Le 28/11/2018 à 11h17, Garreau, Alexandre a écrit :
>
> This VM uses a separate heartbeat thread to update its internal clock
>
> and handle events.  For best operation, this thread should run at a
>
> higher priority, however the VM was unable to change the priority.  The
>
> effect is that heavily loaded systems may experience some latency
>
> issues.  If this occurs, please create the appropriate configuration
>
> file in /etc/security/limits.d/ as shown below:
>
>
> cat <
> *  hardrtprio  2
>
> *  softrtprio  2
>
> END
>
>
> and report to the pharo mailing list whether this improves behaviour.
>
>
> Btw changing this didn’t improve anything until then, since build still
> fails (but the error disappeared).
>
> Sorry to clutter with a second mail.
>
>

-- 
Pablo Tesone.
teso...@gmail.com


Re: [Pharo-users] Unable to compile myself Pharo

2018-11-28 Thread Cédrick Béler
Hi Alexandre,

Do you really want to « bootstrap » an image ? You don’t need to (just use an 
official image). 

Try here, either through the launcher or the curl command line:

https://pharo.org/download (Linux for thé launcher or at the end of the page 
from the command line. 

HTH,

Cedrick

Envoyé de mon iPhone

> Le 28 nov. 2018 à 11:23, Garreau, Alexandre  a écrit :
> 
>> Le 28/11/2018 à 11h17, Garreau, Alexandre a écrit :
>> This VM uses a separate heartbeat thread to update its internal clock
>> and handle events.  For best operation, this thread should run at a
>> higher priority, however the VM was unable to change the priority.  The
>> effect is that heavily loaded systems may experience some latency
>> issues.  If this occurs, please create the appropriate configuration
>> file in /etc/security/limits.d/ as shown below:
>> 
>> cat <> *  hardrtprio  2
>> *  softrtprio  2
>> END
>> 
>> and report to the pharo mailing list whether this improves behaviour.
> 
> Btw changing this didn’t improve anything until then, since build still
> fails (but the error disappeared).
> 
> Sorry to clutter with a second mail.
> 


Re: [Pharo-users] Reify RBLiteralNode and RBBlockNode args/return with MetaLink?

2018-11-28 Thread Marcus Denker
> 
> 
>>> iii) How are cascaded message sends reified? Am I supposed to instrument 
>>> the cascade node or the individual message sends?
>>> 
> 
> https://pharo.fogbugz.com/f/cases/22702/support-before-after-intead-on-RBCascadeNode
>  
> 
> 
> It turns out this is just not implemented. Single message sends *inside* 
> should work (as it calls the same code as a normal send to emit code).
> But even that needs tests.
> 
> Cascade itself needs some code for links, then it will be easy to add 
> reifications for #receiver and #value (and #operation).
> 

Done:

https://github.com/pharo-project/pharo/pull/2018 



Marcus

Re: [Pharo-users] Loading Metacello with Seaside

2018-11-28 Thread Vitor Medina Cruz
I tried with Baseline also, but it didn't work. I will try again as I can
have made some mistake and I will report here.

On Tue, Nov 27, 2018 at 9:19 PM Cyril Ferlicot D. 
wrote:

> 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.
> >
> > <
> http://www.avg.com/email-signature?utm_medium=email_source=link_campaign=sig-email_content=webmail
> >
> >   Livre de vírus. www.avg.com
> > <
> http://www.avg.com/email-signature?utm_medium=email_source=link_campaign=sig-email_content=webmail
> >.
> >
> >
> > <#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
>
>


Re: [Pharo-users] Unable to compile myself Pharo

2018-11-28 Thread Garreau, Alexandre
Le 28/11/2018 à 11h17, Garreau, Alexandre a écrit :
> This VM uses a separate heartbeat thread to update its internal clock
> and handle events.  For best operation, this thread should run at a
> higher priority, however the VM was unable to change the priority.  The
> effect is that heavily loaded systems may experience some latency
> issues.  If this occurs, please create the appropriate configuration
> file in /etc/security/limits.d/ as shown below:
>
> cat < *  hardrtprio  2
> *  softrtprio  2
> END
>
> and report to the pharo mailing list whether this improves behaviour.

Btw changing this didn’t improve anything until then, since build still
fails (but the error disappeared).

Sorry to clutter with a second mail.



[Pharo-users] Unable to compile myself Pharo

2018-11-28 Thread Garreau, Alexandre
I need Pharo soon for my studies, and since it’s not packaged for debian
(how sad for something requiring bootstraping hence binaries :/) I
wanted to compile it, but (please tell me what additional informations I
could give you, I’m under Debian GNU/Linux 32bits for now) since then:

galex-713@portable:~/doc/comp/src/pharo$ make
./pharo bootstrapImage.image ./bootstrap/scripts/bootstrap.st --ARCH=32 
--BUILD_NUMBER=1 --quit
pthread_setschedparam failed: Operation not permitted
This VM uses a separate heartbeat thread to update its internal clock
and handle events.  For best operation, this thread should run at a
higher priority, however the VM was unable to change the priority.  The
effect is that heavily loaded systems may experience some latency
issues.  If this occurs, please create the appropriate configuration
file in /etc/security/limits.d/ as shown below:

cat >error:
[ self
error: 'Must provide VERSION_INFO in the form of a git describe --long' 
] in PBBootstrap class>>fromCommandLine in Block: [ self...
OrderedCollection(Collection)>>detect:ifFound:ifNone:
CommandLineArguments>>longOptionAt:ifAbsent:
CommandLineArguments>>optionAt:ifAbsent:
PBBootstrap class>>fromCommandLine
UndefinedObject>>DoIt
OpalCompiler>>evaluate
DoItChunk>>importFor:
[ :declaration | 
requestor ifNotNil: [ requestor contents: declaration contents ].
value := declaration importFor: requestor ] in CodeImporter>>evaluate in Block: 
[ :declaration | ...
OrderedCollection>>do:
CodeImporter>>evaluate
[ codeImporter evaluate ] in STCommandLineHandler>>installSourceFile: in Block: 
[ codeImporter evaluate ]
BlockClosure>>on:do:
STCommandLineHandler>>handleErrorsDuring:reference:
STCommandLineHandler>>installSourceFile:
[ :reference | self installSourceFile: reference ] in [ sourceFiles do: [ 
:reference | self installSourceFile: reference ] ] in 
STCommandLineHandler>>installSourceFiles in Block: [ :reference | self 
installSourceFile: reference ]...etc...
OrderedCollection>>do:
[ sourceFiles do: [ :reference | self installSourceFile: reference ] ] in 
STCommandLineHandler>>installSourceFiles in Block: [ sourceFiles do: [ 
:reference | self installSourc...etc...
BlockClosure>>ensure:
STCommandLineHandler>>installSourceFiles
STCommandLineHandler>>activate
STCommandLineHandler class(CommandLineHandler class)>>activateWith:
[ aCommandLinehandler activateWith: commandLine ] in 
PharoCommandLineHandler(BasicCommandLineHandler)>>activateSubCommand: in Block: 
[ aCommandLinehandler activateWith: commandLine ]
BlockClosure>>on:do:
PharoCommandLineHandler(BasicCommandLineHandler)>>activateSubCommand:
PharoCommandLineHandler(BasicCommandLineHandler)>>handleSubcommand
PharoCommandLineHandler(BasicCommandLineHandler)>>handleArgument:
[ self
handleArgument:
(self arguments
ifEmpty: [ '' ]
ifNotEmpty: [ :arguments | arguments first ]) ] in 
PharoCommandLineHandler(BasicCommandLineHandler)>>activate in Block: [ self...
BlockClosure>>on:do:
Makefile:125 : la recette pour la cible « bootstrap-cache/bootstrap.image » a 
échouée
make: *** [bootstrap-cache/bootstrap.image] Erreur 1
galex-713@portable:~/doc/comp/src/pharo$

Thank you for any help!



Re: [Pharo-users] Reify RBLiteralNode and RBBlockNode args/return with MetaLink?

2018-11-28 Thread Marcus Denker
>> 
>> 
>> i) How do I reify the value of an RB(Valuel|Literal|LiteralValue)Node? 
>> RFValueReification does not work, and there is no reification for literal, 
>> value, or literal value nodes.

This is now fixed. All subclasses of RBValueNode with the exception of Cascade 
now support #value. (Cascade: see below).

>> ii) How do I reify arguments and results of blocks? I tried reify context 
>> for the block body #before and value for #after block "last", but I often 
>> run into the problem of no reification for literals.

I added issue tracker entries:
https://pharo.fogbugz.com/f/cases/22704/Block-Execution-reify-value-in-after 

https://pharo.fogbugz.com/f/cases/22703/Block-execution-arguments-reification 


The story is that we for now unified links on BlockNode to be the same as a 
link on the block body (as we have with RBMethodNode).

But this is wrong:  a link on a block (e.g. ) [1] should fire when the block 
*definition* is evaluated. Only a link on the body should fire on execution.

If we link on the body, it will be possible to reify the #value (which is the 
value of the last statement).

So this is some work (and a non-backward compatible change), but will be done 
till next week I hope.

>> iii) How are cascaded message sends reified? Am I supposed to instrument the 
>> cascade node or the individual message sends?
>> 

https://pharo.fogbugz.com/f/cases/22702/support-before-after-intead-on-RBCascadeNode
 


It turns out this is just not implemented. Single message sends *inside* should 
work (as it calls the same code as a normal send to emit code).
But even that needs tests.

Cascade itself needs some code for links, then it will be easy to add 
reifications for #receiver and #value (and #operation).

I will do that today I hope.

Marcus

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

2018-11-28 Thread Roelof Wobben

  
  
Thanks for all the explanations. 
  
  and yes, I have to get a feel when I need a new class and when
  not. 
  and when it's "allowed" to use a if then and when not. 
  
  and if I understand the explanations I did not ask a class
  something so a if then is 
  allowed. 
  
  Roelof
  
  
  
  Op 28-11-2018 om 09:01 schreef Richard O'Keefe:


  
  
DRAT!  What (genius
  negated) designed gmail's interface?


If I am wrong that the
  canHandleInput: class method of
IllegalMoveSanta
  should return false, not true (because
the order of the
  elements of #subclasses is not defined,
so that
  IllegalMoveSanta might *always* be selected),
then that is further
  evidence that avoiding "if" made
the code LESS
  readable.


You are a beginner at
  this, doing all the right things
for a beginner to do. 
  One of the things you have to do
is to develop a sense
  of "smell" for code.  Each class
ought to "pull its
  weight".  Four classes -- which it
really does not make
  sense to instantiate, just put the
instance methods on
  the class side and drop the #new --
just to avoid a couple
  of very clear "ifs"?  I don't
think so.  IF THESE
  CLASSES NEEDED TO EXIST FOR SOME
OTHER REASON, if they
  had real work to do, sure.  But
they don't.  They only
  bloat and obscure the code.




  
  
  
On Wed, 28 Nov 2018 at 20:54, Richard O'Keefe
  
  wrote:


  

  

  
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
 

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

2018-11-28 Thread Richard O'Keefe
DRAT!  What (genius negated) designed gmail's interface?

If I am wrong that the canHandleInput: class method of
IllegalMoveSanta should return false, not true (because
the order of the elements of #subclasses is not defined,
so that IllegalMoveSanta might *always* be selected),
then that is further evidence that avoiding "if" made
the code LESS readable.

You are a beginner at this, doing all the right things
for a beginner to do.  One of the things you have to do
is to develop a sense of "smell" for code.  Each class
ought to "pull its weight".  Four classes -- which it
really does not make sense to instantiate, just put the
instance methods on the class side and drop the #new --
just to avoid a couple of very clear "ifs"?  I don't
think so.  IF THESE CLASSES NEEDED TO EXIST FOR SOME
OTHER REASON, if they had real work to do, sure.  But
they don't.  They only bloat and obscure the code.



On Wed, 28 Nov 2018 at 20:54, Richard O'Keefe  wrote:

> 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