comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@gnat.com (Robert Dewar)
Subject: Re: FAQ and string functions
Date: 4 Aug 2002 19:16:12 -0700
Date: 2002-08-05T02:16:12+00:00	[thread overview]
Message-ID: <5ee5b646.0208041816.13c1b3bb@posting.google.com> (raw)
In-Reply-To: 3D4D551F.190A19C0@san.rr.com

Darren New <dnew@san.rr.com> wrote in message news:<3D4D551F.190A19C0@san.rr.com>...
> I don't think you want to recurse a million times to read 
> million lines of text from the terminal. I really suspect 
> you don't want 1.5 million lines of text on the stack,
> either.

A very strange statement indeed. Using recursion to read
a million lines of text is perfectly natural, and with
a decent compiler that does tail recursion elimination,
you will get identical code for loops and for simple
recursion (recursive languages like Haskell absolutely
require this optimization of course). It is simply a
matter of taste whether you like the syntactic sugar
of a looping construct. That's all a loop is, syntactic sugar for tail
recursion.

>  I.e., if you have something
> > > that's difficult to program in a functional style.

None of the examples you give are even vaguely in this
category (unless you have difficulty programming in a functional
style, in which case the statement is sort of
vacuously true :-)

> A lexical analyzer is a simple parser. (I'm a bit of a 
> formalist, ya see, so
> I tend to mean the technical definitions when I use the 
> technical words.)

Well then unless you intend to emulate Humpty-Dumpty in
Alice, please use technical defintions the same way as
the rest of the world.

It is absolutely standard in the world of compilers to
draw a sharp distinction between lexical analysis, typically based on
type 3 (regular) languages, and parsing, typically based on type 2
(context free) languages.

It is *distinctly* unhelpful to use the term parsing for
the former, and will simply confuse other people. If that
is your goal, fine you will succeed, but if you are a "bit
of a formalist" then you will want to use formal terms in
their accepted meaning if you want to be understood.

> That's a good point, and something that's hard to do in 
> many other languages. However, it's really not enough. 
> For example, implement the Ada.Strings.Unbounded package 
> using only recursion to allocate record sizes. I haven't 
> tried, but I don't think it would be easy, even if 
> possible.

Of course it's possible, and easy if you have a reasonable
familiarity with writing in a recursive style. I always
like to give my students the task of writing programs in
a procedural language avoiding the use of assignments and
loops. It is definitely useful to learn familiarity with
recursion as a style of programming. I am not in favor of
forcing everyone to use ONLY this style, but I do find that
people overuse imperative constructs.

In particular, people very much overuse variables, and do
not make sufficient use of constants that are computed 
once, a powerful feature in Ada. 

(digression. I prefer Algol 68 to Ada in this respect. In
Algol-68, it is easier to write a constant declaration

    int a = expression;

than to write an initialized variable

    ref int a = loc int := expression;

and even in the shortened form:

    int a := expression;

is one character longer than the constant. In Ada, we have
to write an extra keyword to make things constant, so the
lazy path is to make an unnecessary variable)

Back on topic: the latest version of GNAT at least warns
if you write

   X : type := expression;

and never modify X (the compiler warns that you could
make this declaration into a constant declaration).

But it does not go so far as warning that if you write

   X : type;
   ..
   X := expression; 

where there are no other assignments to X, that X could
be made into a constant initialized with the expression
(the conditions for that are harder to figure out)


