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,3413256b2f4bedfc X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!local01.nntp.dca.giganews.com!nntp.rcn.net!news.rcn.net.POSTED!not-for-mail NNTP-Posting-Date: Fri, 19 Aug 2005 10:34:34 -0500 Sender: jsa@rigel.goldenthreadtech.com Newsgroups: comp.lang.ada Subject: Re: OT: What was the first programming language to use 'generics'?... References: <43045094_1@glkas0286.greenlnk.net> From: jayessay Organization: Tangible Date: 19 Aug 2005 11:42:07 -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 NNTP-Posting-Host: 209.6.25.79 X-Trace: sv3-ol2zTkKYUdeDNh1NVF8WFzgT0qAiNv91JHuISjf/q1B0DcY/+DLzcpwlGkddzjgCP/CqQClVMJKnhe3!rcaydOZs6vk+L0xStkq9LG+lCljT2yB7DHErMyUx9gNz3MGkkzfZPRMGPunSDPS1LIf/xT6Tr41j X-Complaints-To: abuse@rcn.net X-DMCA-Complaints-To: abuse@rcn.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:4191 Date: 2005-08-19T11:42:07-04:00 List-Id: Robert A Duff writes: > David Trudgett writes: > > > "Martin Dowie" writes: > > > > > ...and were they called 'generics'? > > > > > > Not Ada but I just know /someone/ here will know this! ;-) > > > > > > > > > > Probably (given I'm not a language historian) Lisp code macros were > > the first, except for a couple of provisos: (a) Lisp never had the > > strong static typing that Ada has, so Lisp macros weren't invented to > > solve the same problem as Ada generics; and (b) Lisp macros are more > > general than Ada generics in the sense that they allow essentially > > arbitrary code (not text) generation (every Ada programmer's > > nightmare? ;-)). > > An important difference between Ada's generics and most macro systems Apropos to the actual thread title, I don't think Lisp macros are much of anything like "generics" as the term is typically used, because while they can act as templates for simple cases, that is a small part of what they do. > is: what should names in the template refer to. The distinctions here are harder to apply in the Lisp case, but it may be interesting to look a bit more. > If it refers to a formal parameter in the template, it refers to the > actual parameter in the instance. This is the easier of the two. The most typical case in Lisp, would adhere to this as well: (defmacro hi (a) `(format nil "Hello there object ~A" ,a)) The backquote comma form is a shorthand for creating a template, so this very simple example is indeed a code template. The backquote says to copy things verbatim except for "escaped" things (which the comma does). A call could be (hi 1) ==> "Hello there object 1" The expansion is just what you would think: (FORMAT NIL "Hello there object ~A" 1) (hi 'A) ==> "Hello there object A" Expansion: (FORMAT NIL "Hello there object ~A" 'A) However, this typical _use_ of parameters is not required or even what you want to do in many cases. Those cases are where the parameter(s) may control the expansion process. For example, (defmacro foo (key) (let ((type-of-key (type-of key))) (if (eq key :one) `(identity '(One is the first counting number)) `(identity '(the type of the KEY argument is ,type-of-key))))) (foo :one) ==> (one is the first counting number) Expansion: (identity '(one is the first counting number)) (foo :two) ==> (the type of the key argument is symbol) Expansion: (identity '(the type of the key argument is symbol)) As you can see, the KEY parameter does not show up in either the output (as its value) or the expansion code (as itself). > If a name in the template refers to something local to the > template, it refers to the copy of that thing in the instance. If you look at the foo macro and its expansion a bit, you can also see there are things ("names") in the "template" (expander code) which do not show up at all in the "instance" (expansion). For example, the LET, IF, etc are all gone. There are other things which do behave in this fashion, for example, IDENTITY. > If it refers to neither, what should it refer to? To something > visible at the place of the template, or something visible at the > place of the instance? The Ada answer is: at the place of the > template. The usual macro answer is: at the place of the instance. In the case of Lisp, the answer is it refers to _expander code_ and it doesn't exist (let alone being visible) at either noted place. It exists in the macro function: (symbol-function 'foo) ==> # It's this last bit, that a Lisp macro is really a function (like any other, except that it runs at a special time), able to make use of any resources available in the base language, 3rd party libs, your own code and the macros lexical and expansion time environment, that makes Lisp macros so completely different from templates, parameterized code/types, generics, and other "macros". > Some Lisp dialects have "hygienic macros", which are a lot more like Ada > generics in this regard. You're probably thinking of Scheme (syntax-case) or maybe Dylan here. I'd say they are somewhat more like generics/templates. /Jon -- 'j' - a n t h o n y at romeo/charley/november com