From: Jürgen Böhm
Subject: My 2nd Lisp program....
Date: 
Message-ID: <3B1655D4.C2FDB836@gmx.net>
Hello,

Please excuse me for posting a program that does such a simple thing
using so much lines of code, but when I tried to write the program it
broke down exactly in the way, you see below.

The main function is "make-triangular-form" which receives a
two-dimensional array of numbers and produces by adding multiples of
rows together an "upper triangular form" - that is in the ith column all
rows below the ith contain zero. (also first step in Gaussian
Elimination).

Now I have some questions (regarding the program):

1) Would you too break this up into several functions ?

2) What happens when arrays are returned or given as arguments: Is it
only a pointer to the array that is given or returned (like in
MAPLE-language or in a similar written C/C++ program), or is the whole
array copied ?

3) If the whole array is copied, what do I have to write/code so that
only a pointer to the array is given/returned ?

Secondly, I have some general questions:

A) For those who are acquainted with MAPLE-language: Would it not be
preferable to have a language with the power/expressiveness of LISP, but
in a MAPLE like syntax, which should not be impossible. (In general I
found it quite convenient to program in a language where I dont need
special editors for indenting, and where I can conveniently scribble
code into the editor which I finally put into correct form, but with
illegal syntax in between. In LISP Editors (i use the personal version
of LISPWORKS) one is always in an awkward situation with unfinished
code, because it needs to be indented to understand it, yet one can not
call Editors indentation function on incomplete expressions....ok,
enough whining)

B) Is there someone who (secretly...) uses LISP but with a precompiler
to give it a more MAPLE-language/Pascal-like form ...?


==========================================================================================

(defun make-triangular-form (a)

  (let ((m (array-dimension a 0)))

    (loop for j upfrom 0

          while (< j (min m (array-dimension a 1)))

          finally (return a)

          do (setf a (lower-to-zero a j)))))


(defun lower-to-zero (a col)

  (let ((m (array-dimension a 0))  

        (a (do-pivot-swap a col)))

    (if (/= 0 (aref a col col))

        (loop for i upfrom (1+ col)

              while (< i m)
          
              finally (return a)
              
              do (setf a (add-to-zero a col i)))

      a)))


(defun do-pivot-swap (a col)

  (let* ((m (array-dimension a 0))

        (n (array-dimension a 1))

        (i0 (loop for i upfrom col

                  while (and (< i m) (= 0 (aref a i col)))

                  finally (return i))))

    (if (and (< i0 m) (/= 0 (aref a i0 col)))

        (loop for j upfrom col

              while (< j n)

              finally (return a)
              
              do (let ((mem (aref a col j)))

                   (setf (aref a col j) (aref a i0 j))
                            
                   (setf (aref a i0 j) mem)))

      a)))




(defun add-to-zero (a col i)

  (let ((n (array-dimension a 1))
        
        (mult (/ (aref a i col) (aref a col col))))

    (loop for j upfrom col

          while (< j n)

          do (setf (aref a i j) (- (aref a i j) (* mult (aref a col
j))))

          finally (return a))))
    


(setf arr1 (make-array '(2 3) :initial-contents '((1 1 1) (2 1 3))))

(setf arr2 (make-array '(3 3) :initial-contents '((2 1 5) (2 1 3) (3 3
6))))

==============================================================================
 
-----------------------------------------------------------------------
Dipl.-Math. Jürgen Böhm                        http://www.aviduratas.de

"At a time when so many scholars are calculating, is it not desirable,
that some, who can, dream ?" R. Thom

From: Christopher J. Vogt
Subject: Re: My 2nd Lisp program....
Date: 
Message-ID: <3B16649B.5F4B1FAE@computer.org>
J�rgen B�hm wrote:
> [ ... ]

> 2) What happens when arrays are returned or given as arguments: Is it
> only a pointer to the array that is given or returned (like in
> MAPLE-language or in a similar written C/C++ program), or is the whole
> array copied ?

The array is not copied.  So, in your code, you really don't need to return
the array.

> [ ... ]

> A) For those who are acquainted with MAPLE-language: Would it not be
> preferable to have a language with the power/expressiveness of LISP, but
> in a MAPLE like syntax, which should not be impossible. (In general I
> found it quite convenient to program in a language where I dont need
> special editors for indenting, and where I can conveniently scribble
> code into the editor which I finally put into correct form, but with
> illegal syntax in between. In LISP Editors (i use the personal version
> of LISPWORKS) one is always in an awkward situation with unfinished
> code, because it needs to be indented to understand it, yet one can not
> call Editors indentation function on incomplete expressions....ok,
> enough whining)

Rather than just hitting the [return] at the end of a line, either
follow [return] with a [tab], or use <ctrl>[return] instead.  This will indent
the code as you write it (if I understand your problem).

[ ... ]

A few comments on your code.  Don't leave blank lines, this makes the code
more difficult to read.
> 
> (defun make-triangular-form (a)
>   (let ((m (array-dimension a 0)))
>     (loop for j upfrom 0
>           while (< j (min m (array-dimension a 1)))
>           finally (return a)
>           do (setf a (lower-to-zero a j)))))

When using loop, I don't ever precede it with a let, but rather I use the with
keyword.  Also the for keyword can also take a below keyword, rather than
using while.  And as mentioned above, you don't need to return the array, or
setf it so the code could look like this:

(defun make-triangular-form (a)
  (loop with m = (array-dimension a 0)
        for j from 0 below (min m (array-dimension a 1)) do
     (lower-to-zero a j)))

> [ ... ]

> (setf arr1 (make-array '(2 3) :initial-contents '((1 1 1) (2 1 3))))
> 
> (setf arr2 (make-array '(3 3) :initial-contents '((2 1 5) (2 1 3) (3 3 6))))

You should use defparameter (or maybe defvar) instead of setf, and you shoule
*ALWAYS* use stars around special variables, like this:
(defparameter *arr1* (make-array '(2 3) :initial-contents '((1 1 1) (2 1 3))))
(defparameter *arr2* (make-array '(3 3) :initial-contents '((2 1 5) (2 1 3) (3 3 6))))
From: Kent M Pitman
Subject: Re: My 2nd Lisp program....
Date: 
Message-ID: <sfwd78pmsa2.fsf@world.std.com>
J�rgen B�hm <··········@gmx.net> writes:

> The main function is "make-triangular-form" [...]
> Now I have some questions (regarding the program):
> 
> 1) Would you too break this up into several functions ?

If it makes it more readable (and it plainly does), then yes.  You can
always use an INLINE declaration to re-integrate the code for most
implementations if it turns out to be too slow for your use.  Never
let efficiency concerns get in the way of writing a clear program
until you're sure efficiency is the bottleneck keeping you from having
an efficient delivered application.  Make them first clear and correct,
then efficient.
 
> 2) What happens when arrays are returned or given as arguments: Is it
> only a pointer to the array that is given

Yes.

> or returned (like in
> MAPLE-language or in a similar written C/C++ program), or is the whole
> array copied ?

No.
 
> 3) If the whole array is copied, what do I have to write/code so that
> only a pointer to the array is given/returned ?

N/A

> Secondly, I have some general questions:
> 
> A) For those who are acquainted with MAPLE-language: Would it not be
> preferable to have a language with the power/expressiveness of LISP, but
> in a MAPLE like syntax, which should not be impossible.

Most people familiar with Lisp find there is good technical reason for the
existing syntax.  However, you can write a pre-processor if you want.
MACSYMA, another symbolic algebra program you probably know of, allows you
to work fairly flexibly in both Lisp and Macsyma syntaxes, depending on
your need.

> (In general I
> found it quite convenient to program in a language where I dont need
> special editors for indenting, and where I can conveniently scribble
> code into the editor which I finally put into correct form, but with
> illegal syntax in between. In LISP Editors (i use the personal version
> of LISPWORKS) one is always in an awkward situation with unfinished
> code, because it needs to be indented to understand it, yet one can not
> call Editors indentation function on incomplete expressions....ok,
> enough whining)

Sure you can.  TAB will indent any given line relative to the
previous.  Also, any parent-balanced sub-expression can be indented by
putting the cursor in front of that balanced pair and pressing
Control-Meta-q, regardless of whether the text before or after that
expression is well-formed.  Emacs is extraordinarily tolerant of ill-formed
text.
 
> B) Is there someone who (secretly...) uses LISP but with a precompiler
> to give it a more MAPLE-language/Pascal-like form ...?

Probably.  But not me.  Check out the ALU site www.alu.org looking for
contributed libraries.  You may find one that provides an infix parser,
and maybe even one that provides a whole language preprocessor.  Or you
may not.  I think I've seen things like that floating around, but can't
remember where.  It's a long tradition in Lisp for such things to exist,
going back to Vaughan Pratt's CGOL, which was a thing that ran in Maclisp
in the late 1970's and offered infix syntax for that dialect.
From: Chris Riesbeck
Subject: Re: My 2nd Lisp program....
Date: 
Message-ID: <riesbeck-EEC506.12421131052001@news.it.nwu.edu>
In article <···············@world.std.com>, Kent M Pitman 
<······@world.std.com> wrote:

>J�rgen B�hm <··········@gmx.net> writes:
>
>> B) Is there someone who (secretly...) uses LISP but with a precompiler
>> to give it a more MAPLE-language/Pascal-like form ...?
>
>... It's a long tradition in Lisp for such things to exist,
>going back to Vaughan Pratt's CGOL, which was a thing that ran in Maclisp
>in the late 1970's and offered infix syntax for that dialect

And MLISP at Stanford in the early 70's. 

My impression is that Algol-like syntax for general 
Lisp programming died out by the 80's, and only exists now
as one-person pet projects, and front-ends for specialized 
tools with Lisp hidden inside. Is that an accurate
impression?
From: Barry Margolin
Subject: Re: My 2nd Lisp program....
Date: 
Message-ID: <iAxR6.15$Ij4.373@burlma1-snr2>
In article <······························@news.it.nwu.edu>,
Chris Riesbeck  <········@cs.northwestern.edu> wrote:
>My impression is that Algol-like syntax for general 
>Lisp programming died out by the 80's, and only exists now
>as one-person pet projects, and front-ends for specialized 
>tools with Lisp hidden inside. Is that an accurate
>impression?

Dylan has Pascal- or Ada-style syntax, but semantics much closer to Lisp.
The original Dylan specification used Lisp-like syntax as well, but they
changed it to make the language more palatable to the masses.

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Chris Riesbeck
Subject: Re: My 2nd Lisp program....
Date: 
Message-ID: <riesbeck-59A053.12054601062001@news.it.nwu.edu>
In article <················@burlma1-snr2>, Barry Margolin 
<······@genuity.net> wrote:

>In article <······························@news.it.nwu.edu>,
>Chris Riesbeck  <········@cs.northwestern.edu> wrote:
>>My impression is that Algol-like syntax for general 
>>Lisp programming died out by the 80's, and only exists now
>>as one-person pet projects, and front-ends for specialized 
>>tools with Lisp hidden inside. Is that an accurate
>>impression?
>
>Dylan has Pascal- or Ada-style syntax, but semantics much closer to Lisp.
>The original Dylan specification used Lisp-like syntax as well, but they
>changed it to make the language more palatable to the masses.

Ah, yes, of course. But to that extent, there's a lot
of Lisp in Java too. I was thinking specifically of things
like CGOL and MLISP that were meant to make Lisp
more palatable, but not to deny Lisp-hood.
From: Jochen Schmidt
Subject: Re: My 2nd Lisp program....
Date: 
Message-ID: <9f8lcp$2qu3f$1@ID-22205.news.dfncis.de>
Chris Riesbeck wrote:

> In article <················@burlma1-snr2>, Barry Margolin
> <······@genuity.net> wrote:
> 
>>In article <······························@news.it.nwu.edu>,
>>Chris Riesbeck  <········@cs.northwestern.edu> wrote:
>>>My impression is that Algol-like syntax for general
>>>Lisp programming died out by the 80's, and only exists now
>>>as one-person pet projects, and front-ends for specialized
>>>tools with Lisp hidden inside. Is that an accurate
>>>impression?
>>
>>Dylan has Pascal- or Ada-style syntax, but semantics much closer to Lisp.
>>The original Dylan specification used Lisp-like syntax as well, but they
>>changed it to make the language more palatable to the masses.
> 
> Ah, yes, of course. But to that extent, there's a lot
> of Lisp in Java too. I was thinking specifically of things
> like CGOL and MLISP that were meant to make Lisp
> more palatable, but not to deny Lisp-hood.

I think that was what Barry meant - Dylan users don't deny the Lisp-hood of
their language but I don't know any Java-User that would not feel offended 
if someone would say that Java is very similar to Lisp. Besides that - I 
personally do not find Java very similar to Lisp.

Regards,
Jochen
From: Janis Dzerins
Subject: Re: My 2nd Lisp program....
Date: 
Message-ID: <87lmnded2v.fsf@asaka.latnet.lv>
J�rgen B�hm <··········@gmx.net> writes:

> A) For those who are acquainted with MAPLE-language: Would it not be
> preferable to have a language with the power/expressiveness of LISP, but
> in a MAPLE like syntax, which should not be impossible. (In general I
> found it quite convenient to program in a language where I dont need
> special editors for indenting, and where I can conveniently scribble
> code into the editor which I finally put into correct form, but with
> illegal syntax in between. In LISP Editors (i use the personal version
> of LISPWORKS) one is always in an awkward situation with unfinished
> code, because it needs to be indented to understand it, yet one can not
> call Editors indentation function on incomplete expressions....ok,
> enough whining)

Use your editor better. I guess you don't use M-( and M-), and other
combinations for working with sexps.

So here's what you do -- learn what these key combinations do:
M-(
M-)
C-M-f
C-M-b
C-M-u
C-M-d
C-M-k
C-M-del
C-M-t
C-M-q
C-M-/
C-j

These are the ones I use *very* frequently (and with prefix
args). Funny I don't even press '(' without meta key anymore :)

Some less frequently used are:

····@
C-M-a
C-M-e
C-M-h
C-M-l

I like Emacs M-) key better than in LispWorks editor, but that's
fixable I think.

> B) Is there someone who (secretly...) uses LISP but with a precompiler
> to give it a more MAPLE-language/Pascal-like form ...?

One of the powers of Lisp are in its editability. Why would we want to
give up that?

-- 
Janis Dzerins

  If million people say a stupid thing it's still a stupid thing.