>  
> > But Ada programmers should teach themselves to work with perfectly sized
> > constant strings where feasable, as that's the language's native idiom.
> 
> Agreed. And it's easier to do in Ada than it is in C. But that doesn't make
> Ada a good string-processing language compared to something like Perl or
> Tcl. :-) It's clearly a difficult idiom, given the number of newbie
> questions about how to do it I see here. Once you're used to doing it that
> way, yes, it can be done that way. I'm not disputing that.
> 
> Anyway, this horse is a greasy spot on the sidewalk. You can have the last
> word. :-)



  reply	other threads:[~2002-08-05  2:16 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-30  6:32 FAQ and string functions Oleg Goodyckov
2002-07-30  8:52 ` Colin Paul Gloster
2002-07-30 13:48 ` Ted Dennison
2002-07-31  4:52   ` Brian May
2002-08-01 16:09     ` Ted Dennison
2002-08-02  0:21       ` Brian May
2002-08-02  1:56         ` tmoran
2002-08-02 13:59         ` Ted Dennison
2002-07-31  7:46   ` Oleg Goodyckov
2002-07-31  9:04     ` Lutz Donnerhacke
2002-07-31  9:39       ` Pascal Obry
2002-07-31 15:06         ` Oleg Goodyckov
2002-07-31 16:50       ` Oleg Goodyckov
2002-07-31 20:16     ` Simon Wright
2002-07-31 20:56       ` Robert A Duff
2002-08-01  0:11         ` Darren New
2002-08-01  1:08           ` tmoran
2002-08-01  9:25           ` Brian May
2002-08-01 11:20           ` Oleg Goodyckov
2002-08-01 15:43             ` Darren New
2002-08-01 21:37               ` Robert A Duff
2002-08-03  0:42                 ` Ted Dennison
2002-08-03 13:51                   ` Robert A Duff
2002-08-03 16:43                   ` Darren New
2002-08-05 13:37                   ` Stephen Leake
2002-08-02  8:01               ` Oleg Goodyckov
2002-08-02 16:09                 ` Darren New
2002-08-01 11:09         ` Oleg Goodyckov
2002-08-01 14:08           ` Frank J. Lhota
2002-08-01 15:06             ` Robert A Duff
2002-08-01 16:05             ` Oleg Goodyckov
2002-08-01 14:57         ` Georg Bauhaus
2002-07-31 22:04     ` Dmitry A.Kazakov
2002-07-31 15:23       ` Oleg Goodyckov
2002-08-01 21:57         ` Dmitry A.Kazakov
2002-08-01 13:10           ` Oleg Goodyckov
2002-08-02 23:29             ` Dmitry A.Kazakov
2002-08-02 16:35               ` Oleg Goodyckov
2002-08-05 11:50                 ` Dmitry A. Kazakov
2002-08-05 14:29                   ` Larry Kilgallen
2002-08-05 14:57                     ` Dmitry A. Kazakov
2002-08-05 15:12                   ` Oleg Goodyckov
2002-08-05 16:20                   ` Darren New
2002-08-05 17:01                     ` Georg Bauhaus
2002-08-05 17:48                       ` Darren New
2002-08-05 19:06                         ` tmoran
2002-08-05 20:08                           ` Darren New
     [not found]                     ` <slrnakv3q9.p2.lutz@taranis.iks-jena.de>
     [not found]                       ` <3D4FEFCB.3B74F5E5@san.rr.com>
2002-08-14  0:07                         ` Randy Brukardt
2002-08-01 14:29     ` Ted Dennison
2002-08-01 16:47       ` Oleg Goodyckov
2002-08-02 14:05         ` Ted Dennison
2002-08-02 16:11           ` Darren New
2002-08-03  0:30             ` Ted Dennison
2002-08-03  0:58               ` Darren New
2002-08-03  2:04                 ` Dale Stanbrough
2002-08-03  2:32                 ` Ted Dennison
2002-08-03  2:47                   ` Darren New
2002-08-03 12:41                     ` Ted Dennison
2002-08-03 16:53                       ` Darren New
2002-08-04  1:08                         ` Ted Dennison
2002-08-04 16:23                           ` Darren New
2002-08-05  2:16                             ` Robert Dewar [this message]
2002-08-05  3:45                               ` Darren New
2002-08-05  9:56                     ` Lutz Donnerhacke
2002-08-05 16:02                       ` Darren New
2002-08-14  0:42                         ` Randy Brukardt
2002-08-14  1:45                           ` Darren New
2002-08-14 19:37                             ` Randy Brukardt
2002-08-14 20:25                               ` Stephen Leake
2002-08-14 20:22                           ` Stephen Leake
2002-08-15 19:24                             ` Randy Brukardt
     [not found]                         ` <jb1vkustkugeutalhvrhv1n0k9hqn2fpip@4ax.com>
     [not found]                           ` <3D4FF351.8F4A6C0A@san.rr.com>
2002-08-14  1:03                             ` Randy Brukardt
2002-08-14  1:05                       ` Robert A Duff
     [not found]                       ` <3D4EA1AC.80D17170@s <wccofc6b66u.fsf@shell01.TheWorld.com>
2002-08-14 20:29                         ` Stephen Leake
2002-08-26 17:53                           ` Robert A Duff
2002-08-26 18:40                             ` Chad R. Meiners
2002-08-26 18:52                               ` Robert A Duff
2002-08-26 21:46                                 ` Chad R. Meiners
2002-08-05 13:29                     ` Stephen Leake
2002-08-03  5:07                   ` achrist
2002-08-03 12:52                     ` Ted Dennison
2002-08-05 15:34                       ` Ted Dennison
2002-08-05 13:24                 ` Stephen Leake
2002-08-05 16:02                   ` Darren New
2002-08-05  7:18           ` Oleg Goodyckov
2002-08-02  1:04     ` tmoran
replies disabled

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