Re: [Pharo-users] Query on Pharo syntax

2018-09-20 Thread Offray Vladimir Luna Cárdenas
I learned something for sure from this exchange. Thanks Peter and Ben
for this public conversation.

Cheers,

Offray

On 9/10/18 7:56 PM, Ben Coman wrote:
> Its a very interesting and elegant aspect of Pharo 
> and I'm sure there are others at different parts of their journey
> learning Pharo
> who learnt something new from your question. 
>
> cheers -ben
>
> On Tue, 11 Sep 2018 at 03:13, PBKResearch  <mailto:pe...@pbkresearch.co.uk>> wrote:
>
> Thanks Ben – it’s all clear now. Thanks also to Esteban, who
> spared my blushes by answering direct!
>
> Peter Kenny
>
>  
>
> *From:*Pharo-users  <mailto:pharo-users-boun...@lists.pharo.org>> *On Behalf Of *Ben Coman
> *Sent:* 10 September 2018 19:56
> *To:* Any question about pharo is welcome
> mailto:pharo-users@lists.pharo.org>>
> *Subject:* Re: [Pharo-users] Query on Pharo syntax
>
>  
>
>  
>
> On Tue, 11 Sep 2018 at 02:44, PBKResearch  <mailto:pe...@pbkresearch.co.uk>> wrote:
>
> Hi All
>
>  
>
> This is an idiot question, I should know the answer, but I
> have looked around and can’t find relevant documentation. I’m
> not asking for a full answer, just a pointer as to where to
> start looking.
>
>  
>
> I have seen from examples in this forum that an expression
> like the following:
>
>  
>
> paras collect: [para| para prettyPrinted]
>
>  
>
> can be written more concisely as:
>
>  
>
> paras collect: #prettyPrinted
>
>  
>
> which obviously works when I try it. It doesn’t seem to fit in
> with the definition of #collect:, which requires a block as
> argument. Where can I find the relevant definition, either in
> method comments or in some general manual? Can the notation be
> extended,
>
>  
>
> Its not special notation.  Just a normal object (a Symbol) passed
> via a normal message.
>
>  
>
> for example to #select: - obviously with an argument which
> returns a Boolean? Can it be used with a method which requires
> an argument, e.g. as myArray collect: (#myMethod: arg)? Are
> there any other extensions?
>
>  
>
> Any help gratefully received.
>
>  
>
> Peter Kenny
>
>  
>
> Full answer ;)
>
> Its a combination of the following two methods...
>
>  
>
> Collection >> collect: aBlock 
>
>    | newCollection |
>
>    newCollection := self species new.
>
>    self do: [:each | newCollection add: (aBlock value:
> each)].
>
>    ^ newCollection 
>
>  
>
> Symbol value: anObject 
>
>    ^anObject perform: self.
>
>  
>
> When /aBlock/ is a symbol, that symbol is performed on /each/ element.
>
> And looking at  #select:  , yes it works the same... 
>
>  
>
> Collection >> select: aBlock 
>
>    | newCollection |
>
>    newCollection := self copyEmpty.
>
>    self do: [ :each | 
>
>   (aBlock value: each) 
>
>  ifTrue: [
> newCollection add: each ]].
>
>    ^newCollection
>
>  
>
> cheers -ben
>


Re: [Pharo-users] Query on Pharo syntax

2018-09-10 Thread Ben Coman
Its a very interesting and elegant aspect of Pharo
and I'm sure there are others at different parts of their journey learning
Pharo
who learnt something new from your question.

cheers -ben

On Tue, 11 Sep 2018 at 03:13, PBKResearch  wrote:

> Thanks Ben – it’s all clear now. Thanks also to Esteban, who spared my
> blushes by answering direct!
>
> Peter Kenny
>
>
>
> *From:* Pharo-users  *On Behalf Of *Ben
> Coman
> *Sent:* 10 September 2018 19:56
> *To:* Any question about pharo is welcome 
> *Subject:* Re: [Pharo-users] Query on Pharo syntax
>
>
>
>
>
> On Tue, 11 Sep 2018 at 02:44, PBKResearch  wrote:
>
> Hi All
>
>
>
> This is an idiot question, I should know the answer, but I have looked
> around and can’t find relevant documentation. I’m not asking for a full
> answer, just a pointer as to where to start looking.
>
>
>
> I have seen from examples in this forum that an expression like the
> following:
>
>
>
> paras collect: [para| para prettyPrinted]
>
>
>
> can be written more concisely as:
>
>
>
> paras collect: #prettyPrinted
>
>
>
> which obviously works when I try it. It doesn’t seem to fit in with the
> definition of #collect:, which requires a block as argument. Where can I
> find the relevant definition, either in method comments or in some general
> manual? Can the notation be extended,
>
>
>
> Its not special notation.  Just a normal object (a Symbol) passed via a
> normal message.
>
>
>
> for example to #select: - obviously with an argument which returns a
> Boolean? Can it be used with a method which requires an argument, e.g. as
> myArray collect: (#myMethod: arg)? Are there any other extensions?
>
>
>
> Any help gratefully received.
>
>
>
> Peter Kenny
>
>
>
> Full answer ;)
>
> Its a combination of the following two methods...
>
>
>
> Collection >> collect: aBlock
>
>| newCollection |
>
>newCollection := self species new.
>
>self do: [:each | newCollection add: (aBlock value: each)].
>
>^ newCollection
>
>
>
> Symbol value: anObject
>
>^anObject perform: self.
>
>
>
> When /aBlock/ is a symbol, that symbol is performed on /each/ element.
>
> And looking at  #select:  , yes it works the same...
>
>
>
> Collection >> select: aBlock
>
>| newCollection |
>
>newCollection := self copyEmpty.
>
>self do: [ :each |
>
>   (aBlock value: each)
>
>  ifTrue: [ newCollection add:
> each ]].
>
>^newCollection
>
>
>
> cheers -ben
>


