Yes, that would be nice. Unfortunately a bit more involved than this 1-liner…
Von: Esug-list <esug-list-bounces@lists.esug.org> Im Auftrag von Christophe Dony
Gesendet: Samstag, 28. M�rz 2020 15:17
An: esug-list@lists.esug.org
Betreff: Re: [Esug-list] destructDo:
Hi.
I like tupleDo:
or matchDo:
and what about installing a full pattern matching, as in many languages e.g. Scheme : https://docs.racket-lang.org/reference/match.html
#(1 #(2 3 6 7) 4) matchDo: [:a (:b :@c) :d] | …]
here c would be #(3 6 7)
may be it already exist?
if not, would really be a +
Christophe
Le 28/03/2020 � 14:15, Mark Plas a �crit :
Hello Christian,
" I don’t really like the name,"
Maybe you could call it #tupleDo:?
#(1 2 3) tupleDo: [:a :b :c | …]
Mark
Mark Plas
Software Engineer
T +32 2 467 34 30
This e-mail and any files attached to it are confidential and intended only for the use of the individuals or entity to whom they are addressed. If you have received this e-mail in error, please notify the sender immediately.
From: Esug-list <esug-list-bounces@lists.esug.org> On Behalf Of Christian Haider
Sent: zaterdag 28 maart 2020 13:43
To: vwnc@cs.uiuc.edu; esug-list@lists.esug.org; amber-lang@googlegroups.com
Subject: [Esug-list] destructDo:
Hi,
I am using a nice little method #destructDo: for a while now and it feels good.
In VisualWorks:
SequenceableCollection>>destructDo: aBlock
"Evaluate aBlock with the receiver's elements as parameters.
aBlock takes its arguments from the receiver.
'ok'
#(1 2 3) destructDo: [:a :b :c | a + b + c]
#(1 2 3) destructDo: [:a :b | a + b]
#(1 2 3) destructDo: [:a | a]
#(1 2 3) destructDo: [42]
'not ok'
#(1 2 3) destructDo: [:a :b :c :d | a + b + c + d]
"
^aBlock cullWithArguments: self asArray
In Amber:
SequenceableCollection>>destructDo: aBlock
^aBlock valueWithPossibleArguments: self
In Pharo and other dialects, I don’t know, but should be as easy.
For example you can do
(('2020-03-28' tokensBasedOn: $-) collect: #asNumber) destructDo: [:year :month :day |
Date newDay: day monthNumber: month year: year]
I like that the block is not the receiver (like with #valueWithArguments or #cullWithArguments), but the last argument.
Now the questions:
- I am sure that others came up with this. Anybody knows?
- What are you using for this pattern?
- I don’t really like the name, but haven’t found anything better yet. Maybe #destructedDo: or just #destructed: or: #withPartsDo:… maybe something shorter? Ideas?
- What are you thinking about this?
Happy hacking,
Christian
_______________________________________________Esug-list mailing listEsug-list@lists.esug.orghttp://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org