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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fc52c633190162e0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!out02a.usenetserver.com!news.usenetserver.com!in02.usenetserver.com!news.usenetserver.com!cycny01.gnilink.net!spamkiller2.gnilink.net!gnilink.net!trndny05.POSTED!0e8a908a!not-for-mail From: Hyman Rosen User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: why learn C? References: <1172144043.746296.44680@m58g2000cwm.googlegroups.com> <1172161751.573558.24140@h3g2000cwc.googlegroups.com> <546qkhF1tr7dtU1@mid.individual.net> <5ZULh.48$YL5.40@newssvr29.news.prodigy.net> <1175215906.645110.217810@e65g2000hsc.googlegroups.com> <1175230700.925143.28490@n59g2000hsh.googlegroups.com> <1btkgzzj6zimp.acsq8mkzqz1w$.dlg@40tude.net> <1175488143.324741.283480@y80g2000hsf.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <9l1Rh.7648$%G4.3596@trndny05> Date: Thu, 05 Apr 2007 07:14:13 GMT NNTP-Posting-Host: 70.19.99.182 X-Complaints-To: abuse@verizon.net X-Trace: trndny05 1175757253 70.19.99.182 (Thu, 05 Apr 2007 03:14:13 EDT) NNTP-Posting-Date: Thu, 05 Apr 2007 03:14:13 EDT Xref: g2news1.google.com comp.lang.ada:14791 Date: 2007-04-05T07:14:13+00:00 List-Id: jayessay wrote: > C++ templates, other than being Turing complete, have absolutely nothing > to do with Lisp or Lisp like languages. Nothing. And to think otherwise > shows a complete ignorance of the matter. Sorry, I'm afraid you're wrong about that. In fact, many C++ template metaprograms use techniques that would be quite familiar to Lisp users. For example, one might build up type lists as follows: struct Nil { }; template struct Cons { typedef T1 Car; typedef T2 Cdr; }; typedef Cons > > my3types; my3types::Car an_int; my3types::Cdr::Car a_bool; my3types::Cdr::Cdr::Car a_float; > Allow a user/programmer to define a dictionary like object while > ensuring at _compile_ time that the size of the table implementing it > is a prime number. > > That's something that is easy to do in Lisp. It is at least > theoretically possible (if mind numbingly painful) to achieve with C++ > templates. It's actually quite easy with templates, although the following may hit compiler limits that a better algorithm would avoid. It takes just three lines to implement straightforwardly the definition that a prime number has exactly two divisors. template struct divNleK { enum { v = ((N % K) == 0) + divNleK::v }; }; template struct divNleK { enum { v = 1 }; }; template struct prime_test { enum { v = divNleK::v == 2 }; }; > That wouldn't be so bad (or even such a big deal), but C++ templates > are nothing like this and are in general a clumsy giant PITA. I don't agree at all.