comp.lang.ada
 help / color / mirror / Atom feed
* Re: Looking for Ada Technique Name and References
       [not found] ` <88kh6q$j4j$1@coward.ks.cc.utah.edu>
@ 2000-02-18  0:00   ` Tucker Taft
  2000-02-21  0:00   ` Diana Webster
  2000-02-22  0:00   ` Gautier
  2 siblings, 0 replies; 25+ messages in thread
From: Tucker Taft @ 2000-02-18  0:00 UTC (permalink / raw)


John Halleck wrote:
> 
> > John Halleck (nahaj@u.cc.utah.edu) wrote:
> > : I would appreciate it if someone could give me the name and a
> > : print reference for the following technique.
> 
> > Someone Replied:
> 
> >  It is called overloading.
> 
>   It uses overloading, but that was not the technique I was trying
>   to get accross.
> 
>   The technique in question is turning the what is normally written
>   as two function calls  (More or less:)
>       "*" (Transpose (A), B)
>   into a type mark and a single function call to a special function
>   that can handle it all more effeciently.


I've never seen it before, but I would call it "clever" ;-).

(Maybe too clever?  Perhaps a Transpose_And_Multiply(A, B) would be more
explicit...).


-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




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

* Re: Looking for Ada Technique Name and References
       [not found] ` <88kh6q$j4j$1@coward.ks.cc.utah.edu>
  2000-02-18  0:00   ` Looking for Ada Technique Name and References Tucker Taft
@ 2000-02-21  0:00   ` Diana Webster
  2000-02-22  0:00     ` John Halleck
  2000-02-22  0:00   ` Gautier
  2 siblings, 1 reply; 25+ messages in thread
From: Diana Webster @ 2000-02-21  0:00 UTC (permalink / raw)


This technique is called "composition" in mathematics, i.e., the composition
of two functions,
i.e, sum (average (xnum)).  Most programming languages support this.

John Halleck <nahaj@u.cc.utah.edu> wrote in message
news:88kh6q$j4j$1@coward.ks.cc.utah.edu...
> > John Halleck (nahaj@u.cc.utah.edu) wrote:
> > : I would appreciate it if someone could give me the name and a
> > : print reference for the following technique.
>
> > Someone Replied:
>
> >  It is called overloading.
>
>   It uses overloading, but that was not the technique I was trying
>   to get accross.
>
>   The technique in question is turning the what is normally written
>   as two function calls  (More or less:)
>       "*" (Transpose (A), B)
>   into a type mark and a single function call to a special function
>   that can handle it all more effeciently.
>
> >
> > : Background:
> >
> > :    Many matrix methods are written in the form  A := Transpose(B)*C
> > :    But, actually forming the transpose is expensive, and you are
better
> > :    off just writing a second matrix multiply routine that takes the
> > :    two matrices and treats the one as a transpose without actually
> > :    doing the transpose.
> >
> > :    Below is a technique that allows one to write it as one normally
> > :    sees it written, but lets the Ada compiler do the selection of
> > :    an appropriate routine.
> >
> > : Is there a name for this technique?   Does it appear already
documented
> > : somewhere?
> >
> >
: --------------------------------------------------------------------------
----
> >
> > : --  ...
> >
> > : type Matrix is array (positive range <>, positive range <>) of Float;
> > : type Transpose is new Matrix;
> >
> > : --  ...
> >
> > : -- This is just a matrix multiply routine.
> > : function "*" (Left : Matrix; Right : Matrix) return Matrix;
> >
> > : -- This routine multiplies the transpose of Left by Right.
> > : function "*" (Left : Transpose; Right : Matrix) return Matrix;
> >
> > : ----------
> >
> > : --  Examples:
> > : A, B, C, D, E: Matrix;
> >
> > : --  ...
> >
> > : A := B * C;              --  Matrix multiply.
> > : D := Transpose (E) * F;  --  D gets the result of multiplying E'F
> > :                          --  (By selecting the appropriate routine.
> >
> > : ---------------------------------------------------------------------






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

* Re: Looking for Ada Technique Name and References
       [not found] ` <88kh6q$j4j$1@coward.ks.cc.utah.edu>
  2000-02-18  0:00   ` Looking for Ada Technique Name and References Tucker Taft
  2000-02-21  0:00   ` Diana Webster
@ 2000-02-22  0:00   ` Gautier
  2 siblings, 0 replies; 25+ messages in thread
From: Gautier @ 2000-02-22  0:00 UTC (permalink / raw)
  To: John Halleck

Hi. The point with what you are trying to do is that the "*"
cannot know if its argument is transposed by nature...
unless you create a sort of matrices that are taken
as transposed! But it doesn't solve your pb.
The thing to do is "function Mult_transposed_by(..."
as suggested. No ambiguity... NB: For small matrices (3x3)
it's not so dramatic explicitely to transpose - since
you chose the functional writing that's is already a bit more expensive.
The real cost is with the multiplications. Transposing
is not too awful - no fp arithmetic and well cached. E.g.
I fill sparse matrices with tiny 4x4 up to 27x27 matrices
involved in expressions like 
 Transpose(Me4) + Transpose(Me3) + Re + Transpose(Me)
and the filling is very fast (DEC Ada on OpenVMS).

-- 
Gautier

_____\\________________\_______\
http://members.xoom.com/gdemont/




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

* Re: Looking for Ada Technique Name and References
  2000-02-22  0:00     ` John Halleck
@ 2000-02-22  0:00       ` Vladimir Olensky
  2000-02-22  0:00         ` John Halleck
  2000-02-22  0:00       ` tmoran
  2000-02-23  0:00       ` Nick Roberts
  2 siblings, 1 reply; 25+ messages in thread
From: Vladimir Olensky @ 2000-02-22  0:00 UTC (permalink / raw)


 John Halleck <nahaj@u.cc.utah.edu> wrote in message
 news:88kh6q$j4j$1@coward.ks.cc.utah.edu...
 > > John Halleck (nahaj@u.cc.utah.edu) wrote:
 > > : I would appreciate it if someone could give me the name and a
 > > : print reference for the following technique.
 >
 >> Someone Replied:
 >>  It is called overloading.
 >

 >   It uses overloading, but that was not the technique I was trying

 >   to get accross.
 >
 >   The technique in question is turning the what is normally written
 >   as two function calls  (More or less:)
 >       "*" (Transpose (A), B)
 >   into a type mark and a single function call to a special function

>   that can handle it all more effeciently.


As a matter of fact the answer is contained in your original question.

Actually this is combination of two basic techniques and as such I do
not think that it has or should have any special name.  There would be
just not enough names to cover all possible combination of language
basic techniques.

In this case it is combination of object type marking (or view conversion
or type cast  - there are several terns for that )  with procedure
overloading.
Such view  conversion  in  some other systems  called simply as
"object logical view "  and this object is treated differently depending on
it's  current  logical view.

You have an matrix object and you mark it as transpose so that language
can choose appropriate  procedure  to handle matrix object  according
to it's  current view (or mark) .

In real life many things are done the same way but this happens without
paying special attention to that.


Regards,
Vladimir Olensky







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

* Re: Looking for Ada Technique Name and References
  2000-02-22  0:00     ` John Halleck
  2000-02-22  0:00       ` Vladimir Olensky
@ 2000-02-22  0:00       ` tmoran
  2000-02-22  0:00         ` David Starner
  2000-02-23  0:00       ` Nick Roberts
  2 siblings, 1 reply; 25+ messages in thread
From: tmoran @ 2000-02-22  0:00 UTC (permalink / raw)


> type Transpose is new Matrix;
> D := Transpose (E) * F;  --  D gets the result of multiplying E'F
  Perhaps there's a term for it among magicians.  You get the audience's
attention focused on what you seem to be doing to E, and they don't
notice that you're actually doing something to '*' instead.  Is this
for an obfuscated code contest?




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

* Re: Looking for Ada Technique Name and References
  2000-02-22  0:00       ` tmoran
@ 2000-02-22  0:00         ` David Starner
  2000-02-23  0:00           ` tmoran
  0 siblings, 1 reply; 25+ messages in thread
From: David Starner @ 2000-02-22  0:00 UTC (permalink / raw)


On Tue, 22 Feb 2000 08:05:50 GMT, tmoran@bix.com <tmoran@bix.com> wrote:
>> type Transpose is new Matrix;
>> D := Transpose (E) * F;  --  D gets the result of multiplying E'F
>  Perhaps there's a term for it among magicians.  You get the audience's
>attention focused on what you seem to be doing to E, and they don't
>notice that you're actually doing something to '*' instead.  Is this
>for an obfuscated code contest?

Why is this obfuscated? It does Transpose (E) * F. The * operator does
multiplication.  Transpose does invert the array, it just does so by
redefining it instead of moving stuff around in memory. It's not the
clearest thing in the world, but it's entirely reasonable, especially
for the optimization done.

-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




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

* Re: Looking for Ada Technique Name and References
  2000-02-23  0:00       ` Nick Roberts
@ 2000-02-22  0:00         ` Jon S Anthony
  2000-02-28  0:00           ` Charles D. Hixson
  0 siblings, 1 reply; 25+ messages in thread
From: Jon S Anthony @ 2000-02-22  0:00 UTC (permalink / raw)


Nick Roberts wrote:
> 
> "John Halleck" <nahaj@u.cc.utah.edu> wrote in message
> news:88svc0$nkj$1@coward.ks.cc.utah.edu...
> > ...
> > This trick is *** NOT *** supported by most languages.
>
> I don't think I've ever encountered any language that allows a
> function composition itself to be specially defined.

Any language that directly supports higher order functions supports
such definitions (any functional language, e.g., Common Lisp or Scheme).


> A classic case is where a 'mod' is done between two operands just
> after (or before) a divide is done between the same operands. Many
> compilers will optimise this into a single machine instruction
> (which computes both the quotient and the modulus in one go).

What has this to do with function composition?  Sounds like a typical
optimization arising out of data flow analysis.

/Jon

-- 
Jon Anthony
Synquiry Technologies, Ltd. Belmont, MA 02478, 617.484.3383
"Nightmares - Ha!  The way my life's been going lately,
 Who'd notice?"  -- Londo Mollari




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

* Re: Looking for Ada Technique Name and References
  2000-02-21  0:00   ` Diana Webster
@ 2000-02-22  0:00     ` John Halleck
  2000-02-22  0:00       ` Vladimir Olensky
                         ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: John Halleck @ 2000-02-22  0:00 UTC (permalink / raw)


Diana Webster (dkweb@arlut.utexas.edu) wrote:
: This technique is called "composition" in mathematics, i.e., the composition
: of two functions,
: i.e, sum (average (xnum)).  Most programming languages support this.

  The trick posted is not a composition of functions.

  It keeps the notation of the composition of functions, but substitutes
  a special purpose routine faster than the composition of functions. 

  This trick is *** NOT *** supported by most languages.

