comp.lang.ada
 help / color / mirror / Atom feed
* is there a FAQ?
@ 1998-05-13  0:00 Cristian Libardo
  1998-05-13  0:00 ` Markus Kuhn
  0 siblings, 1 reply; 8+ messages in thread
From: Cristian Libardo @ 1998-05-13  0:00 UTC (permalink / raw)



if so... where?

Ciao
  Cristian
-- 
"Det är bara den medelmåttige som alltid presterar sitt bästa."




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: is there a FAQ?
  1998-05-13  0:00 is there a FAQ? Cristian Libardo
@ 1998-05-13  0:00 ` Markus Kuhn
  1998-05-15  0:00   ` Johann Hibschman
  0 siblings, 1 reply; 8+ messages in thread
From: Markus Kuhn @ 1998-05-13  0:00 UTC (permalink / raw)



To get started:

http://www.cl.cam.ac.uk/~mgk25/ada.html
http://www.adahome.com/
http://www.adahome.com/FAQ/comp-lang-ada.html
http://wuarchive.wustl.edu/languages/ada/
http://sw-eng.falls-church.va.us/AdaIC/

Markus

-- 
Markus G. Kuhn, Security Group, Computer Lab, Cambridge University, UK
email: mkuhn at acm.org,  home page: <http://www.cl.cam.ac.uk/~mgk25/>




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: is there a FAQ?
  1998-05-13  0:00 ` Markus Kuhn
@ 1998-05-15  0:00   ` Johann Hibschman
  1998-05-15  0:00     ` Markus Kuhn
  0 siblings, 1 reply; 8+ messages in thread
From: Johann Hibschman @ 1998-05-15  0:00 UTC (permalink / raw)



Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk> writes:

> To get started:

[links snipped]

I'm also just looking into Ada.  I tried reading the FAQ, but I
couldn't find a could very basic questions answered.  Does Ada support
functional programming and closures?  I'm a bit of a language
hobbyist, and I've become quite addicted to easy temporary function
creation for mapping/reduce/etc uses.

Is there a (convenient) way to write

(map-into out-vector
          #'(lambda (x y) (+ x (sqrt y)))
          vector1 vector2)

as I would in Common Lisp?  (Or, with slight syntax changes, in ML?)

Sather iterators do this fairly well, but they're still a little
inconvenient.

From what I see, Ada has much better array syntax support, which means
I wouldn't have to write it myself, as I would have to in CL.  I'm
surprised that I'm having trouble finding an answer to this question;
it seems so basic.

- Johann




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: is there a FAQ?
  1998-05-15  0:00   ` Johann Hibschman
@ 1998-05-15  0:00     ` Markus Kuhn
  0 siblings, 0 replies; 8+ messages in thread
From: Markus Kuhn @ 1998-05-15  0:00 UTC (permalink / raw)



Johann Hibschman wrote:
> I'm also just looking into Ada.  I tried reading the FAQ, but I
> couldn't find a could very basic questions answered.  Does Ada support
> functional programming and closures?

No, Ada is clearly not a functional programming language. It
supports references to functions as parameters, but it has otherwise
very little in common with functional programming languages.
Ada is supporting the procedural, data abstraction, object orientation
styles, in the tradition of languages like Algol, Pascal,
Modula II, C, C++, Java. It is not in any way related to
functional languages like Scheme, ML, Haskell, Miranda, DSSSL,
etc. Unlike C and Algol, Ada does not even have conditions in
expressions (A := if B then C else D), as those were considered
to lead to unreadable code too easily.

> I'm a bit of a language
> hobbyist, and I've become quite addicted to easy temporary function
> creation for mapping/reduce/etc uses.

You can't create an unnamed function, often not even an unnamed
type in Ada.

> Is there a (convenient) way to write
> 
> (map-into out-vector
>           #'(lambda (x y) (+ x (sqrt y)))
>           vector1 vector2)
> 
> as I would in Common Lisp?  (Or, with slight syntax changes, in ML?)

