From: David Trudgett <wpower@zeta.org.au.nospamplease>
Subject: Re: OT: What was the first programming language to use 'generics'?...
Date: Fri, 19 Aug 2005 07:11:08 +1000
Date: 2005-08-19T07:11:08+10:00 [thread overview]
Message-ID: <m34q9nymqb.fsf@rr.trudgett> (raw)
In-Reply-To: 43045094_1@glkas0286.greenlnk.net
"Martin Dowie" <martin.dowie@baesystems.com> 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? ;-)).
I'm only a Lisp learner myself (same as I'm learning Ada), but for
those who may be interested, the following is a very simple example of
a template style macro in Common Lisp (lifted from Peter Herth's LTk
package):
(defmacro with-ltk (&rest body)
`(let ((*wish* nil)
(ltk::*callbacks* (make-hash-table :test #'equal))
(ltk::*counter* 1)
(ltk::*event-queue* nil))
(start-wish)
,@body
(mainloop)))
This defines a macro called 'with-ltk' that takes a list of parameters
which it collectively (in this case) refers to as 'body'. The rest is
a code template (introduced by the backtick), into which the arguments
to 'with-ltk' are inserted (the ',@body' business). So, 'with-ltk' is
essentially just a simple code wrapper, and therefore not a
particularly fascinating example.
With this macro facility, the programmer can write a simple (or not!)
piece of code which generates different "parse trees" (I believe
that's the terminology) according to the context, for a similar effect
to Ada generics, which result in the generation of varying object code
according to context.
David
--
David Trudgett
http://www.zeta.org.au/~wpower/
As a computer, I find your faith in technology amusing.
next prev parent reply other threads:[~2005-08-18 21:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-18 9:18 OT: What was the first programming language to use 'generics'? Martin Dowie
2005-08-18 11:29 ` Jean-Pierre Rosen
2005-08-19 16:25 ` Charles Lindsey
2005-08-18 21:11 ` David Trudgett [this message]
2005-08-18 21:36 ` Robert A Duff
2005-08-18 23:43 ` David Trudgett
2005-08-19 2:13 ` OT: What was the first programming language to use Larry Kilgallen
2005-08-19 9:44 ` David Trudgett
2005-08-19 14:22 ` jayessay
2005-08-19 15:08 ` OT: What was the first programming language to use 'generics'? Robert A Duff
2005-08-19 18:09 ` jayessay
2005-08-19 15:42 ` jayessay
2005-08-19 2:47 ` Jeffrey R. Carter
2005-08-21 17:33 ` adaworks
[not found] ` <odeig19vmplnbt67s3s148eb4mqrk9vujd@4ax.com>
2005-08-23 7:03 ` adaworks
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox