From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c406e0c4a6eb74ed X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!feed2.news.rcn.net!rcn!feed3.news.rcn.net!not-for-mail Sender: jsa@rigel.goldenthreadtech.com Newsgroups: comp.lang.ada Subject: Re: ADA Popularity Discussion Request References: <49dc98cf.0408110556.18ae7df@posting.google.com> <1093634083.931713@master.nyc.kbcfp.com> From: jayessay Organization: Tangible Date: 29 Aug 2004 12:14:39 -0400 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: DXC=2Pe8>?07C4jdePdd<;jV^n0R]m=BkYWIg:6bU3OT9S9jC6d49m?CIBlLjhDjIjS^>a?Gj[P`nL>je X-Complaints-To: abuse@rcn.com Xref: g2news1.google.com comp.lang.ada:3143 Date: 2004-08-29T12:14:39-04:00 List-Id: Kevin Cline wrote: > Hyman Rosen wrote in message > news:<1093634083.931713@master.nyc.kbcfp.com>... >> >> No fair picking an easy one. Suppose you have a vector of complex >> numbers and want to set the real part of each to zero. That's far >> from a one liner in C++ even though it's conceptually trivial. > > With boost::lambda, it would be a one liner: > for_each(v.begin(), v.end(), _1.r = 0); Why not just use the real thing (instead of a pale emasculated hack) (map 'vec (lambda (c) (complex 0 (imagpart c))) v) Actually it's simple to be more flexible: (defun zero-realpart (vec &optional (type (type-of vec))) (map type (lambda (c) (complex 0 (imagpart c))) vec)) (let ((vc1 (vector #c(1 2) #c(2 3) #c(1/3 4.5)))) (zero-realpart vc1)) ==> #(#c(0 2) #c(0 3) #c(0.0 4.5)) (let ((vc1 (list #c(1 2) #c(2 3) #c(1/3 4.5)))) (zero-realpart vc1)) ==> (#c(0 2) #c(0 3) #c(0.0 4.5)) (let ((vc1 (list #c(1 2) #c(2 3) #c(1/3 4.5)))) (zero-realpart vc1 'vector)) ==> #(#c(0 2) #c(0 3) #c(0.0 4.5)) It wouldn't take much to generalize this to be much more flexible and generic while still generating optimal code. /Jon -- 'jay' - a n t h o n y at romeo/november/charley com