You have nested functions in Ada, so creating a small function
close to the place where you use it (inside a declare block)
is not too inconvenient, and frequently used.

Markus

-- 
Markus G. Kuhn, Security Group, Computer Lab, Cambridge University, UK
email: mkuhn at acm.org,  home page: <http://www.cl.cam.ac.uk/~mgk25/>




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: is there a FAQ?
@ 1998-05-15  0:00 adam
  1998-05-15  0:00 ` Brian Rogoff
  0 siblings, 1 reply; 8+ messages in thread
From: adam @ 1998-05-15  0:00 UTC (permalink / raw)



Johann Hibschman wrote:
>
> I'm also just looking into Ada.  I tried reading the FAQ, but I
> couldn't find a could very basic questions answered.  Does Ada support
> functional programming and closures?  I'm a bit of a language
> hobbyist, and I've become quite addicted to easy temporary function
> creation for mapping/reduce/etc uses.
>
> Is there a (convenient) way to write
>
> (map-into out-vector
>           #'(lambda (x y) (+ x (sqrt y)))
>           vector1 vector2)
>
> as I would in Common Lisp?  (Or, with slight syntax changes, in ML?)

I don't really know what "map-into" does; in my hazy recollection, I
only remember something like "mapcar", which takes a lambda-function
and one or more input lists and returns an output list.  I assume that
"map-into" does something similar.

Ada doesn't have a built-in mapping routine, but it's pretty easy to
create one.  I'll assume that a "vector" is implemented as an array.

    generic
        type ELEMENT_TYPE is private;
        type INDEX is (<>);
        type ARRAY_TYPE is array (INDEX range <>) of ELEMENT_TYPE;
        with function MAP_FUNCTION (Left, Right : ELEMENT_TYPE)
                 return ELEMENT_TYPE;

    procedure Generic_Map (Input_1, Input_2 : in ARRAY_TYPE;
                           Result           : out ARRAY_TYPE);

    procedure Generic_Map (Input_1, Input_2 : in ARRAY_TYPE;
                           Result           : out ARRAY_TYPE) is
    begin
        for I in Input_1'range loop
            Result (I) := MAP_FUNCTION (Input_1 (I), Input_2 (I));
        end loop;
    end Generic_Map;

I've made the assumption that Input_1, Input_2, and Result all have
the same bounds.  In real life, you'd probably want to check that
yourself.

Now, to use the Map procedure, we just have to tell it about our
element type, our array type, and what mapping function we plan to
use:

    procedure Demonstrate is
        type Float_Array is array (Integer range <>) of Float;
        Array_1, Array_2, Array_3 : Float_Array (1 .. 10);

        function My_Function (X, Y : Float) return Float;

        procedure Map_My_Function is new Generic_Map
            (ELEMENT_TYPE => Float,
             INDEX        => Integer,
             ARRAY_TYPE   => Float_Array,
             MAP_FUNCTION => My_Function);

        function My_Function (X, Y : Float) return Float is
        begin
            return X + Sqrt (Y);
        end My_Function;

    begin
        ......
        Map_My_Function (Array_1, Array_2, Array_3);
    end Demonstrate;

A little more verbose than Common Lisp, but not that much, really.  No
more than you'd expect for a strongly typed language.

Hope this helps,
                                -- Adam

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: is there a FAQ?
  1998-05-15  0:00 adam
@ 1998-05-15  0:00 ` Brian Rogoff
       [not found]   ` <Et0xrx.798@world.std.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Brian Rogoff @ 1998-05-15  0:00 UTC (permalink / raw)



On Fri, 15 May 1998 adam@irvine.com wrote:
> Johann Hibschman wrote:
> > Is there a (convenient) way to write
> >
> > (map-into out-vector
> >           #'(lambda (x y) (+ x (sqrt y)))
> >           vector1 vector2)
> >
> > as I would in Common Lisp?  (Or, with slight syntax changes, in ML?)
>
> ... snip ...
> 
> A little more verbose than Common Lisp, but not that much, really.  No
> more than you'd expect for a strongly typed language.

Actually, ML is quite strongly typed, and does mapping just as concisely
as Common Lisp. The distinction is that ML is not *explicitly* typed, like 
Ada; the most general type is inferred and so you don't have to spell
everything out, or instantiate generic functions. Lots of "researchy"
languages do this. 

I found your Ada more than "a little more verbose" than the comparable
code in ML or Haskell. Its clear that this is not so for all problems
however, and sometimes that verbosity is a win. 

-- Brian







^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: is there a FAQ?
       [not found]   ` <Et0xrx.798@world.std.com>
  1998-05-16  0:00     ` Fergus Henderson
@ 1998-05-16  0:00     ` Brian Rogoff
  1 sibling, 0 replies; 8+ messages in thread