Re: [Pharo-users] Query on Pharo syntax

2018-09-10 Thread PBKResearch
Thanks Ben – it’s all clear now. Thanks also to Esteban, who spared my blushes 
by answering direct!

Peter Kenny

 

From: Pharo-users  On Behalf Of Ben Coman
Sent: 10 September 2018 19:56
To: Any question about pharo is welcome 
Subject: Re: [Pharo-users] Query on Pharo syntax

 

 

On Tue, 11 Sep 2018 at 02:44, PBKResearch mailto:pe...@pbkresearch.co.uk> > wrote:

Hi All

 

This is an idiot question, I should know the answer, but I have looked around 
and can’t find relevant documentation. I’m not asking for a full answer, just a 
pointer as to where to start looking.

 

I have seen from examples in this forum that an expression like the following:

 

paras collect: [para| para prettyPrinted]

 

can be written more concisely as:

 

paras collect: #prettyPrinted

 

which obviously works when I try it. It doesn’t seem to fit in with the 
definition of #collect:, which requires a block as argument. Where can I find 
the relevant definition, either in method comments or in some general manual? 
Can the notation be extended,

 

Its not special notation.  Just a normal object (a Symbol) passed via a normal 
message.

 

for example to #select: - obviously with an argument which returns a Boolean? 
Can it be used with a method which requires an argument, e.g. as myArray 
collect: (#myMethod: arg)? Are there any other extensions?

 

Any help gratefully received.

 

Peter Kenny

 

Full answer ;)

Its a combination of the following two methods...

 

Collection >> collect: aBlock 

   | newCollection |

   newCollection := self species new.

   self do: [:each | newCollection add: (aBlock value: each)].

   ^ newCollection 

 

Symbol value: anObject 

   ^anObject perform: self.

 

When /aBlock/ is a symbol, that symbol is performed on /each/ element.

And looking at  #select:  , yes it works the same... 

 

Collection >> select: aBlock 

   | newCollection |

   newCollection := self copyEmpty.

   self do: [ :each | 

  (aBlock value: each) 

 ifTrue: [ newCollection add: each 
]].

   ^newCollection

 

cheers -ben



Re: [Pharo-users] Query on Pharo syntax

2018-09-10 Thread Ben Coman
On Tue, 11 Sep 2018 at 02:44, PBKResearch  wrote:

> Hi All
>
>
>
> This is an idiot question, I should know the answer, but I have looked
> around and can’t find relevant documentation. I’m not asking for a full
> answer, just a pointer as to where to start looking.
>
>
>
> I have seen from examples in this forum that an expression like the
> following:
>
>
>
> paras collect: [para| para prettyPrinted]
>
>
>
> can be written more concisely as:
>
>
>
> paras collect: #prettyPrinted
>
>
>
> which obviously works when I try it. It doesn’t seem to fit in with the
> definition of #collect:, which requires a block as argument. Where can I
> find the relevant definition, either in method comments or in some general
> manual? Can the notation be extended,
>

Its not special notation.  Just a normal object (a Symbol) passed via a
normal message.


> for example to #select: - obviously with an argument which returns a
> Boolean? Can it be used with a method which requires an argument, e.g. as
> myArray collect: (#myMethod: arg)? Are there any other extensions?
>
>
>
> Any help gratefully received.
>
>
>
> Peter Kenny
>

Full answer ;)
Its a combination of the following two methods...

Collection >> collect: aBlock
| newCollection |
newCollection := self species new.
self do: [:each | newCollection add: (aBlock value: each)].
^ newCollection

Symbol value: anObject
^anObject perform: self.

When /aBlock/ is a symbol, that symbol is performed on /each/ element.
And looking at  #select:  , yes it works the same...

Collection >> select: aBlock
| newCollection |
newCollection := self copyEmpty.
self do: [ :each |
(aBlock value: each)
ifTrue: [ newCollection add: each ]].
^newCollection

cheers -ben


[Pharo-users] Query on Pharo syntax

2018-09-10 Thread PBKResearch
Hi All

 

This is an idiot question, I should know the answer, but I have looked
around and can't find relevant documentation. I'm not asking for a full
answer, just a pointer as to where to start looking.

 

I have seen from examples in this forum that an expression like the
following:

 

paras collect: [para| para prettyPrinted]

 

can be written more concisely as:

 

paras collect: #prettyPrinted

 

which obviously works when I try it. It doesn't seem to fit in with the
definition of #collect:, which requires a block as argument. Where can I
find the relevant definition, either in method comments or in some general
manual? Can the notation be extended, for example to #select: - obviously
with an argument which returns a Boolean? Can it be used with a method which
requires an argument, e.g. as myArray collect: (#myMethod: arg)? Are there
any other extensions?

 

Any help gratefully received.

 

Peter Kenny