Amber and Pharo

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Amber and Pharo

horrido
I thought Pharo was the reference implementation for Amber. Why does the following code snippet from Sven VC's "Elegant Pharo Code" not work?

$/ join: ($- split: '1969-07-20') reverse

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Amber and Pharo

paul-3
Because there are always differences :-)

isn't it almost equally elegant:

'/' join: ('1969-07-20' tokenize: '-' ) reversed




Am Montag, 30. November 2015 18:13:15 UTC+1 schrieb Richard Eng:
I thought Pharo was the reference implementation for Amber. Why does the following code snippet from Sven VC's "Elegant Pharo Code" not work?

$/ join: ($- split: '1969-07-20') reverse

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Amber and Pharo

Martin Bähr
Excerpts from paul's message of 2015-12-01 15:30:44 +0100:
> > I thought Pharo was the reference implementation for Amber. Why does the
> > following code snippet from Sven VC's "Elegant Pharo Code" not work?
> > $/ join: ($- split: '1969-07-20') reverse
> Because there are always differences :-)
> isn't it almost equally elegant:
> '/' join: ('1969-07-20' tokenize: '-' ) reversed

why is it that join and split are messages on the separator, and not on the
item to be split and joined?

i would have expected:

('1969-07-20' split: $-) join: $/.
or
('1969-07-20' tokenize: '-' ) join: '/'.

at least tokenize gets it right, so that is definitely more elegant :-)

greetings, martin.

--
eKita                   -   the online platform for your entire academic life
--
chief engineer                                                       eKita.co
pike programmer      pike.lysator.liu.se    caudium.net     societyserver.org
secretary                                                      beijinglug.org
mentor                                                           fossasia.org
foresight developer  foresightlinux.org                            realss.com
unix sysadmin
Martin Bähr          working in china        http://societyserver.org/mbaehr/

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Amber and Pharo

Bernat Romagosa
IMO both are ambiguous, shouldn't they be named something like #splitBy: and #joinWith: ?

2015-12-01 16:09 GMT+01:00 Martin Bähr <[hidden email]>:
Excerpts from paul's message of 2015-12-01 15:30:44 +0100:
> > I thought Pharo was the reference implementation for Amber. Why does the
> > following code snippet from Sven VC's "Elegant Pharo Code" not work?
> > $/ join: ($- split: '1969-07-20') reverse
> Because there are always differences :-)
> isn't it almost equally elegant:
> '/' join: ('1969-07-20' tokenize: '-' ) reversed

why is it that join and split are messages on the separator, and not on the
item to be split and joined?

i would have expected:

('1969-07-20' split: $-) join: $/.
or
('1969-07-20' tokenize: '-' ) join: '/'.

at least tokenize gets it right, so that is definitely more elegant :-)

greetings, martin.

--
eKita                   -   the online platform for your entire academic life
--
chief engineer                                                       eKita.co
pike programmer      pike.lysator.liu.se    caudium.net     societyserver.org
secretary                                                      beijinglug.org
mentor                                                           fossasia.org
foresight developer  foresightlinux.org                            realss.com
unix sysadmin
Martin Bähr          working in china        http://societyserver.org/mbaehr/

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
Bernat Romagosa.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Amber and Pharo

Martin Bähr
Excerpts from Bernat Romagosa's message of 2015-12-01 16:13:07 +0100:

> > > > I thought Pharo was the reference implementation for Amber. Why does
> > the
> > > > following code snippet from Sven VC's "Elegant Pharo Code" not work?
> > > > $/ join: ($- split: '1969-07-20') reverse
> > > Because there are always differences :-)
> > > isn't it almost equally elegant:
> > > '/' join: ('1969-07-20' tokenize: '-' ) reversed
> >
> > why is it that join and split are messages on the separator, and not on the
> > item to be split and joined?
> >
> > i would have expected:
> >
> > ('1969-07-20' split: $-) join: $/.
> > or
> > ('1969-07-20' tokenize: '-' ) join: '/'.
> > at least tokenize gets it right, so that is definitely more elegant :-)
>
> IMO both are ambiguous, shouldn't they be named something like #splitBy:
> and #joinWith: ?

you are of course quite right, the thought even crossed my mind while writing
the response, but i guess i am not yet deep enough into smalltalk to feel
strong enough about it.

greetings, martin.

--
eKita                   -   the online platform for your entire academic life
--
chief engineer                                                       eKita.co
pike programmer      pike.lysator.liu.se    caudium.net     societyserver.org
secretary                                                      beijinglug.org
mentor                                                           fossasia.org
foresight developer  foresightlinux.org                            realss.com
unix sysadmin
Martin Bähr          working in china        http://societyserver.org/mbaehr/

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Amber and Pharo