: John Halleck <nahaj@u.cc.utah.edu> wrote in message
: news:88kh6q$j4j$1@coward.ks.cc.utah.edu...
: > > John Halleck (nahaj@u.cc.utah.edu) wrote:
: > > : I would appreciate it if someone could give me the name and a
: > > : print reference for the following technique.
: >
: > > Someone Replied:
: >
: > >  It is called overloading.
: >
: >   It uses overloading, but that was not the technique I was trying
: >   to get accross.
: >
: >   The technique in question is turning the what is normally written
: >   as two function calls  (More or less:)
: >       "*" (Transpose (A), B)
: >   into a type mark and a single function call to a special function
: >   that can handle it all more effeciently.
: >
: > >
: > > : Background:
: > >
: > > :    Many matrix methods are written in the form  A := Transpose(B)*C
: > > :    But, actually forming the transpose is expensive, and you are
: better
: > > :    off just writing a second matrix multiply routine that takes the
: > > :    two matrices and treats the one as a transpose without actually
: > > :    doing the transpose.
: > >
: > > :    Below is a technique that allows one to write it as one normally
: > > :    sees it written, but lets the Ada compiler do the selection of
: > > :    an appropriate routine.
: > >
: > > : Is there a name for this technique?   Does it appear already
: documented
: > > : somewhere?
: > >
: > >
: : --------------------------------------------------------------------------
: ----
: > >
: > > : --  ...
: > >
: > > : type Matrix is array (positive range <>, positive range <>) of Float;
: > > : type Transpose is new Matrix;
: > >
: > > : --  ...
: > >
: > > : -- This is just a matrix multiply routine.
: > > : function "*" (Left : Matrix; Right : Matrix) return Matrix;
: > >
: > > : -- This routine multiplies the transpose of Left by Right.
: > > : function "*" (Left : Transpose; Right : Matrix) return Matrix;
: > >
: > > : ----------
: > >
: > > : --  Examples:
: > > : A, B, C, D, E: Matrix;
: > >
: > > : --  ...
: > >
: > > : A := B * C;              --  Matrix multiply.
: > > : D := Transpose (E) * F;  --  D gets the result of multiplying E'F
: > > :                          --  (By selecting the appropriate routine.
: > >
: > > : ---------------------------------------------------------------------






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

* Re: Looking for Ada Technique Name and References
  2000-02-22  0:00       ` Vladimir Olensky
@ 2000-02-22  0:00         ` John Halleck
  0 siblings, 0 replies; 25+ messages in thread
From: John Halleck @ 2000-02-22  0:00 UTC (permalink / raw)


:  >   The technique in question is turning the what is normally written
:  >   as two function calls  (More or less:)
:  >       "*" (Transpose (A), B)
:  >   into a type mark and a single function call to a special function
:  >   that can handle it all more effeciently.


: [...]

: In this case it is combination of object type marking (or view conversion
: or type cast  - there are several terns for that )  with procedure
: overloading.
: Such view  conversion  in  some other systems  called simply as
: "object logical view "  and this object is treated differently depending on
: it's  current  logical view.

: You have an matrix object and you mark it as transpose so that language
: can choose appropriate  procedure  to handle matrix object  according
: to it's  current view (or mark) .

  Thank you...   You've given the best response to date, and you clearly
  understand what is intended.

: In real life many things are done the same way but this happens without
: paying special attention to that.

  The reason for the original question is a matter of documentation.
  It helps (in my opinion) if one has other places one can point
  people if you use an unfamiliar technique.

: Regards,
: Vladimir Olensky

  Thank you for your thoughtfull post.





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

* Re: Looking for Ada Technique Name and References
  2000-02-22  0:00     ` John Halleck
  2000-02-22  0:00       ` Vladimir Olensky
  2000-02-22  0:00       ` tmoran
@ 2000-02-23  0:00       ` Nick Roberts
  2000-02-22  0:00         ` Jon S Anthony
  2 siblings, 1 reply; 25+ messages in thread
From: Nick Roberts @ 2000-02-23  0:00 UTC (permalink / raw)


"John Halleck" <nahaj@u.cc.utah.edu> wrote in message
news:88svc0$nkj$1@coward.ks.cc.utah.edu...
> ...
> This trick is *** NOT *** supported by most languages.

I don't think I've ever encountered any language that allows a function
composition itself to be specially defined. The nearest thing is when
compilers do optimisations.

A classic case is where a 'mod' is done between two operands just after (or
before) a divide is done between the same operands. Many compilers will
optimise this into a single machine instruction (which computes both the
quotient and the modulus in one go).

--
Nick Roberts
http://www.adapower.com/lab/adaos









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

* Re: Looking for Ada Technique Name and References
  2000-02-22  0:00         ` David Starner
@ 2000-02-23  0:00           ` tmoran
  0 siblings, 0 replies; 25+ messages in thread
From: tmoran @ 2000-02-23  0:00 UTC (permalink / raw)


>Why is this obfuscated? It does Transpose (E) * F. The * operator does
>multiplication.  Transpose does invert the array, it just does so by
>redefining it instead of moving stuff around in memory. It's not the
  Transpose does not invert the array.  It tells the compiler to use a
different definition of "*".
  Suppose the body of the Matrix."*" routine was re-written, say to take
advantage of new vector arithmetic hardware or to fix an error.
"Transpose (E) * F" would be no faster, and no more correct, since it
actually calls a different "*" function entirely.
  It looks like "Transpose" is doing something to E, but instead it's
modifying "*".  Granted this seems like a useful little white lie,
but tricky code makes me uncomfortable.  The usual recommendation for
tricky, but useful, code is to comment thoroughly.  But compare
X := Transpose(E) * F; -- use the Transpose_Left_And_Multiply function
to
X := TLM(E, F); -- X := Transpose(E) * F;

  Of course if you are trying to save the time of copying an array,
you surely will use procedures, rather than array-returning functions,
anyway.




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

* Re: Looking for Ada Technique Name and References
  2000-02-22  0:00         ` Jon S Anthony
@ 2000-02-28  0:00           ` Charles D. Hixson
  2000-02-28  0:00             ` Jon S Anthony
  0 siblings, 1 reply; 25+ messages in thread
From: Charles D. Hixson @ 2000-02-28  0:00 UTC (permalink / raw)


Jon S Anthony wrote:
  -- snip

> Any language that directly supports higher order functions supports
> such definitions (any functional language, e.g., Common Lisp or Scheme).
>
>

  -- snip

> /Jon
>
> --
> Jon Anthony
> Synquiry Technologies, Ltd. Belmont, MA 02478, 617.484.3383
> "Nightmares - Ha!  The way my life's been going lately,
>  Who'd notice?"  -- Londo Mollari

Also some not-so-functional languages, like Python, have constructs that
support this.  And since C supports pointers to functions, I suppose that
one could implement it in C.  And speaking of pointers to functions,
doesn't Ada95 ...







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

* Re: Looking for Ada Technique Name and References
  2000-02-28  0:00           ` Charles D. Hixson
@ 2000-02-28  0:00             ` Jon S Anthony
  2000-02-29  0:00               ` Charles Hixson
  0 siblings, 1 reply; 25+ messages in thread
From: Jon S Anthony @ 2000-02-28  0:00 UTC (permalink / raw)


> And since C supports pointers to functions, I suppose that
> one could implement it in C.  And speaking of pointers to functions,
> doesn't Ada95 ...

Depends on what you mean.  In any of these you need to hack a lot
of support - to make it really "right" you probably end up
hacking a lot of the implementation of some functional language.

In particular, none of the above supports closures (to have closures
you really need GC) and certainly not Lisp like macros (where you
can make compile time versions of such compositions).

/Jon

-- 
Jon Anthony
Synquiry Technologies, Ltd. Belmont, MA 02478, 617.484.3383
"Nightmares - Ha!  The way my life's been going lately,
 Who'd notice?"  -- Londo Mollari




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

* Re: Looking for Ada Technique Name and References
  2000-02-29  0:00                 ` Brian Rogoff
@ 2000-02-29  0:00                   ` Jon S Anthony
  2000-02-29  0:00                     ` Brian Rogoff
  2000-03-04  0:00                     ` Nick Roberts
  2000-02-29  0:00                   ` Wes Groleau
  1 sibling, 2 replies; 25+ messages in thread
From: Jon S Anthony @ 2000-02-29  0:00 UTC (permalink / raw)


Brian Rogoff wrote:
> 
> Well, the topic has really changed, but if you are going to rank languages
> based on their support for the functional programming paradigm, I'd give
> Ada a fairly significant edge over C and C++ since

Agreed.

> (1) Ada is lexically scoped

??? Surely you don't mean to imply that C/C++ are dynamically scoped?


> (2) Ada allows the use of nested subprograms as subprogram parameters to
>     generic instantiations, allowing the crude simulation of downward
>     funargs.

Agreed, but this is very crude indeed.


> In my experience, this captures some small amount of FP style directly
> which is awful in C and unpleasant in C++ (where you can overload "()"
> and explicitly pass local state rather than directly referencing variables
> from an enclosing scope).

I'm still not clear on why you think this means that C/C++ are not
lexically
scoped (or perhaps "less lexically scoped" than Ada).  Certainly passing
local state around does not impact this.  I agree that there are cases
where
you _have_ to do this when a lexically scoped access is what you really
want.


>Re: On Tue, 29 Feb 2000, Charles Hixson wrote:
>> Even the various dialects of Lisp range from the purely functional (i.e.,
>> where all constructs can be phrased as a functional call with sugar around
>> it) to Common Lisp.  And none of these are what I now think of as the
>> functional languages:  ML, OCaML, etc.
>
> I don't want to start a FP language war in c.l.ada, but why do you
> consider "Pure Lisp", ML and OCaml functional, Common Lisp not? I use
> references, arrays, and exceptions in my OCaml code...

Good question; direct support for iteration?  Then again, he seems to
exclude
Scheme as well.  Shrug.

/Jon

-- 
Jon Anthony
Synquiry Technologies, Ltd. Belmont, MA 02478, 617.484.3383
"Nightmares - Ha!  The way my life's been going lately,
 Who'd notice?"  -- Londo Mollari




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

* Re: Looking for Ada Technique Name and References
  2000-02-29  0:00                   ` Jon S Anthony
@ 2000-02-29  0:00                     ` Brian Rogoff
  2000-02-29  0:00                       ` Jon S Anthony
  2000-03-04  0:00                     ` Nick Roberts
  1 sibling, 1 reply; 25+ messages in thread
From: Brian Rogoff @ 2000-02-29  0:00 UTC (permalink / raw)


On Tue, 29 Feb 2000, Jon S Anthony wrote:

> Brian Rogoff wrote:
> > 
> > Well, the topic has really changed, but if you are going to rank languages
> > based on their support for the functional programming paradigm, I'd give
> > Ada a fairly significant edge over C and C++ since
> 
> Agreed.
> 
> > (1) Ada is lexically scoped
> 
> ??? Surely you don't mean to imply that C/C++ are dynamically scoped?

No, C is lexically scoped too, but in a very trivial way, since you can't 
nest subprogram definitions. For those who aren't familiar with the
terminology, I mean that free variables in a block get their values from
the closest *textually* enclosing block, as opposed to getting its value 
from the runtime context like Emacs Lisp for example. 

Thanks for the prompt; what I wrote could easily mislead someone. Perhaps 
more precise terminology is called for. Or perhaps not, maybe I should
just have used a strong "and", the combination of lexical scope AND
subprogram nesting is what enables a limited FP style in Ada...

> > (2) Ada allows the use of nested subprograms as subprogram parameters to
> >     generic instantiations, allowing the crude simulation of downward
> >     funargs.
> 
> Agreed, but this is very crude indeed.

Yes, that's why I think it should be fixed. Generics are a heavyweight
mechanism for this, and there are a few cases (I posted one a long time 
ago based on some code Richard O'Keefe posted here) where using generics
is far less readable and reusable than something like Unrestricted_Access.

> > In my experience, this captures some small amount of FP style directly
> > which is awful in C and unpleasant in C++ (where you can overload "()"
> > and explicitly pass local state rather than directly referencing variables
> > from an enclosing scope).
> 
> I'm still not clear on why you think this means that C/C++ are not
> lexically
> scoped (or perhaps "less lexically scoped" than Ada).  Certainly passing
> local state around does not impact this.  I agree that there are cases
> where
> you _have_ to do this when a lexically scoped access is what you really
> want.

Because in Ada I can declare a subprogram nested in another, which refers
to local variables in the enclosing subprogram, and then use the nested 
subprogram as a parameter to a generic instantiation. I can't do that in 
C or C++, and to achieve the same effect I have to manually "lambda lift", 
and explicitly pass those local vars I'm interested in as method
arguments.

So, while they are strictly speaking lexically scoped, it isn't very
useful from a "coding FP" perspective. I hope that's clearer.

> 
> >Re: On Tue, 29 Feb 2000, Charles Hixson wrote:
> >> Even the various dialects of Lisp range from the purely functional (i.e.,
> >> where all constructs can be phrased as a functional call with sugar around
> >> it) to Common Lisp.  And none of these are what I now think of as the
> >> functional languages:  ML, OCaML, etc.
> >
> > I don't want to start a FP language war in c.l.ada, but why do you
> > consider "Pure Lisp", ML and OCaml functional, Common Lisp not? I use
> > references, arrays, and exceptions in my OCaml code...
> 
> Good question; direct support for iteration?  

Here's some legal OCaml from the manual

#let insertion_sort a =
   for i = 1 to Array.length a - 1 do
     let val_i = a.(i) in
     let j = ref i in
     while !j > 0 && val_i < a.(!j - 1) do
       a.(!j) <- a.(!j - 1);
       j := !j - 1
     done;
     a.(!j) <- val_i
   done;;

val insertion_sort : 'a array -> unit = <fun>

I guess OCaml isn't an FP then. Charles?

-- Brian





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

* Re: Looking for Ada Technique Name and References
  2000-02-29  0:00                     ` Brian Rogoff
@ 2000-02-29  0:00                       ` Jon S Anthony
  2000-03-01  0:00                         ` Brian Rogoff
  2000-03-01  0:00                         ` Charles Hixson
  0 siblings, 2 replies; 25+ messages in thread
From: Jon S Anthony @ 2000-02-29  0:00 UTC (permalink / raw)


Brian Rogoff wrote:
> 
> > ??? Surely you don't mean to imply that C/C++ are dynamically scoped?
> 
> No, C is lexically scoped too, but in a very trivial way, since you can't
> nest subprogram definitions.

Right - this is leading where I figured you intended it to go.

> > I'm still not clear on why you think this means that C/C++ are not
> > lexically scoped (or perhaps "less lexically scoped" than Ada).
> > Certainly passing local state around does not impact this.  I agree
> > that there are cases where you _have_ to do this when a lexically
> > scoped access is what you really want.
> 
> Because in Ada I can declare a subprogram nested in another, which
> refers to local variables in the enclosing subprogram, and then use
...

Right, this is actually exactly what I thought you intended.  I agree
with this completely.

> So, while they are strictly speaking lexically scoped, it isn't very
> useful from a "coding FP" perspective. I hope that's clearer.

Also agree.

> > > I don't want to start a FP language war in c.l.ada, but why do you
> > > consider "Pure Lisp", ML and OCaml functional, Common Lisp not? I use
> > > references, arrays, and exceptions in my OCaml code...
> >
> > Good question; direct support for iteration?
> 
> Here's some legal OCaml from the manual
> 
> #let insertion_sort a =
>    for i = 1 to Array.length a - 1 do
>      let val_i = a.(i) in
>      let j = ref i in
>      while !j > 0 && val_i < a.(!j - 1) do
>        a.(!j) <- a.(!j - 1);
>        j := !j - 1
>      done;
>      a.(!j) <- val_i
>    done;;

So much for iteration being the reason (as I mentioned, this couldn't
have been quite right anyway as he seems to exclude Scheme as well).

> val insertion_sort : 'a array -> unit = <fun>
> 
> I guess OCaml isn't an FP then. Charles?

Well, he already claimed it was, so there must be some other
feature(s) of direct Lisp family members that excludes them in his
taxonomy.  I see OCaml also has assignment.

Charles, what about Dylan?


/Jon

-- 
Jon Anthony
Synquiry Technologies, Ltd. Belmont, MA 02478, 617.484.3383
"Nightmares - Ha!  The way my life's been going lately,
 Who'd notice?"  -- Londo Mollari




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

* Re: Looking for Ada Technique Name and References
  2000-02-28  0:00             ` Jon S Anthony
@ 2000-02-29  0:00               ` Charles Hixson
  2000-02-29  0:00                 ` Brian Rogoff
  0 siblings, 1 reply; 25+ messages in thread
From: Charles Hixson @ 2000-02-29  0:00 UTC (permalink / raw)


Sorry, my point was that there was a "hierarchy" of languages.  I was
ranking them (approximately) by decreasing amount of support for
functional constructs. (Not clear, I realize, as I only gave three
examples, and C [or C++] really is about on a par with Ada.)  But there
are several different languages that give different degrees of support.
Even the various dialects of Lisp range from the purely functional (i.e.,
where all constructs can be phrased as a functional call with sugar around
it) to Common Lisp.  And none of these are what I now think of as the
functional languages:  ML, OCaML, etc.

Jon S Anthony wrote:

> > And since C supports pointers to functions, I suppose that
> > one could implement it in C.  And speaking of pointers to functions,
> > doesn't Ada95 ...
>
> Depends on what you mean.  In any of these you need to hack a lot
> of support - to make it really "right" you probably end up
> hacking a lot of the implementation of some functional language.
>
> In particular, none of the above supports closures (to have closures
> you really need GC) and certainly not Lisp like macros (where you
> can make compile time versions of such compositions).
>
> /Jon
>
> --
> Jon Anthony
> Synquiry Technologies, Ltd. Belmont, MA 02478, 617.484.3383
> "Nightmares - Ha!  The way my life's been going lately,
>  Who'd notice?"  -- Londo Mollari





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

* Re: Looking for Ada Technique Name and References
  2000-02-29  0:00               ` Charles Hixson
@ 2000-02-29  0:00                 ` Brian Rogoff
  2000-02-29  0:00                   ` Jon S Anthony
  2000-02-29  0:00                   ` Wes Groleau
  0 siblings, 2 replies; 25+ messages in thread
From: Brian Rogoff @ 2000-02-29  0:00 UTC (permalink / raw)


On Tue, 29 Feb 2000, Charles Hixson wrote:
> Sorry, my point was that there was a "hierarchy" of languages.  I was
> ranking them (approximately) by decreasing amount of support for
> functional constructs. (Not clear, I realize, as I only gave three
> examples, and C [or C++] really is about on a par with Ada.)  But there
> are several different languages that give different degrees of support.
> Even the various dialects of Lisp range from the purely functional (i.e.,
> where all constructs can be phrased as a functional call with sugar around
> it) to Common Lisp.  And none of these are what I now think of as the
> functional languages:  ML, OCaML, etc.

Well, the topic has really changed, but if you are going to rank languages 
based on their support for the functional programming paradigm, I'd give 
Ada a fairly significant edge over C and C++ since 

(1) Ada is lexically scoped
(2) Ada allows the use of nested subprograms as subprogram parameters to 
    generic instantiations, allowing the crude simulation of downward 
    funargs. 

In my experience, this captures some small amount of FP style directly
which is awful in C and unpleasant in C++ (where you can overload "()" 
and explicitly pass local state rather than directly referencing variables 
from an enclosing scope). I hope that the issue of downward funargs is 
revisited in Ada 0X, since using generics this way is awkward when you've 
grown accustomed to direct support for this. Robert Eachus mentioned that 
if you have "apply" you never need iterators. I think that's a bit extreme 
(and he really meant "fold" ;-) but I also think downward funargs would
make that programming style far nicer in Ada.

I don't want to start a FP language war in c.l.ada, but why do you
consider "Pure Lisp", ML and OCaml functional, Common Lisp not? I use 
references, arrays, and exceptions in my OCaml code...

-- Brian





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

* Re: Looking for Ada Technique Name and References
  2000-02-29  0:00                 ` Brian Rogoff
  2000-02-29  0:00                   ` Jon S Anthony
@ 2000-02-29  0:00                   ` Wes Groleau
  2000-02-29  0:00                     ` Gautier
  1 sibling, 1 reply; 25+ messages in thread
From: Wes Groleau @ 2000-02-29  0:00 UTC (permalink / raw)


> Well, the topic has really changed, but if you are going to rank languages
> based on their support for the functional programming paradigm, I'd give
> Ada a fairly significant edge over C and C++ .....

I once saw an example where someone (who obviously 
misunderstood the "mandate") wrote an Ada 83 package 
containing (I'm probably getting some of this wrong 
due to elapsed time):

  - an enumerated type where the literals were
    LISP predefined function names.

  - an unconstrained array type of those enums

  - Various support subprograms (I forget the
    details) that took the array type as parameter.

  - A subprogram that iterates over an enum array
    object and uses each element as a case selector.

Then this guy wrote his whole program in LISP, and 
with a trivial syntax transformation, could compile 
it with an Ada compiler and run it:

with LISP_Support; use LISP_Support;
procedure Main is

begin

   LISP(( CAR (( CDR (( atom, atom, atom )) .....
      ..... ));

   -- I don't know LISP, so I made up the above
   -- just to give the flavor....

end Main;

If anyone else saw this, and can tell me where to find
it, I'd love to see it again!  :-)

-- 
Wes Groleau
http://freepages.genealogy.rootsweb.com/~wgroleau




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

* Re: Looking for Ada Technique Name and References
  2000-02-29  0:00                   ` Wes Groleau
@ 2000-02-29  0:00                     ` Gautier
  2000-03-01  0:00                       ` Wes Groleau
  0 siblings, 1 reply; 25+ messages in thread
From: Gautier @ 2000-02-29  0:00 UTC (permalink / raw)


Wes:

>    LISP(( CAR (( CDR (( atom, atom, atom )) .....
[...]

> If anyone else saw this, and can tell me where to find
> it, I'd love to see it again!  :-)

Anyway, CAR x could be programmed +/- as ( 1=> x(x'first) )
and CDR x as ( x(x'first+1 .. x'last) ), couldn't it ?

G.




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

* Re: Looking for Ada Technique Name and References
  2000-03-01  0:00                         ` Brian Rogoff
@ 2000-03-01  0:00                           ` Jon S Anthony
  0 siblings, 0 replies; 25+ messages in thread
From: Jon S Anthony @ 2000-03-01  0:00 UTC (permalink / raw)


> Brian Rogoff wrote:
>
> On Tue, 29 Feb 2000, Jon S Anthony wrote:
> > Brian Rogoff wrote:
> > > I guess OCaml isn't an FP then. Charles?
> > 
> > Well, he already claimed it was, so there must be some other
> > feature(s) of direct Lisp family members that excludes them in his
> > taxonomy.  I see OCaml also has assignment.
> 
> Yes. OCaml and SML both have references, mutable arrays, and
> exceptions, which mean they are not "pure" FPs like Haskell and
> Clean, and much closer to languages like Scheme.

Sound closer to CL/CLOS to me (a lot of machinery "out-of-the-box").


> My view (grunt programmer in the trenches) is that we judge a
> language by its support for a particular style, and don't worry
> about pure/impure distinctions.

Here we are in great alignment.  I would go even further and say that
single paradigm languages (so called "pure" OO or FP or ...) are
always at a significant disadvantage in being able to cleanly express
solutions to problems.  Problems are nearly always multi-faceted and
larger ones are typically mult-perspective.  To cleanly tackle these
things you really need cleanly and flexibly handle diverse
representations and processing paradigms.


> Lisp (ANSI CL), Scheme and the MLs all support FP style *much*
> better than those languages without first class functions. To me,
> first class functions are the sine-qua-non of FP, so these are all
> FPLs.

Again, we are in close agreement.  Certainly first class functions are
_necessary_.  At the end of the day, I would say that the exclusion of
assignment yields "pure" FPLs.  Assignment is an ugly nasty thing, but
it's advantages always seem to out weigh this.


> Some might argue that Haskell and Clean do best of all because they
> are lazy (a little lie; really "non-strict") by default.

I think there are many who would argue this, where "best" means
"purest" not actually "overall goodness" (at least IMO).


> I don't have enough practical experience here, when I tried to use
> Haskell in anger I found it way too slow.

I too do not have enough real experience with Haskell, but all I have
read about it (even from its proponents) directly supports you here.


> Common Lisp and C++ are interesting in that they support "staged
> programming" or partial evaluation directly in the language, via
> procedural macros and templates respectively.

Common Lisp macros are really a _lot_ more than this - there's nothing
partial about them.  They go far beyond the sort of thing you can do
with templates.  A CL macro is really just another CL program and can
do anything a "regular" program can do.  It can make use of any
functions, methods, other macros, etc.  What makes them so potent is
that they are invoked between the reader and the parser (in this they
are sort of like a "typical macro").  But since you have the full
capabilities of CL here, you can perform "unlimited" compile time
computations.  In particular, on the input stream.  You can do truly
stunning things with this.  You could write a C++ compiler with it
(well, as close as one can write a C++ compiler...) or the goofy
template language of C++.

One of the most typical is to write a domain or application specific
language for use in the "real" programs you are after (so that you can
express things cleanly, flexibly and at very high level), have it
compile down into optimized CL/CLOS, and then have this passed off to
the optimizing CL compiler.  This all happens transparently.  Of
course, you can also do this sort of thing "on the fly".  Upshot: you
typically never need any interpreter for anything, and you can express
solutions that mirror the problem space extremely closely (far closer
than with simple OOP), and the result always has the full advantage of
optimized machine code.


> Kinda cool, but I understand the Ada position on these features and
> how they impact maintainability.

The C++ template crap might be "kinda cool", but the CL macro
capability is pretty awesome.  Done "correctly", CL macros have a very
_positive_ impact on maintainability.

I agree it can be useful to keep the Ada position in mind; certainly
in the C++ case, the Ada way is a hands down winner.  Note that in the
CL case, you can at any point of use of a macro immediately: 1) see
what it yields and check if this is what you expect, 2) try it to see
if the result does what you expect.  Typically neither of these is
necessary.


> As I understand it, the consensus in the Lisp community is that
> macros are to be used sparingly.

I would say - used correctly, sparingly not being relevant.


I suppose this has gone far enough afield from Ada and we can
pretty much lay it to rest in this forum.


/Jon

-- 
Jon Anthony
Synquiry Technologies, Ltd. Belmont, MA 02478, 617.484.3383
"Nightmares - Ha!  The way my life's been going lately,
 Who'd notice?"  -- Londo Mollari




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

* Re: Looking for Ada Technique Name and References
  2000-02-29  0:00                     ` Gautier
@ 2000-03-01  0:00                       ` Wes Groleau
  0 siblings, 0 replies; 25+ messages in thread
From: Wes Groleau @ 2000-03-01  0:00 UTC (permalink / raw)


Gautier wrote:
> 
> Wes:
> 
> >    LISP(( CAR (( CDR (( atom, atom, atom )) .....
> [...]
> 
> > If anyone else saw this, and can tell me where to find
> > it, I'd love to see it again!  :-)
> 
> Anyway, CAR x could be programmed +/- as ( 1=> x(x'first) )
> and CDR x as ( x(x'first+1 .. x'last) ), couldn't it ?

I'm not a LISP expert, but I think you're right.  However, the package
mentioned could do a lot more than CAR and CDR.




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

* Re: Looking for Ada Technique Name and References
  2000-02-29  0:00                       ` Jon S Anthony
  2000-03-01  0:00                         ` Brian Rogoff
@ 2000-03-01  0:00                         ` Charles Hixson
  1 sibling, 0 replies; 25+ messages in thread
From: Charles Hixson @ 2000-03-01  0:00 UTC (permalink / raw)


I'm not an expert, or even an intermediate at most of these languages, so if I
misclassified some of them, well, I'm sorry. My level of knowledge is such that
I class Scheme as a Lisp dialect that's simpler than Common Lisp, and don't go
much further.

What Do I Think Is a Functional Language?
When I was studying Lisp (around the time of Lisp 1.5 and without access to a
computer that actually had Lisp installed) there was a big argument raging as
to whether or not certain features should be included, because they converted
Lisp from being a purely functional language into being an impurely functional
language.  Most (all?) modern dialects have these features.  I don't remember
specifically what they were.  Something pretty basic.  Possibly fset or set.
Anything that does direct surgery on the list structure would have been
considered non-functional.  In a purely functional language there was to be no
direct changes allowed to anything that had been previously defined.  So this
is what I was considering one of the extreme poles.  Assembler (well,
micro-code [i.e., direct specification of hardware gate choices]) is, of
course, the other extreme pole along the spectrum that I was using.  I was not
assuming that anything "practical for use in large projects" would be found at
either pole (though I've heard arguments about that from both the camps that
this isn't true).

When I mentioned C or Ada as allowing functional programming to be done, my
idea was rather along the lines of "You can design a set of functions that are
complete and implement them in [C | Ada].  Then do your programming based on
those functions", rather than that the language as issued would support
functional programming (though both C and Ada *DO* prohibit changing the value
of parameters passed to a function).  Still, even using the assignment
statement directly voids the rules that I was taught functional programming
obeyed.

I am definitely the wrong person to be defending the functional position, as I
don't believe it to be ... desirable.  But then neither do I believe its
opposite to be desirable (necessary, perhaps).  I was merely observing that the
various languages fell along a range.  I'm sorry if I mispositioned one or two
of them.






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

* Re: Looking for Ada Technique Name and References
  2000-02-29  0:00                       ` Jon S Anthony
@ 2000-03-01  0:00                         ` Brian Rogoff
  2000-03-01  0:00                           ` Jon S Anthony
  2000-03-01  0:00                         ` Charles Hixson
  1 sibling, 1 reply; 25+ messages in thread
From: Brian Rogoff @ 2000-03-01  0:00 UTC (permalink / raw)


On Tue, 29 Feb 2000, Jon S Anthony wrote:
> Brian Rogoff wrote:
> > I guess OCaml isn't an FP then. Charles?
> 
> Well, he already claimed it was, so there must be some other
> feature(s) of direct Lisp family members that excludes them in his
> taxonomy.  I see OCaml also has assignment.

Yes. OCaml and SML both have references, mutable arrays, and exceptions, 
which mean they are not "pure" FPs like Haskell and Clean, and much closer 
to languages like Scheme. 

My view (grunt programmer in the trenches) is that we judge a language by
its support for a particular style, and don't worry about pure/impure
distinctions. 

So, IMO Ada supports the FP style better than C or C++, though Ada 83 
doesn't clearly do better since it doesn't have access to subprogram and 
has to always use generics whereas C can use function pointers. 

Lisp (ANSI CL), Scheme and the MLs all support FP style *much* better than 
those languages without first class functions. To me, first class
functions are the sine-qua-non of FP, so these are all FPLs. 

Some might argue that Haskell and Clean do best of all because they are
lazy (a little lie; really "non-strict") by default. I don't have enough 
practical experience here, when I tried to use Haskell in anger I found it
way too slow. 

I apply the same criteria to OOP, logic/relational style, etc. 

Common Lisp and C++ are interesting in that they support "staged programming" 
or partial evaluation directly in the language, via procedural macros and 
templates respectively. Kinda cool, but I understand the Ada position on
these features and how they impact maintainability. As I understand it,
the consensus in the Lisp community is that macros are to be used
sparingly. 

-- Brian






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

* Re: Looking for Ada Technique Name and References
  2000-02-29  0:00                   ` Jon S Anthony
  2000-02-29  0:00                     ` Brian Rogoff
@ 2000-03-04  0:00                     ` Nick Roberts
  1 sibling, 0 replies; 25+ messages in thread
From: Nick Roberts @ 2000-03-04  0:00 UTC (permalink / raw)


And Haskell (which is a bit bizarre).

--
Nick Roberts
http://www.adapower.com/lab/adaos

"Jon S Anthony" <jsa@synquiry.com> wrote in message
news:38BC3496.26FE@synquiry.com...

> Then again, he seems to exclude Scheme as well.  Shrug.







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

end of thread, other threads:[~2000-03-04  0:00 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <88kegp$iso$1@coward.ks.cc.utah.edu>
     [not found] ` <88kh6q$j4j$1@coward.ks.cc.utah.edu>
2000-02-18  0:00   ` Looking for Ada Technique Name and References Tucker Taft
2000-02-21  0:00   ` Diana Webster
2000-02-22  0:00     ` John Halleck
2000-02-22  0:00       ` Vladimir Olensky
2000-02-22  0:00         ` John Halleck
2000-02-22  0:00       ` tmoran
2000-02-22  0:00         ` David Starner
2000-02-23  0:00           ` tmoran
2000-02-23  0:00       ` Nick Roberts
2000-02-22  0:00         ` Jon S Anthony
2000-02-28  0:00           ` Charles D. Hixson
2000-02-28  0:00             ` Jon S Anthony
2000-02-29  0:00               ` Charles Hixson
2000-02-29  0:00                 ` Brian Rogoff
2000-02-29  0:00                   ` Jon S Anthony
2000-02-29  0:00                     ` Brian Rogoff
2000-02-29  0:00                       ` Jon S Anthony
2000-03-01  0:00                         ` Brian Rogoff
2000-03-01  0:00                           ` Jon S Anthony
2000-03-01  0:00                         ` Charles Hixson
2000-03-04  0:00                     ` Nick Roberts
2000-02-29  0:00                   ` Wes Groleau
2000-02-29  0:00                     ` Gautier
2000-03-01  0:00                       ` Wes Groleau
2000-02-22  0:00   ` Gautier

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