From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: luser- -droog Newsgroups: gmane.emacs.help Subject: Re: GURU NEEDED : macro SQUARE(x) for any type x Date: Fri, 14 Jan 2011 01:04:02 -0800 (PST) Organization: http://groups.google.com Message-ID: <350732e2-363b-457d-b20d-6f248eb3ae90@32g2000yqz.googlegroups.com> References: <2ed1ceee-dac4-43b2-bbdb-72e8db2bf482@b25g2000vbz.googlegroups.com> <079c3f10-9328-407e-aca3-78c8044cfafa@w17g2000yqh.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1294998123 21630 80.91.229.12 (14 Jan 2011 09:42:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 14 Jan 2011 09:42:03 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jan 14 10:41:57 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PdgAP-0004Jk-44 for geh-help-gnu-emacs@m.gmane.org; Fri, 14 Jan 2011 10:41:57 +0100 Original-Received: from localhost ([127.0.0.1]:43236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdgAO-0000In-EK for geh-help-gnu-emacs@m.gmane.org; Fri, 14 Jan 2011 04:41:56 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!32g2000yqz.googlegroups.com!not-for-mail Original-Newsgroups: comp.lang.c,comp.lang.c++,gnu.emacs.help Original-Lines: 48 Original-NNTP-Posting-Host: 99.160.254.3 Original-X-Trace: posting.google.com 1294995842 3531 127.0.0.1 (14 Jan 2011 09:04:02 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 14 Jan 2011 09:04:02 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 32g2000yqz.googlegroups.com; posting-host=99.160.254.3; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.9.0.19) Gecko/2010072023 Iceweasel/3.0.6 (Debian-3.0.6-3),gzip(gfe) Original-Xref: usenet.stanford.edu comp.lang.c:990947 comp.lang.c++:1053368 gnu.emacs.help:184269 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:78443 Archived-At: On Jan 14, 2:14=A0am, Hans Vlems wrote: > On 14 jan, 08:15, luser- -droog wrote: > > > > > On Jan 14, 12:46=A0am, bolega wrote: > > > > Basically, I have spent a few hours experimenting and searching on th= e > > > comp.lang.c/c++ > > > > Let me use SQR for brevity and saving line > > > > Here are progressively refined macros : > > > > #define SQR(x) ((x)*(x)) > > > > #define SQR(x) ({typedef xtype=3Dx; xtype xval=3Dx; xval*xval}) =A0//= NOTE, > > > closure or {} inside () is a valid idea in C, and thus no return is > > > needed. > > > > this macro is given in several posts like > > > >http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/38ef2.= .. > > > > there is a problem with typedef > > > > Bolega > > > OIK > > > #define SQR(x) pow((x),2) > > or > > #define SQR(x) exp(2 * log(x))- Tekst uit oorspronkelijk bericht niet w= eergeven - > > > - Tekst uit oorspronkelijk bericht weergeven - > > What happens for x=3D0 in the second example? Rats! And you can't do a ternary 'cause you'd have to mention x twice. But that would be a penalty in lisp, too wouldn't it? An expression with a side-effect would perform the side-effect twice, right?