Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dynamic Typing in Ada

20 views
Skip to first unread message

Mike Linnig

unread,
Mar 10, 1989, 11:49:27 AM3/10/89
to
John Gateley's (Gat...@tilde.csc.ti.com) challenge was to implement the
following lisp construct in Ada...

----------------------------------------------------------------------
-- Scheme CL
-- (define print (defun print (x)
-- (lambda (x) (typecase x
-- (cond (integer 1)
-- ((integer? x) 1) (real 2)
-- ((real? x) 2) (complex 3)
-- ((complex? x) 3) (vector 4)))
-- ((vector? x) 4))))
----------------------------------------------------------------------
package dynamic_types is

TYPE real IS NEW integer; -- not how we would really do it
TYPE complex IS NEW integer; -- but good enuf for an example.
TYPE vector IS NEW integer;

Type Dynamic_Type_options is (integer_t,real_t,complex_t,vector_t);

type Dynamic_Type(which: Dynamic_Type_options := integer_t) IS record
CASE which IS
WHEN integer_t => I: integer;
WHEN real_t => R: real;
WHEN complex_t => C: complex;
WHEN vector_t => V: vector;
END CASE;
END RECORD;

FUNCTION print(x: Dynamic_Type) return integer;
END dynamic_types;
----------------------------------------------------------------------
WITH text_io;
PACKAGE BODY dynamic_types IS

FUNCTION print(x: Dynamic_Type) return integer is
BEGIN
CASE x.which IS
WHEN integer_t => return (1);
WHEN real_t => return (2);
WHEN complex_t => return (3);
WHEN vector_t => return (4);
END CASE;
END print;

END Dynamic_Types;
----------------------------------------------------------------------
WITH dynamic_types,text_io;
USE dynamic_types;

PROCEDURE lisp_test IS
PACKAGE int_io IS NEW text_io.integer_io(integer); -- I hate this.

tmp1 : dynamic_type := (which=>real_t, r=> 3); -- init to real type

BEGIN
text_io.put("the type number of tmp1 is :");
int_io.put(print(tmp1));
text_io.new_line;

tmp1 := (which=>complex_t, c => 99);

text_io.put("the NEW type number of tmp1 is :");
int_io.put(print(tmp1));
text_io.new_line;

END lisp_test;
----------------------- SAMPLE OUTPUT ---------------------------
the type number of tmp1 is : 2
the NEW type number of tmp1 is : 3
----------------------------------------------------------------------

I think this answers John Gateley's (Gat...@tilde.csc.ti.com) dynamic
typing challenge. I didn't understand the first challenge; if it involved
something similar to The C Language construct allowing pointers to
procedures (and calling them) that can be handled too.

Mike Linnig,
Texas Instruments

Geez, we work for the same company!

Som Hane

unread,
Mar 19, 1989, 4:52:24 PM3/19/89
to
In article <890310170...@ti.com> lin...@skvax1.csc.ti.com (Mike Linnig) writes:

>John Gateley's (Gat...@tilde.csc.ti.com) challenge was to implement the
>following lisp construct in Ada...
>
> ----------------------------------------------------------------------
>-- Scheme CL
>-- (define print (defun print (x)
>-- (lambda (x) (typecase x
>-- (cond (integer 1)
>-- ((integer? x) 1) (real 2)
>-- ((real? x) 2) (complex 3)
>-- ((complex? x) 3) (vector 4)))
>-- ((vector? x) 4))))
> ----------------------------------------------------------------------
>package dynamic_types is
>

> [ Ada code deleted ]


>
>I think this answers John Gateley's (Gat...@tilde.csc.ti.com) dynamic
>typing challenge. I didn't understand the first challenge; if it involved
>something similar to The C Language construct allowing pointers to
>procedures (and calling them) that can be handled too.
>

Let me start off by saying that I am a Lisp ( and C ) programmer, and have
only been doing Ada for 1 year, so I may be totally off base, but... I
think you may have missed the point. In the CL example above the type of
"x" could be set or changed dynamically; in your Ada example it was ( and
had to be ? ) set at compile time. In addition, in the CL example the range
of choices in the typecase itself could be modified dynamically to be the
members of an arbitrary set of types ( some of which could themselves have
been dynamically created ). I do not see at all how your example can be
modified to do any of these things... so I think the challenge has not been
met.

Mark Reynolds

...!BBN.COM!bbn!aoa!mark
mark%aoa....@BBN.COM

Scott Moody

unread,
Mar 24, 1989, 1:42:43 PM3/24/89
to
I think the real issue is not to make Ada into something it
isn't. It isn't the greatest dynamic prototyping language,
but can still be used to prototype.
Aside from the Ada Guru test of providing in Ada similar
dynamic capabilities that other languages offer, I think we
are missing the real issue of "design" and "requirements".

Once the prototyper has developed a nifty lisp/smalltalk/ai program, take the
"design/requirements" that the prototype generated
and code it up in your favorite type safe language (Ada).
A "design/requirements" shouldn't rely on dynamic typing
(but an implementation may use these feature especially in a prototype).

-- Scott Moody

0 new messages