Re: [Esug-list] destructDo:

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

Re: [Esug-list] destructDo:

jb
Hello Christian,

the hint to Lisp is obvious. In Clojure (a modern Lisp-Dialect) destructuring (https://clojure.org/guides/destructuring) is used a lot.

Johannes
Am 28.03.2020 um 15:23 schrieb Christian Haider <[hidden email]>:

I chose the name because of the old Lisp “destructuring-bind”. But this is more powerful, because it does tree matching. This is just shallow.
I am not sure where the concept was invented first. It may have been Lisp.
 
 
Von: Norbert Hartl <[hidden email]> 
Gesendet: Samstag, 28. März 2020 14:20
An: Mark Plas <[hidden email]>
Cc: Christian Haider <[hidden email]>; [hidden email]; [hidden email]; [hidden email]
Betreff: Re: [Esug-list] destructDo:
 
I think the name destructDo: comes from destructuring assignment. 
 
 
Norbert


Am 28.03.2020 um 14:15 schrieb Mark Plas <[hidden email]>:
 
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
 
<logomgxnew_3d44337b-2535-4d6a-9f5f-3fdd565513ca.png>
 
 
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 <[hidden email]> On Behalf Of Christian Haider
Sent: zaterdag 28 maart 2020 13:43
To: [hidden email]; [hidden email]; [hidden email]
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 list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
 
_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/amber-lang/947D670F-0596-47FD-8BF0-49539986667B%40nordakademie.de.
Reply | Threaded
Open this post in threaded view
|

Re: [Esug-list] destructDo:

Dave Mason-3
I'd just call it `destructure:` it's not really doing a `do`

../Dave


On Sat, Mar 28, 2020 at 6:23 PM Johannes Brauer <[hidden email]> wrote:
Hello Christian,

the hint to Lisp is obvious. In Clojure (a modern Lisp-Dialect) destructuring (https://clojure.org/guides/destructuring) is used a lot.

Johannes
Am 28.03.2020 um 15:23 schrieb Christian Haider <[hidden email]>:

I chose the name because of the old Lisp “destructuring-bind”. But this is more powerful, because it does tree matching. This is just shallow.
I am not sure where the concept was invented first. It may have been Lisp.
 
 
Von: Norbert Hartl <[hidden email]> 
Gesendet: Samstag, 28. März 2020 14:20
An: Mark Plas <[hidden email]>
Cc: Christian Haider <[hidden email]>; [hidden email]; [hidden email]; [hidden email]
Betreff: Re: [Esug-list] destructDo:
 
I think the name destructDo: comes from destructuring assignment. 
 
 
Norbert


Am 28.03.2020 um 14:15 schrieb Mark Plas <[hidden email]>:
 
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
 
<logomgxnew_3d44337b-2535-4d6a-9f5f-3fdd565513ca.png>
 
 
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 <[hidden email]> On Behalf Of Christian Haider
Sent: zaterdag 28 maart 2020 13:43
To: [hidden email]; [hidden email]; [hidden email]
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 list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
 
_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/amber-lang/947D670F-0596-47FD-8BF0-49539986667B%40nordakademie.de.

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/amber-lang/CAL1GWxhj3USt4_A%3Dv_bcSU6PZHSRysNX1wUMMgOH46mC%3DfchGw%40mail.gmail.com.