NorbertHartl
In reply to this post by Martin Bähr

> Am 01.12.2015 um 16:09 schrieb Martin Bähr <[hidden email]>:
>
> Excerpts from paul's message of 2015-12-01 15:30:44 +0100:
>>> I thought Pharo was the reference implementation for Amber. Why does the
>>> following code snippet from Sven VC's "Elegant Pharo Code" not work?
>>> $/ join: ($- split: '1969-07-20') reverse
>> Because there are always differences :-)
>> isn't it almost equally elegant:
>> '/' join: ('1969-07-20' tokenize: '-' ) reversed
>
> why is it that join and split are messages on the separator, and not on the
> item to be split and joined?
>
> i would have expected:
>
> ('1969-07-20' split: $-) join: $/.
> or
> ('1969-07-20' tokenize: '-' ) join: '/'.
>
> at least tokenize gets it right, so that is definitely more elegant :-)
>
A good example how we accept things being right because we are used to do it wrongly :)

A method name is like a verb. In a sentence that has a subject, a verb and an object the "subject does-something-with object". When we look at the verbs split and join then it tells who (the subject) splits/joins whom (object). Taking a second look at it you might recognize that the separator splits the string or the string is split by the separator but not the other way round. So

$/ split: '1969-07-20'

or

'1969-07-20' splitBy: $/

are right, no?

my 2 cents,

Norbert
 

> greetings, martin.
>
> --
> eKita                   -   the online platform for your entire academic life
> --
> chief engineer                                                       eKita.co
> pike programmer      pike.lysator.liu.se    caudium.net     societyserver.org
> secretary                                                      beijinglug.org
> mentor                                                           fossasia.org
> foresight developer  foresightlinux.org                            realss.com
> unix sysadmin
> Martin Bähr          working in china        http://societyserver.org/mbaehr/
>
> --
> You received this message because you are subscribed to the Google Groups "amber-lang" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Amber and Pharo

philippeback
Pharo 4.0 has this:

splitOn: splitter 
"splitter - can be a subsequence, a Block or a Regex (String receiver only).
Any other object used as a splitter is treated as an Array containing that object."
^ splitter split: self

joinUsing: joiner
"joiner - character, string or sequenceable collection
returns collection of the same collection class as 'joiner', or a String"
^ joiner join: self

So, not really doing it wrong. Basically, it calls back into the "wrong names".

BTW, didn't used this one yet:

joinUsing: joiner last: last 
"#(1 2 3 4) joinUsing: ', ' last: 'and'. => '1, 2, 3 and 4"
(self size = 0) ifTrue: [  ^ '' ].
(self size = 1) ifTrue: [  ^ self first asString ].
^ last join: (Array
with: (joiner join: self allButLast)
with: self last)

Phil


On Wed, Dec 2, 2015 at 10:35 AM, Norbert Hartl <[hidden email]> wrote:

> Am 01.12.2015 um 16:09 schrieb Martin Bähr <[hidden email]>:
>
> Excerpts from paul's message of 2015-12-01 15:30:44 +0100:
>>> I thought Pharo was the reference implementation for Amber. Why does the
>>> following code snippet from Sven VC's "Elegant Pharo Code" not work?
>>> $/ join: ($- split: '1969-07-20') reverse
>> Because there are always differences :-)
>> isn't it almost equally elegant:
>> '/' join: ('1969-07-20' tokenize: '-' ) reversed
>
> why is it that join and split are messages on the separator, and not on the
> item to be split and joined?
>
> i would have expected:
>
> ('1969-07-20' split: $-) join: $/.
> or
> ('1969-07-20' tokenize: '-' ) join: '/'.
>
> at least tokenize gets it right, so that is definitely more elegant :-)
>
A good example how we accept things being right because we are used to do it wrongly :)

A method name is like a verb. In a sentence that has a subject, a verb and an object the "subject does-something-with object". When we look at the verbs split and join then it tells who (the subject) splits/joins whom (object). Taking a second look at it you might recognize that the separator splits the string or the string is split by the separator but not the other way round. So

$/ split: '1969-07-20'

or

'1969-07-20' splitBy: $/

are right, no?

my 2 cents,

Norbert


> greetings, martin.
>
> --
> eKita                   -   the online platform for your entire academic life
> --
> chief engineer                                                       eKita.co
> pike programmer      pike.lysator.liu.se    caudium.net     societyserver.org
> secretary                                                      beijinglug.org
> mentor                                                           fossasia.org
> foresight developer  foresightlinux.org                            realss.com
> unix sysadmin
> Martin Bähr          working in china        http://societyserver.org/mbaehr/
>
> --
> You received this message because you are subscribed to the Google Groups "amber-lang" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.