comp.lang.ada
 help / color / mirror / Atom feed
* ForTran-Ada + flamette + question
@ 1986-05-21  6:06 larry
  1986-05-21 15:41 ` Mark Biggar
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: larry @ 1986-05-21  6:06 UTC (permalink / raw)


>  I for one am getting a little tired of short, nasty, replies from 
>  "real-annoyed-sender"s who pull the reply trigger before they stop....

Me too.

The biggest difference is that you can use subprogram names as parameters 
to subprograms in ForTran and you can't in Ada.  This is causing me major
problems in porting EMACS (written in C) to Ada.  An important feature of 
EMACS is the ability to do run-time rebinding of functions to key-strokes
and I haven't figured out how to do this in Ada.

In C one can build an array of records, each record containing a pointer 
to a function and the string of characters used to invoke the function.  
When that string is intercepted from the keyboard, the matching function
is invoked.

With this to build on it's fairly easy to create a macro facility, and even 
a subset programming language so that users can extend the editor command 
set.

Anyone have an idea how to do run-time binding of keys to commands in Ada?

                                                    Larry @ jpl-vlsi.arpa

^ permalink raw reply	[flat|nested] 14+ messages in thread
[parent not found: <175155@QZCOM>]
* Re: ForTran-Ada + flamette + question
@ 1986-05-28 15:54 richw
  1986-05-30 12:46 ` Russ Holden
  0 siblings, 1 reply; 14+ messages in thread
From: richw @ 1986-05-28 15:54 UTC (permalink / raw)



The following includes a suggestion for solving your problem, along
with my own defense of the decision to omit procedure-pointers from Ada:

The first solution I can think of (and, I guess, the simplest?) would
be to define an enumeration type, where each enumeral (is that a
word?) corresponds to one of the functions you'd like to bind to a
key-sequence.  Then just write a procedure that takes such an enumeral
as an "in" parameter and then "case"s on that parameter to the
appropriate call.

Abstractly, this new function is similar to "eval" in Lisp.  Now, instead
of binding characters sequences to function-pointers (as in C), just bind
the character sequences to enumerals.

Other comments about why I think the ability to pass procedures around
was omitted from Ada: (note that these are just opinions -- I'm not
quoting one of the design documents for Ada or anything like that)

In a language like Lisp, you can actually create procedures AT RUN-TIME
since they're just lists (i.e. data).  However, in C and Ada this isn't
true.  In C, all procedures that you can point to at run-time are defined
at compile time.  I think this last fact is an important one to consider;
the above method of mapping enumerals to subprogram calls works for Ada.
It wouldn't work in Lisp because you can't list all of the subprograms
that will exist when you run the program BEFORE you run it (because you
can build Lisp procedures "on the fly"); thus, you can't define an
enumeration type since that type has a finite number of compile-time
enumerals.

Anyway, my point is that I think that one can do all that you can do in
C in Ada by using the above enumerals-to-subprogram mapping method; I'd
be interested if people can provide counter-examples (I realize that
you'd have to do more if the procedures you call take different numbers
of arguments, but then again, you'd have to be more fancy in C, too).

If so, then omitting the ability to pass procedures around in Ada saved
the language designers from adding more syntactic and semantic and
run-time constructs to the language to support this.  Considering
the fact that Ada is already big, I think this was a wise decision --
especially since, with a minimal amount of work, you CAN do what you
want (using the enumeral-to-subprogram method).

Think about it -- strict type-checking becomes much more messy...
It is possible to add this to your language (e.g. CLU), but I personally
don't think it's worth complicating your language.  Even though C lets
you do it, C BY NO MEANS does type-checking of calls to procedures which
were passed in as arguments (it doesn't even check that the number of
arguments is correct).  Yes, C is an "unsafe" language...

Comments?  Remember, these are casual remarks and opinions -- please
think before you flame  :-)

Rich

^ permalink raw reply	[flat|nested] 14+ messages in thread
* Re: ForTran-Ada + flamette + question
@ 1986-05-28 16:56 richw
  1986-05-30 16:28 ` Vincent P. Broman
  0 siblings, 1 reply; 14+ messages in thread
From: richw @ 1986-05-28 16:56 UTC (permalink / raw)



> Unfortunately, Ada seems to be designed to make that as hard
> as possible.
>        :
> The only way I can see to simulate procedure pointers is to
> define an enumeration type with elements corresponding to
> the procedures that may be pointed to...

I personally don't think this is so bad or "hard".  In any case,
read on...

> The Steelman requirement 5D says: "Procedures, functions, types,
> labels, exception situations, and statements shall not be
> assignable to variables, be computable as values of expressions,
> or be usable as nongeneric parameters to procedures or
> functions."  This is a major lossage, in my view, compared to
> the reasonable design in (e.g.) Modula-2 for defining procedure
> pointers.

The most common complaint about Ada is that it's too large -- you're
suggesting that they should've added more?  Even though it really
isn't that hard to do what you want without this feature?  In my own
experience with CLU and C, both of which allow procedures as arguments,
the feature just wasn't used all that much to justify its existence...

In any case, you have overlooked the fact that Ada provides generics
which, although it can't be used for this particular case because generic
instantiation happens at compile time, can often be used where one would
like to define a subprogram which takes a subprogram as a argument...

It would've been REAL nice if they added Smalltalk-like inheritance to
Ada, too.  What about type inference?  Or logic programming features
like Prolog?  Or the ability to create functions at run-time like in
Lisp (which is pretty much what you want for this application)?

You've gotta draw the line somewhere.  I'm continually amazed how
people complain that Ada has either too much or not enough because
it's left out their favorite feature from language X.  Considering the
design goals for Ada, I think they did a good (not perfect) job of
designing a language with which you can write both efficient and
abstract, safe programs.

> Vincent Broman, code 632,  Naval Ocean Systems Center, San Diego, CA 92152, USA
> Phone: +1 619 225 2365        {seismo,caip,ihnp4,ucbvax}!\\\\\\\
> Arpa: broman@bugs.nosc.mil Uucp: {floyd,moss,bang,hp-sdd,sdcsvax}!noscvax!broman

Rich Wagner

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

end of thread, other threads:[~1986-06-04 23:39 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1986-05-21  6:06 ForTran-Ada + flamette + question larry
1986-05-21 15:41 ` Mark Biggar
1986-05-21 16:40 ` broman
1986-05-27 13:07   ` ForTran-Ada ... (really procedure variables) Vic Churchill
1986-05-28 19:30 ` ForTran-Ada + flamette + question David Lamb
     [not found] <175155@QZCOM>
1986-05-22  1:00 ` Jan_Michael_Rynning
  -- strict thread matches above, loose matches on Subject: below --
1986-05-28 15:54 richw
1986-05-30 12:46 ` Russ Holden
1986-05-28 16:56 richw
1986-05-30 16:28 ` Vincent P. Broman
1986-06-02 16:28   ` Jonathan P. Biggar
1986-06-03  5:11     ` Barry Margolin
1986-06-03 12:39     ` Russ Holden
1986-06-04 23:39   ` Bryce Bardin

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