From: Brian Rogoff @ 1998-05-16  0:00 UTC (permalink / raw)



On Sat, 16 May 1998, Robert A Duff wrote:
> Type inference seems like a nice thing locally, within a single
> subroutine, but it seems to me that the interface (to a subroutine, or
> package, &c) should be written out explicitly.

Interfaces are written out explicitly in the ML signatures. From the OCAML 
docs 

module type PRIOQUEUE =
    sig
      type priority = int         
      type 'a queue               
      val empty : 'a queue
      val insert : 'a queue -> int -> 'a -> 'a queue
      val extract : 'a queue -> int * 'a * 'a queue
      exception Queue_is_empty
    end;;

spells out the interface clearly if you read a bit of ML ('a is a type 
variable and can stand for a type, 'a queue is a queue of 'a, int -> real 
is a functio mapping ints to reals, and * constructs tuples). In a way its
more explicit than Ada (exceptions are part of the signature) and in a way 
less, as I can't restrict the priorities to some range. SML is similar. 

The biggest problems with these schemes IMO are the lack of human
engineering in the error reporting and the difficulty of integrating 
useful overloading (so called ad-hoc polymorphism, Ada's forte) with type
inference.  The first is a matter of sweat and time, the second may be too
hard.*

-- Brian

(* I know about multi-parameter type classes in Gofer/Haskell. If people
   are still as convinced in 5 years... )







^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: is there a FAQ?
       [not found]   ` <Et0xrx.798@world.std.com>
@ 1998-05-16  0:00     ` Fergus Henderson
  1998-05-16  0:00     ` Brian Rogoff
  1 sibling, 0 replies; 8+ messages in thread
From: Fergus Henderson @ 1998-05-16  0:00 UTC (permalink / raw)



robertduff@world.std.com (Robert A Duff) writes:

>Brian Rogoff  <bpr@shell5.ba.best.com> wrote:
>>Actually, ML is quite strongly typed, and does mapping just as concisely
>>as Common Lisp. The distinction is that ML is not *explicitly* typed, like 
>>Ada; the most general type is inferred and so you don't have to spell
>>everything out, or instantiate generic functions. Lots of "researchy"
>>languages do this. 
>
>Type inference seems like a nice thing locally, within a single
>subroutine, but it seems to me that the interface (to a subroutine, or
>package, &c) should be written out explicitly.

Yes, I agree.  We came to a similar design decision in the design of
Mercury.  Mercury supports type inference for local variables and for
local procedures but requires that types for procedures exported from a
module be declared explicitly.

--
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3        |     -- the last words of T. S. Garp.




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1998-05-16  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-13  0:00 is there a FAQ? Cristian Libardo
1998-05-13  0:00 ` Markus Kuhn
1998-05-15  0:00   ` Johann Hibschman
1998-05-15  0:00     ` Markus Kuhn
  -- strict thread matches above, loose matches on Subject: below --
1998-05-15  0:00 adam
1998-05-15  0:00 ` Brian Rogoff
     [not found]   ` <Et0xrx.798@world.std.com>
1998-05-16  0:00     ` Fergus Henderson
1998-05-16  0:00     ` Brian Rogoff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox