From: ·······@cad.strath.ac.uk
Subject: Q: looking for simplified version of this code.
Date: 
Message-ID: <91vsqr$bv6$1@nnrp1.deja.com>
Merry Christmas to all~!

Before take a nice holiday, could anyone help me solve this problem?
Below code works, but looks little bit odd.
Is there anyways to make this code more simple?
Thanks for your help. =)

Sungwoo

;--------------------------------------
(setf first-max (if (zerop (length copy-array))
                    0
                    (aref copy-array 0))
        second-max (if (< (length copy-array) 2)
                     0
                     (aref copy-array 1))
        third-max (if (< (length copy-array) 3)
                    0
                    (aref copy-array 2))
        fourth-max (if (< (length copy-array) 4)
                     0
                     (aref copy-array 3)))


Sent via Deja.com
http://www.deja.com/

From: JP Massar
Subject: Re: Q: looking for simplified version of this code.
Date: 
Message-ID: <3a4396a0.47508886@news.mindspring.com>
On Fri, 22 Dec 2000 15:43:24 GMT, ·······@cad.strath.ac.uk wrote:
 
(let ((alen (length copy-array)))
   (flet ((aval (n) (if (< alen n) 0 (aref copy-array (1- n)))))
     (setf first-max (aval 1) second-max (aval 2) 
           third-max (aval 3) fourth-max (aval 4))))

>
>Sungwoo
>
>;--------------------------------------
>(setf first-max (if (zerop (length copy-array))
>                    0
>                    (aref copy-array 0))
>        second-max (if (< (length copy-array) 2)
>                     0
>                     (aref copy-array 1))
>        third-max (if (< (length copy-array) 3)
>                    0
>                    (aref copy-array 2))
>        fourth-max (if (< (length copy-array) 4)
>                     0
>                     (aref copy-array 3)))
>
>
>Sent via Deja.com
>http://www.deja.com/
From: ·······@cad.strath.ac.uk
Subject: Re: Q: looking for simplified version of this code.
Date: 
Message-ID: <920c4m$p2k$1@nnrp1.deja.com>
> (let ((alen (length copy-array)))
>    (flet ((aval (n) (if (< alen n) 0 (aref copy-array (1- n)))))
>      (setf first-max (aval 1) second-max (aval 2)
>            third-max (aval 3) fourth-max (aval 4))))
>

Hmm, I see.
Thanks, =)

Sungwoo


Sent via Deja.com
http://www.deja.com/
From: SRS
Subject: Re: Q: looking for simplified version of this code.
Date: 
Message-ID: <9206gs$ka3$1@nnrp1.deja.com>
In article <············@nnrp1.deja.com>,
  ·······@cad.strath.ac.uk wrote:
> Merry Christmas to all~!
>
> Before take a nice holiday, could anyone help me solve this problem?
> Below code works, but looks little bit odd.
> Is there anyways to make this code more simple?
> Thanks for your help. =)
>
> Sungwoo
>
> ;--------------------------------------
> (setf first-max (if (zerop (length copy-array))
>                     0
>                     (aref copy-array 0))
>         second-max (if (< (length copy-array) 2)
>                      0
>                      (aref copy-array 1))
>         third-max (if (< (length copy-array) 3)
>                     0
>                     (aref copy-array 2))
>         fourth-max (if (< (length copy-array) 4)
>                      0
>                      (aref copy-array 3)))
>
> Sent via Deja.com
> http://www.deja.com/
>

Well, you could use a vector instead of four distinct variables:

    (setf max-vector (make-array 4 :initial-element 0))
    (replace max-vector copy-array)

-- SRS


Sent via Deja.com
http://www.deja.com/
From: ·······@cad.strath.ac.uk
Subject: Re: Q: looking for simplified version of this code.
Date: 
Message-ID: <920ch1$phk$1@nnrp1.deja.com>
> Well, you could use a vector instead of four distinct variables:
>
>     (setf max-vector (make-array 4 :initial-element 0))
>     (replace max-vector copy-array :end1 (length copy-array))
>

Thanks, =)

Sungwoo


Sent via Deja.com
http://www.deja.com/