From: Sungwoo, Lim
Subject: How can I extend array
Date: 
Message-ID: <301120001638083887%sungwoo@cad.strath.ac.uk>
Hello,  

(loop for coord-x from first-x to last-x
      collect (list coord-x (setf coord-y (+ (* constant-a coord-x)
                                             aconstant-b)) coord-z)

Above loop gives me a list, but I need an array... To do this,
perhaps I should incrementally change the value 'n' until the drawing
of a sketch stroke is finished.

Let's say that 
   n = last-x - first-x (the number of total point of stroke).

Then, I want to create array rooms and extend them incrementally.

   (setf n (+ n 1))
   (make-array '(n 3)) 

However, obviously this doesn't work. 
Common Lisp complains that the 'n' is not of the expected type REAL.  ;(
How can I incrementally extend an array and put the above three
coordinates in the array?
Thanks for your help.

Sungwoo

From: Barry Margolin
Subject: Re: How can I extend array
Date: 
Message-ID: <KyvV5.13$DL1.32@burlma1-snr2>
In article <··························@cad.strath.ac.uk>,
Sungwoo, Lim <·······@cad.strath.ac.uk> wrote:
>Hello,  
>
>(loop for coord-x from first-x to last-x
>      collect (list coord-x (setf coord-y (+ (* constant-a coord-x)
>                                             aconstant-b)) coord-z)
>
>Above loop gives me a list, but I need an array... To do this,
>perhaps I should incrementally change the value 'n' until the drawing
>of a sketch stroke is finished.
>
>Let's say that 
>   n = last-x - first-x (the number of total point of stroke).
>
>Then, I want to create array rooms and extend them incrementally.
>
>   (setf n (+ n 1))
>   (make-array '(n 3)) 
>
>However, obviously this doesn't work. 
>Common Lisp complains that the 'n' is not of the expected type REAL.  ;(

(make-array (list n 3))

>How can I incrementally extend an array and put the above three
>coordinates in the array?

See the ADJUST-ARRAY function.

-- 
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: Greg Menke
Subject: Re: How can I extend array
Date: 
Message-ID: <m3lmu1o0q1.fsf@mindspring.com>
> Then, I want to create array rooms and extend them incrementally.
> 
>    (setf n (+ n 1))
>    (make-array '(n 3)) 
> 
> However, obviously this doesn't work. 
> Common Lisp complains that the 'n' is not of the expected type REAL.  ;(
> How can I incrementally extend an array and put the above three
> coordinates in the array?

Try 

(make-array (list n 3))

Gregm
From: Janis Dzerins
Subject: Re: How can I extend array
Date: 
Message-ID: <87lmu173tj.fsf@asaka.latnet.lv>
Greg Menke <··············@zxy.mindspring.com> writes:

> > Then, I want to create array rooms and extend them incrementally.
> > 
> >    (setf n (+ n 1))
> >    (make-array '(n 3)) 
> > 
> > However, obviously this doesn't work. 
> > Common Lisp complains that the 'n' is not of the expected type REAL.  ;(
> > How can I incrementally extend an array and put the above three
> > coordinates in the array?
> 
> Try 
> 
> (make-array (list n 3))

Or (make-array `(,n 3))

Janis Dzerins
-- 
  Ever feel like life was a game and you had the wrong instruction book?
From: Sungwoo, Lim
Subject: Re: How can I extend array
Date: 
Message-ID: <301120001923219599%sungwoo@cad.strath.ac.uk>
Thanks guys, so I could get an array like this.

(setq ref-array (make-array (list (abs (- first-x last-x)) 3))) 

Other question was, how can I get the result as an array type rather
then list one. How could I put these coordinates (x, y, z) in the
array?

(loop for coord-x from first-x to last-x
      collect (list coord-x 
                    (setf coord-y (+ (* constant-a coord-x)
constant-b)) 
                    coord-z))

Any help please?

Sungwoo
From: Martti Halminen
Subject: Re: How can I extend array
Date: 
Message-ID: <3A2765AD.B8C1ADF0@solibri.com>
"Sungwoo, Lim" wrote:
> 
> Thanks guys, so I could get an array like this.
> 
> (setq ref-array (make-array (list (abs (- first-x last-x)) 3)))
> 
> Other question was, how can I get the result as an array type rather
> then list one. How could I put these coordinates (x, y, z) in the
> array?
> 
> (loop for coord-x from first-x to last-x
>       collect (list coord-x
>                     (setf coord-y (+ (* constant-a coord-x)
> constant-b))
>                     coord-z))

If producing some garbage isn't a problem, you could use the loop as a
:initial-contents argument to the make-array call.

If you want to avoid the intermediate list, use "do" instead of
"collect" and replace (list coord-x ... )
 with (setf (aref ref-array index 0) coord-x) etc.
 You'll need to add the index to the loop, too.

Generally, looks like reading some documentation on the loop macro might
be useful for you, there are usually examples of similar cases, too.

--
From: Sungwoo, Lim
Subject: Re: How can I extend array
Date: 
Message-ID: <011220001135300403%sungwoo@cad.strath.ac.uk>
In article <·················@solibri.com>, Martti Halminen
<···············@solibri.com> wrote:

> "Sungwoo, Lim" wrote:
> > 
> > Thanks guys, so I could get an array like this.
> > 
> > (setq ref-array (make-array (list (abs (- first-x last-x)) 3)))
> > 
> > Other question was, how can I get the result as an array type rather
> > then list one. How could I put these coordinates (x, y, z) in the
> > array?
> > 
> > (loop for coord-x from first-x to last-x
> >       collect (list coord-x
> >                     (setf coord-y (+ (* constant-a coord-x)
> > constant-b))
> >                     coord-z))
> 
> If producing some garbage isn't a problem, you could use the loop as a
> :initial-contents argument to the make-array call.
> 
> If you want to avoid the intermediate list, use "do" instead of
> "collect" and replace (list coord-x ... )
>  with (setf (aref ref-array index 0) coord-x) etc.
>  You'll need to add the index to the loop, too.
> 
> Generally, looks like reading some documentation on the loop macro might
> be useful for you, there are usually examples of similar cases, too.
> 
> --

Thanks for your help. =)
Now I modified my code as below.

(defun ref-straightline-array ()
  (setf constant-a (/ distance-firstandlast-y distance-firstandlast-x)) 
  (setf constant-b (- first-y (* constant-a first-x)))
  (setf coord-z 0)

  (cond ((>= distance-firstandlast-x distance-firstandlast-y)
         (and (setq ref-array (make-array (list distance-firstandlast-x
3)))
              (cond ((< first-x last-x)
                     (loop for coord-x from first-x to last-x
                           for ref-index from 0 to (-
distance-firstandlast-x 1)
                           do (setf (aref ref-array ref-index 0) 
                                    coord-x)
                           do (setf (aref ref-array ref-index 1) 
                                    (setf coord-y (+ (* constant-a
coord-x) constant-b))) 
                           do (setf (aref ref-array ref-index 2) 
                                    coord-z)))
                    (t (loop for coord-x from first-x downto last-x
                             for ref-index from 0 to (-
distance-firstandlast-x 1)
                             do (setf (aref ref-array ref-index 0) 
                                      coord-x)
                             do (setf (aref ref-array ref-index 1) 
                                      (setf coord-y (+ (* constant-a
coord-x) constant-b))) 
                             do (setf (aref ref-array ref-index 2) 
                                      coord-z))))))
        (t (and (setq ref-array (make-array (list
distance-firstandlast-y 3)))
                (cond ((< first-y last-y) 
                       (loop for coord-y from first-y to last-y
                             for ref-index from 0 to (-
distance-firstandlast-y 1)
                             do (setf (aref ref-array ref-index 0) 
                                      (setf coord-x (/ (- coord-y
constant-b) constant-a)))
                             do (setf (aref ref-array ref-index 1) 
                                      coord-y) 
                             do (setf (aref ref-array ref-index 2) 
                                      coord-z)))
                      (t (loop for coord-y from first-y downto last-y
                               for ref-index from 0 to (-
distance-firstandlast-y 1)
                               do (setf (aref ref-array ref-index 0) 
                                        (setf coord-x (/ (- coord-y
constant-b) constant-a)))
                               do (setf (aref ref-array ref-index 1) 
                                        coord-y) 
                               do (setf (aref ref-array ref-index 2) 
                                        coord-z))))))))

It seems to works. But I repeated some codes over and over in here.
Maybe there are some ways to optimise this silly codes?
Thanks in advance.

Sungwoo
From: Martti Halminen
Subject: Re: How can I extend array
Date: 
Message-ID: <3A27A42E.C374664D@solibri.com>
"Sungwoo, Lim" wrote:
>
> Now I modified my code as below.
> 
> (defun ref-straightline-array ()
>   (setf constant-a (/ distance-firstandlast-y distance-firstandlast-x))
>   (setf constant-b (- first-y (* constant-a first-x)))
>   (setf coord-z 0)
> 
>   (cond ((>= distance-firstandlast-x distance-firstandlast-y)
>          (and (setq ref-array (make-array (list distance-firstandlast-x
> 3)))
>               (cond ((< first-x last-x)
>                      (loop for coord-x from first-x to last-x
>                            for ref-index from 0 to (-
> distance-firstandlast-x 1)
>                            do (setf (aref ref-array ref-index 0)
>                                     coord-x)
>                            do (setf (aref ref-array ref-index 1)
>                                     (setf coord-y (+ (* constant-a
> coord-x) constant-b)))
>                            do (setf (aref ref-array ref-index 2)
>                                     coord-z)))
>                     (t (loop for coord-x from first-x downto last-x
>                              for ref-index from 0 to (-
> distance-firstandlast-x 1)
>                              do (setf (aref ref-array ref-index 0)
>                                       coord-x)
>                              do (setf (aref ref-array ref-index 1)
>                                       (setf coord-y (+ (* constant-a
> coord-x) constant-b)))
>                              do (setf (aref ref-array ref-index 2)
>                                       coord-z))))))
>         (t (and (setq ref-array (make-array (list
> distance-firstandlast-y 3)))
>                 (cond ((< first-y last-y)
>                        (loop for coord-y from first-y to last-y
>                              for ref-index from 0 to (-
> distance-firstandlast-y 1)
>                              do (setf (aref ref-array ref-index 0)
>                                       (setf coord-x (/ (- coord-y
> constant-b) constant-a)))
>                              do (setf (aref ref-array ref-index 1)
>                                       coord-y)
>                              do (setf (aref ref-array ref-index 2)
>                                       coord-z)))
>                       (t (loop for coord-y from first-y downto last-y
>                                for ref-index from 0 to (-
> distance-firstandlast-y 1)
>                                do (setf (aref ref-array ref-index 0)
>                                         (setf coord-x (/ (- coord-y
> constant-b) constant-a)))
>                                do (setf (aref ref-array ref-index 1)
>                                         coord-y)
>                                do (setf (aref ref-array ref-index 2)
>                                         coord-z))))))))
> 
> It seems to works. But I repeated some codes over and over in here.
> Maybe there are some ways to optimise this silly codes?

You could reduce the visual clutter a little:
- those "and"s are superfluous, cond already has an implicit progn
there.
- you can have several statements after a "do" keyword in loop, so leave
only the first do in each loop.
- if you leave the to -definition from ref-index away, it'll still get
incremented each time through the loop.

- If using an array really is necessary, I'd define a little help
function:
(defun put-coord (arr index x y z)
   (setf (aref arr index 0) x)
   (setf (aref arr index 1) y) 
    ...)
so the first loop would be

   (loop for coord-x from first-x to last-x
         for ref-index from 0
      do (put-coord ref-array ref-index coord-x 
                                        (+ (* const-a xoord-x) ...)
                                        coord-z)))
 - I'd more likely do each x y z triple as a vector or a struct, so the
ref-array would be a vector.


Another suggestion for style would be making clear for yourself which
variables are local, and which are special variables defined elsewhere.

The locals (for example your const-a, const-b etc.) should be defined
with let (unless they really are intended for use outside this defun,
too.)

The non-local stuff used here, for example first-x, last-x, should
rather be brought here as parameters for the function, instead of
sneaking them in from wherever they might be set as specials.

Also, it would be more stylish to return ref-array as the value of the
function, instead of as a side-effect.
 
   
--
From: Sungwoo, Lim
Subject: Re: How can I extend array
Date: 
Message-ID: <011220001438552081%sungwoo@cad.strath.ac.uk>
In article <·················@solibri.com>, Martti Halminen
<···············@solibri.com> wrote:

> "Sungwoo, Lim" wrote:
> >
> > Now I modified my code as below.
> > 
> > (defun ref-straightline-array ()
> >   (setf constant-a (/ distance-firstandlast-y distance-firstandlast-x))
> >   (setf constant-b (- first-y (* constant-a first-x)))
> >   (setf coord-z 0)
> > 
> >   (cond ((>= distance-firstandlast-x distance-firstandlast-y)
> >          (and (setq ref-array (make-array (list distance-firstandlast-x
> > 3)))
> >               (cond ((< first-x last-x)
> >                      (loop for coord-x from first-x to last-x
> >                            for ref-index from 0 to (-
> > distance-firstandlast-x 1)
> >                            do (setf (aref ref-array ref-index 0)
> >                                     coord-x)
> >                            do (setf (aref ref-array ref-index 1)
> >                                     (setf coord-y (+ (* constant-a
> > coord-x) constant-b)))
> >                            do (setf (aref ref-array ref-index 2)
> >                                     coord-z)))
> >                     (t (loop for coord-x from first-x downto last-x
> >                              for ref-index from 0 to (-
> > distance-firstandlast-x 1)
> >                              do (setf (aref ref-array ref-index 0)
> >                                       coord-x)
> >                              do (setf (aref ref-array ref-index 1)
> >                                       (setf coord-y (+ (* constant-a
> > coord-x) constant-b)))
> >                              do (setf (aref ref-array ref-index 2)
> >                                       coord-z))))))
> >         (t (and (setq ref-array (make-array (list
> > distance-firstandlast-y 3)))
> >                 (cond ((< first-y last-y)
> >                        (loop for coord-y from first-y to last-y
> >                              for ref-index from 0 to (-
> > distance-firstandlast-y 1)
> >                              do (setf (aref ref-array ref-index 0)
> >                                       (setf coord-x (/ (- coord-y
> > constant-b) constant-a)))
> >                              do (setf (aref ref-array ref-index 1)
> >                                       coord-y)
> >                              do (setf (aref ref-array ref-index 2)
> >                                       coord-z)))
> >                       (t (loop for coord-y from first-y downto last-y
> >                                for ref-index from 0 to (-
> > distance-firstandlast-y 1)
> >                                do (setf (aref ref-array ref-index 0)
> >                                         (setf coord-x (/ (- coord-y
> > constant-b) constant-a)))
> >                                do (setf (aref ref-array ref-index 1)
> >                                         coord-y)
> >                                do (setf (aref ref-array ref-index 2)
> >                                         coord-z))))))))
> > 
> > It seems to works. But I repeated some codes over and over in here.
> > Maybe there are some ways to optimise this silly codes?
> 
> You could reduce the visual clutter a little:
> - those "and"s are superfluous, cond already has an implicit progn
> there.
> - you can have several statements after a "do" keyword in loop, so leave
> only the first do in each loop.
> - if you leave the to -definition from ref-index away, it'll still get
> incremented each time through the loop.
> 
> - If using an array really is necessary, I'd define a little help
> function:
> (defun put-coord (arr index x y z)
>    (setf (aref arr index 0) x)
>    (setf (aref arr index 1) y) 
>     ...)
> so the first loop would be
> 
>    (loop for coord-x from first-x to last-x
>          for ref-index from 0
>       do (put-coord ref-array ref-index coord-x 
>                                         (+ (* const-a xoord-x) ...)
>                                         coord-z)))
>  - I'd more likely do each x y z triple as a vector or a struct, so the
> ref-array would be a vector.
> 
> 
> Another suggestion for style would be making clear for yourself which
> variables are local, and which are special variables defined elsewhere.
> 
> The locals (for example your const-a, const-b etc.) should be defined
> with let (unless they really are intended for use outside this defun,
> too.)
> 
> The non-local stuff used here, for example first-x, last-x, should
> rather be brought here as parameters for the function, instead of
> sneaking them in from wherever they might be set as specials.
> 
> Also, it would be more stylish to return ref-array as the value of the
> function, instead of as a side-effect.
>  
>    
> --

Thanks for very detailed comment. =)
So I modified the code as follow. 
I couldn't fully understand below comment. Do you mean that I have to
define a function for non-local stuff, and then adapt the functions...?
Could you give me one simple example please? =.=

> The non-local stuff used here, for example first-x, last-x, should
> rather be brought here as parameters for the function, instead of
> sneaking them in from wherever they might be set as specials.

The other thing is that I tried to return ref-array as the value of the
function like below. But I am not sure this is right way..

BTW, thanks very much indeed.

Sungwoo

;---------------------------------------------
(defun ref-straightline-array ()                                   
  (let ((constant-a (/ distance-firstandlast-y
distance-firstandlast-x)) 
        (constant-b (- first-y (* constant-a first-x)))))

  (setq ref-array
        (cond ((>= distance-firstandlast-x distance-firstandlast-y)
               (make-array (list distance-firstandlast-x 3))
               (cond ((< first-x last-x)
                      (loop for coord-x from first-x to last-x
                            for ref-index from 0
                            do (put-coord ref-array ref-index coord-x 
                                                              (setf
coord-y (+ (* constant-a coord-x) constant-b))
                                                              coord-z)))
                     (t (loop for coord-x from first-x downto last-x
                              for ref-index from 0
                              do (put-coord ref-array ref-index coord-x 
                                                                (setf
coord-y (+ (* constant-a coord-x) constant-b))
                                                               
coord-z)))
              (t (make-array (list distance-firstandlast-y 3))
                 (cond ((< first-y last-y) 
                        (loop for coord-y from first-y to last-y
                              for ref-index from 0
                              do (put-coord ref-array ref-index (setf
coord-x (/ (- coord-y constant-b) constant-a)) 
                                                                coord-y
                                                               
coord-z)))
                       (t (loop for coord-y from first-y downto last-y
                                for ref-index from 0
                              do (put-coord ref-array ref-index (setf
coord-x (/ (- coord-y constant-b) constant-a)) 
                                                                coord-y
                                                               
coord-z))))))))))

(defun put-coord (arr index x y z) 
  (setf (aref arr index 0) x)
  (setf (aref arr index 1) y) 
  (setf (aref arr index 2) z)) 
;-------------------------------------------
From: Martti Halminen
Subject: Re: How can I extend array
Date: 
Message-ID: <3A27BE89.3E089314@solibri.com>
"Sungwoo, Lim" wrote:

> I couldn't fully understand below comment. Do you mean that I have to
> define a function for non-local stuff, and then adapt the functions...?
> Could you give me one simple example please? =.=
> > The non-local stuff used here, for example first-x, last-x, should
> > rather be brought here as parameters for the function, instead of
> > sneaking them in from wherever they might be set as specials.
> 
> The other thing is that I tried to return ref-array as the value of the
> function like below. But I am not sure this is right way..



(defun ref-straightline-array (first-x first-y last-x last-y ...)
  "This would be a good place to document this function"
  (let ((constant-a (...))
        ...
        (ref-array (make-array (list (max
distance-firstandlast-x                                          
distance-firstandlast-y)
                                      3))))
     ;; the current cond stuff here (without the make-array)
     ...
     ref-array)) ; <-- here we return the value, still from inside the
let.

- Note that here ref-array is not global, so you'll have to use (and
store) the return value of this function.


- In your (setq ref-array ...) there is a problem: you can have several
  forms in a cond branch, and they'll all get executed, but the value
returned is the last one, so you'd have to add a return clause to your
loops.



--

(leaving for the weekend, so no more answers today.)
From: Sungwoo, Lim
Subject: Re: How can I extend array
Date: 
Message-ID: <011220001616173582%sungwoo@cad.strath.ac.uk>
In article <·················@solibri.com>, Martti Halminen
<···············@solibri.com> wrote:

> "Sungwoo, Lim" wrote:
> 
> > I couldn't fully understand below comment. Do you mean that I have to
> > define a function for non-local stuff, and then adapt the functions...?
> > Could you give me one simple example please? =.=
> > > The non-local stuff used here, for example first-x, last-x, should
> > > rather be brought here as parameters for the function, instead of
> > > sneaking them in from wherever they might be set as specials.
> > 
> > The other thing is that I tried to return ref-array as the value of the
> > function like below. But I am not sure this is right way..
> 
> 
> 
> (defun ref-straightline-array (first-x first-y last-x last-y ...)
>   "This would be a good place to document this function"
>   (let ((constant-a (...))
>         ...
>         (ref-array (make-array (list (max
> distance-firstandlast-x                                          
> distance-firstandlast-y)
>                                       3))))
>      ;; the current cond stuff here (without the make-array)
>      ...
>      ref-array)) ; <-- here we return the value, still from inside the
> let.
> 
> - Note that here ref-array is not global, so you'll have to use (and
> store) the return value of this function.
> 
> 
> - In your (setq ref-array ...) there is a problem: you can have several
>   forms in a cond branch, and they'll all get executed, but the value
> returned is the last one, so you'd have to add a return clause to your
> loops.
> 
> 
> 
> --
> 
> (leaving for the weekend, so no more answers today.)

Thanks again, have a nice weekend.

Now I modified the code as below based on the Martti's comment.
Just want to make sure that did I used 'let' correctly to handle some
variables as a local? 
Thanks,

Sungwoo

;-------------------------------------------------------
(defun ref-straightline-array ()                                   
  (let ((constant-a (/ distance-firstandlast-y
distance-firstandlast-x)) 
        (constant-b (- first-y (* constant-a first-x)))
        (ref-array (make-array (list (max distance-firstandlast-x
distance-firstandlast-y) 3))))
        (cond ((>= distance-firstandlast-x distance-firstandlast-y)
               (cond ((< first-x last-x)
                      (loop for coord-x from first-x to last-x
                            for ref-index from 0
                            do (put-coord ref-array ref-index coord-x 
                                                              (setf
coord-y (+ (* constant-a coord-x) constant-b))
                                                              coord-z)))
                     (t (loop for coord-x from first-x downto last-x
                              for ref-index from 0
                              do (put-coord ref-array ref-index coord-x 
                                                                (setf
coord-y (+ (* constant-a coord-x) constant-b))
                                                               
coord-z)))
              (t (cond ((< first-y last-y) 
                        (loop for coord-y from first-y to last-y
                              for ref-index from 0
                              do (put-coord ref-array ref-index (setf
coord-x (/ (- coord-y constant-b) constant-a)) 
                                                                coord-y
                                                               
coord-z)))
                       (t (loop for coord-y from first-y downto last-y
                                for ref-index from 0
                              do (put-coord ref-array ref-index (setf
coord-x (/ (- coord-y constant-b) constant-a)) 
                                                                coord-y
                                                               
coord-z))))))))
    ref-array))

(defun put-coord (arr index x y z) 
  (setf (aref arr index 0) x)
  (setf (aref arr index 1) y) 
  (setf (aref arr index 2) z)) 
;----------------------------------------------------------
From: John Clonts
Subject: Re: How can I extend array
Date: 
Message-ID: <3A27C9D6.62750638@mastnet.net>
Sungwoo, Lim wrote:
> 
> In article <·················@solibri.com>, Martti Halminen
> <···············@solibri.com> wrote:
> 
> > "Sungwoo, Lim" wrote:
> > >
> > > Now I modified my code as below.
> > >
> > > (defun ref-straightline-array ()
> > >   (setf constant-a (/ distance-firstandlast-y distance-firstandlast-x))
> > >   (setf constant-b (- first-y (* constant-a first-x)))
> > >   (setf coord-z 0)
> > >
> > >   (cond ((>= distance-firstandlast-x distance-firstandlast-y)
> > >          (and (setq ref-array (make-array (list distance-firstandlast-x
> > > 3)))
> > >               (cond ((< first-x last-x)
> > >                      (loop for coord-x from first-x to last-x
> > >                            for ref-index from 0 to (-
> > > distance-firstandlast-x 1)
> > >                            do (setf (aref ref-array ref-index 0)
> > >                                     coord-x)
> > >                            do (setf (aref ref-array ref-index 1)
> > >                                     (setf coord-y (+ (* constant-a
> > > coord-x) constant-b)))
> > >                            do (setf (aref ref-array ref-index 2)
> > >                                     coord-z)))
> > >                     (t (loop for coord-x from first-x downto last-x
> > >                              for ref-index from 0 to (-
> > > distance-firstandlast-x 1)
> > >                              do (setf (aref ref-array ref-index 0)
> > >                                       coord-x)
> > >                              do (setf (aref ref-array ref-index 1)
> > >                                       (setf coord-y (+ (* constant-a
> > > coord-x) constant-b)))
> > >                              do (setf (aref ref-array ref-index 2)
> > >                                       coord-z))))))
> > >         (t (and (setq ref-array (make-array (list
> > > distance-firstandlast-y 3)))
> > >                 (cond ((< first-y last-y)
> > >                        (loop for coord-y from first-y to last-y
> > >                              for ref-index from 0 to (-
> > > distance-firstandlast-y 1)
> > >                              do (setf (aref ref-array ref-index 0)
> > >                                       (setf coord-x (/ (- coord-y
> > > constant-b) constant-a)))
> > >                              do (setf (aref ref-array ref-index 1)
> > >                                       coord-y)
> > >                              do (setf (aref ref-array ref-index 2)
> > >                                       coord-z)))
> > >                       (t (loop for coord-y from first-y downto last-y
> > >                                for ref-index from 0 to (-
> > > distance-firstandlast-y 1)
> > >                                do (setf (aref ref-array ref-index 0)
> > >                                         (setf coord-x (/ (- coord-y
> > > constant-b) constant-a)))
> > >                                do (setf (aref ref-array ref-index 1)
> > >                                         coord-y)
> > >                                do (setf (aref ref-array ref-index 2)
> > >                                         coord-z))))))))
> > >
> > > It seems to works. But I repeated some codes over and over in here.
> > > Maybe there are some ways to optimise this silly codes?
> >
> > You could reduce the visual clutter a little:
> > - those "and"s are superfluous, cond already has an implicit progn
> > there.
> > - you can have several statements after a "do" keyword in loop, so leave
> > only the first do in each loop.
> > - if you leave the to -definition from ref-index away, it'll still get
> > incremented each time through the loop.
> >
> > - If using an array really is necessary, I'd define a little help
> > function:
> > (defun put-coord (arr index x y z)
> >    (setf (aref arr index 0) x)
> >    (setf (aref arr index 1) y)
> >     ...)
> > so the first loop would be
> >
> >    (loop for coord-x from first-x to last-x
> >          for ref-index from 0
> >       do (put-coord ref-array ref-index coord-x
> >                                         (+ (* const-a xoord-x) ...)
> >                                         coord-z)))
> >  - I'd more likely do each x y z triple as a vector or a struct, so the
> > ref-array would be a vector.
> >
> >
> > Another suggestion for style would be making clear for yourself which
> > variables are local, and which are special variables defined elsewhere.
> >
> > The locals (for example your const-a, const-b etc.) should be defined
> > with let (unless they really are intended for use outside this defun,
> > too.)
> >
> > The non-local stuff used here, for example first-x, last-x, should
> > rather be brought here as parameters for the function, instead of
> > sneaking them in from wherever they might be set as specials.
> >
> > Also, it would be more stylish to return ref-array as the value of the
> > function, instead of as a side-effect.
> >
> >
> > --
> 
> Thanks for very detailed comment. =)
> So I modified the code as follow.
> I couldn't fully understand below comment. Do you mean that I have to
> define a function for non-local stuff, and then adapt the functions...?
> Could you give me one simple example please? =.=
> 
> > The non-local stuff used here, for example first-x, last-x, should
> > rather be brought here as parameters for the function, instead of
> > sneaking them in from wherever they might be set as specials.
> 
> The other thing is that I tried to return ref-array as the value of the
> function like below. But I am not sure this is right way..
> 
> BTW, thanks very much indeed.
> 
> Sungwoo
> 
> ;---------------------------------------------
> (defun ref-straightline-array ()
>   (let ((constant-a (/ distance-firstandlast-y 
> distance-firstandlast-x))
>         (constant-b (- first-y (* constant-a first-x)))))
> 

In addition to martti's comments to you, I would point out that the
above (let ...) expression has no effect.  Therefore you probably have
global variables called constant-a and constant-b, and you will
(eventually) be surprised that their values do not change.

Was this just a typo?  If not, write back and someone (perhaps me) will
explain how let works.

Cheers,
John
From: Sungwoo, Lim
Subject: Re: How can I extend array
Date: 
Message-ID: <011220001709165579%sungwoo@cad.strath.ac.uk>
In article <·················@mastnet.net>, John Clonts
<·······@mastnet.net> wrote:

> Sungwoo, Lim wrote:
> > 
> > In article <·················@solibri.com>, Martti Halminen
> > <···············@solibri.com> wrote:
> > 
> > > "Sungwoo, Lim" wrote:
> > > >
> > > > Now I modified my code as below.
> > > >
> > > > (defun ref-straightline-array ()
> > > >   (setf constant-a (/ distance-firstandlast-y distance-firstandlast-x))
> > > >   (setf constant-b (- first-y (* constant-a first-x)))
> > > >   (setf coord-z 0)
> > > >
> > > >   (cond ((>= distance-firstandlast-x distance-firstandlast-y)
> > > >          (and (setq ref-array (make-array (list distance-firstandlast-x
> > > > 3)))
> > > >               (cond ((< first-x last-x)
> > > >                      (loop for coord-x from first-x to last-x
> > > >                            for ref-index from 0 to (-
> > > > distance-firstandlast-x 1)
> > > >                            do (setf (aref ref-array ref-index 0)
> > > >                                     coord-x)
> > > >                            do (setf (aref ref-array ref-index 1)
> > > >                                     (setf coord-y (+ (* constant-a
> > > > coord-x) constant-b)))
> > > >                            do (setf (aref ref-array ref-index 2)
> > > >                                     coord-z)))
> > > >                     (t (loop for coord-x from first-x downto last-x
> > > >                              for ref-index from 0 to (-
> > > > distance-firstandlast-x 1)
> > > >                              do (setf (aref ref-array ref-index 0)
> > > >                                       coord-x)
> > > >                              do (setf (aref ref-array ref-index 1)
> > > >                                       (setf coord-y (+ (* constant-a
> > > > coord-x) constant-b)))
> > > >                              do (setf (aref ref-array ref-index 2)
> > > >                                       coord-z))))))
> > > >         (t (and (setq ref-array (make-array (list
> > > > distance-firstandlast-y 3)))
> > > >                 (cond ((< first-y last-y)
> > > >                        (loop for coord-y from first-y to last-y
> > > >                              for ref-index from 0 to (-
> > > > distance-firstandlast-y 1)
> > > >                              do (setf (aref ref-array ref-index 0)
> > > >                                       (setf coord-x (/ (- coord-y
> > > > constant-b) constant-a)))
> > > >                              do (setf (aref ref-array ref-index 1)
> > > >                                       coord-y)
> > > >                              do (setf (aref ref-array ref-index 2)
> > > >                                       coord-z)))
> > > >                       (t (loop for coord-y from first-y downto last-y
> > > >                                for ref-index from 0 to (-
> > > > distance-firstandlast-y 1)
> > > >                                do (setf (aref ref-array ref-index 0)
> > > >                                         (setf coord-x (/ (- coord-y
> > > > constant-b) constant-a)))
> > > >                                do (setf (aref ref-array ref-index 1)
> > > >                                         coord-y)
> > > >                                do (setf (aref ref-array ref-index 2)
> > > >                                         coord-z))))))))
> > > >
> > > > It seems to works. But I repeated some codes over and over in here.
> > > > Maybe there are some ways to optimise this silly codes?
> > >
> > > You could reduce the visual clutter a little:
> > > - those "and"s are superfluous, cond already has an implicit progn
> > > there.
> > > - you can have several statements after a "do" keyword in loop, so leave
> > > only the first do in each loop.
> > > - if you leave the to -definition from ref-index away, it'll still get
> > > incremented each time through the loop.
> > >
> > > - If using an array really is necessary, I'd define a little help
> > > function:
> > > (defun put-coord (arr index x y z)
> > >    (setf (aref arr index 0) x)
> > >    (setf (aref arr index 1) y)
> > >     ...)
> > > so the first loop would be
> > >
> > >    (loop for coord-x from first-x to last-x
> > >          for ref-index from 0
> > >       do (put-coord ref-array ref-index coord-x
> > >                                         (+ (* const-a xoord-x) ...)
> > >                                         coord-z)))
> > >  - I'd more likely do each x y z triple as a vector or a struct, so the
> > > ref-array would be a vector.
> > >
> > >
> > > Another suggestion for style would be making clear for yourself which
> > > variables are local, and which are special variables defined elsewhere.
> > >
> > > The locals (for example your const-a, const-b etc.) should be defined
> > > with let (unless they really are intended for use outside this defun,
> > > too.)
> > >
> > > The non-local stuff used here, for example first-x, last-x, should
> > > rather be brought here as parameters for the function, instead of
> > > sneaking them in from wherever they might be set as specials.
> > >
> > > Also, it would be more stylish to return ref-array as the value of the
> > > function, instead of as a side-effect.
> > >
> > >
> > > --
> > 
> > Thanks for very detailed comment. =)
> > So I modified the code as follow.
> > I couldn't fully understand below comment. Do you mean that I have to
> > define a function for non-local stuff, and then adapt the functions...?
> > Could you give me one simple example please? =.=
> > 
> > > The non-local stuff used here, for example first-x, last-x, should
> > > rather be brought here as parameters for the function, instead of
> > > sneaking them in from wherever they might be set as specials.
> > 
> > The other thing is that I tried to return ref-array as the value of the
> > function like below. But I am not sure this is right way..
> > 
> > BTW, thanks very much indeed.
> > 
> > Sungwoo
> > 
> > ;---------------------------------------------
> > (defun ref-straightline-array ()
> >   (let ((constant-a (/ distance-firstandlast-y 
> > distance-firstandlast-x))
> >         (constant-b (- first-y (* constant-a first-x)))))
> > 
> 
> In addition to martti's comments to you, I would point out that the
> above (let ...) expression has no effect.  Therefore you probably have
> global variables called constant-a and constant-b, and you will
> (eventually) be surprised that their values do not change.
> 
> Was this just a typo?  If not, write back and someone (perhaps me) will
> explain how let works.
> 
> Cheers,
> John

Here is the modified code. 
Please let me know the 'let' works properly (to handle variable as a
local) in here.
Thanks,

Sungwoo
;-------------------------------------------------------
(defun ref-straightline-array ()                                   
  (let ((constant-a (/ distance-firstandlast-y
distance-firstandlast-x)) 
        (constant-b (- first-y (* constant-a first-x)))
        (ref-array (make-array (list (max distance-firstandlast-x
distance-firstandlast-y) 3))))
        (cond ((>= distance-firstandlast-x distance-firstandlast-y)
               (cond ((< first-x last-x)
                      (loop for coord-x from first-x to last-x
                            for ref-index from 0
                            do (put-coord ref-array ref-index coord-x 
                                                              (setf
coord-y (+ (* constant-a coord-x) constant-b))
                                                              coord-z)))
                     (t (loop for coord-x from first-x downto last-x
                              for ref-index from 0
                              do (put-coord ref-array ref-index coord-x 
                                                                (setf
coord-y (+ (* constant-a coord-x) constant-b))
                                                               
coord-z)))
              (t (cond ((< first-y last-y) 
                        (loop for coord-y from first-y to last-y
                              for ref-index from 0
                              do (put-coord ref-array ref-index (setf
coord-x (/ (- coord-y constant-b) constant-a)) 
                                                                coord-y
                                                               
coord-z)))
                       (t (loop for coord-y from first-y downto last-y
                                for ref-index from 0
                              do (put-coord ref-array ref-index (setf
coord-x (/ (- coord-y constant-b) constant-a)) 
                                                                coord-y
                                                               
coord-z))))))))
    ref-array))

(defun put-coord (arr index x y z) 
  (setf (aref arr index 0) x)
  (setf (aref arr index 1) y) 
  (setf (aref arr index 2) z)) 
;----------------------------------------------------------
From: John Clonts
Subject: Re: How can I extend array
Date: 
Message-ID: <3A27E37C.2C425255@mastnet.net>
Sungwoo, Lim wrote:
[snip]
> Here is the modified code.
> Please let me know the 'let' works properly (to handle variable as a
> local) in here.
> Thanks,
> 
> Sungwoo
> ;-------------------------------------------------------
> (defun ref-straightline-array ()
>   (let ((constant-a (/ distance-firstandlast-y
> distance-firstandlast-x))
>         (constant-b (- first-y (* constant-a first-x)))
>         (ref-array (make-array (list (max distance-firstandlast-x
> distance-firstandlast-y) 3))))
>         (cond ((>= distance-firstandlast-x distance-firstandlast-y)
[snip]

Yes, thats better.  Now if you just use function parameters as Martti
suggested, you will be "side-effect-free" !

(defun ref-straightline-array 
  (first-x last-x distance-firstandlast-x
   first-y last-y distance-firstandlast-y)
  (let (( .....

Cheers,
John
From: Sungwoo, Lim
Subject: Re: How can I extend array
Date: 
Message-ID: <051220001203202785%sungwoo@cad.strath.ac.uk>
In article <··························@cad.strath.ac.uk>, Sungwoo, Lim
<·······@cad.strath.ac.uk> wrote:

Hello,  

I got a differen problem.
In following code, I tried to store the points of a stroke with
'vector-push-extend' because I don't know the necessary array size
until I release the mouse button.
I got the error about 'bad fill-pointer' here.

My question is,
First, how can I use 'fill-pointer' with multiple dimension?
Second, I thought the 'vector' in an array could be represented as
(aref stroke-array stroke-index 0), but seems wrong?
Third, 'next-x' and 'next-y' should be a new-element in
'vector-push-extend' function, but when I run that line, lisp complains
that the next-x is not the unbounded variable... what's wrong?
Finally, is this (using 'vector-push-extend') the best way to store an
incremental array or another alternatives?
Thanks for your help.

Sungwoo
;-------------------------------------------------------
(defclass simple-drawing-item (dialog-item) ())

(setf stroke-limit 0)
(setf coord-z 0)

(defmethod dialog-item-action ((view simple-drawing-item))
  (let ((where (view-mouse-position view)))
    (#_moveto (point-h where) (point-v where))
    (setf max-x (setf first-x (point-h where))) 
    (setf max-y (setf first-y (point-v where))) 
    (setf min-x (setf first-x (point-h where))) 
    (setf min-y (setf first-y (point-v where))) 
    (setf stroke-limit 1)
    (setf stroke-index 0)
    (setf stroke-array (make-array (list stroke-limit 3) :adjustable t
                                                         :fill-pointer
1))
    (put-coord stroke-array stroke-index first-x
                                         first-y
                                         coord-z)
    (with-pen-saved
      (set-pen-mode view :patOr)  
      (loop while (mouse-down-p)
            for previous-x = first-x then next-x
            for previous-y = first-y then next-y
            do (let* ((pos (view-mouse-position view))) 
                 (#_lineto (point-h pos) (point-v pos))
                 (setf next-x (point-h pos))
                 (setf next-y (point-v pos))
                 (set-initial-region next-x next-y)   
                 (when (or (/= previous-x next-x) (/= previous-y
next-y))
                   (incf stroke-limit) 
                   (incf stroke-index)
                   (vector-push-extend next-x (aref stroke-array
stroke-index 0))
                   (vector-push-extend next-y (aref stroke-array
stroke-index 0))
                   (vector-push-extend 0 (aref stroke-array
stroke-index 0))
))
                                    finally (setf last-x next-x last-y
next-y)))
;      (set-rect-region view min-x min-y max-x max-y) ; this is buggy
))
From: Janis Dzerins
Subject: Re: How can I extend array
Date: 
Message-ID: <87aeab2hgq.fsf@asaka.latnet.lv>
"Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:


> Finally, is this (using 'vector-push-extend') the best way to store an
> incremental array or another alternatives?

I doubt that it is the best way to achiev what you are trying to
achieve. I a very simple drawing application I wrote to learn CLX I
use queues for this purpose. I can send the source to you if you're
interested.

Janis Dzerins
-- 
  If million people say a stupid thing it's still a stupid thing.
From: Sungwoo, Lim
Subject: Re: How can I extend array
Date: 
Message-ID: <051220001259456540%sungwoo@cad.strath.ac.uk>
In article <··············@asaka.latnet.lv>, Janis Dzerins
<·····@latnet.lv> wrote:

> "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> 
> 
> > Finally, is this (using 'vector-push-extend') the best way to store an
> > incremental array or another alternatives?
> 
> I doubt that it is the best way to achiev what you are trying to
> achieve. I a very simple drawing application I wrote to learn CLX I
> use queues for this purpose. I can send the source to you if you're
> interested.
> 
> Janis Dzerins

Thanks, =)
Please send me the source as ········@cad.strath.ac.uk'.
BTW, what is CLX?
CLX-> Common Lisp X?

Sungwoo
From: Martti Halminen
Subject: Re: How can I extend array
Date: 
Message-ID: <3A2CEB2E.EF8BBAFD@solibri.com>
"Sungwoo, Lim" wrote:

> I got a differen problem.
> In following code, I tried to store the points of a stroke with
> 'vector-push-extend' because I don't know the necessary array size
> until I release the mouse button.
> I got the error about 'bad fill-pointer' here.
> 
> My question is,
> First, how can I use 'fill-pointer' with multiple dimension?

You can't. Fill-pointer only works for one-dimensional arrays. On the
other hand, why are you using an n x 3 array for your points? It would
be cleaner if you used a one-dimensional array, i.e. a vector, for your
points; each point would be an object with all the coordinate
information for that point, either a vector or a struct.

> Second, I thought the 'vector' in an array could be represented as
> (aref stroke-array stroke-index 0), but seems wrong?

This refers to whatever you have stored in the [stroke-index, 0] cell of
your array; in your case, a number, but it could be any lisp object
whatsoever in the general case. There isn't a way to refer to larger
subparts of a general array (beyond some tricks with displaced arrays),
you are always pointing to either the whole array or to a specific item
in the array. The item can be a vector or whatever, there is no
requirement for it to be a simple number (unless you define it with that
type).

> Third, 'next-x' and 'next-y' should be a new-element in
> 'vector-push-extend' function, but when I run that line, lisp complains
> that the next-x is not the unbounded variable... what's wrong?

I'd have thought it complains because the value of (aref stroke-array
stroke-index 0) isn't a vector.


> Finally, is this (using 'vector-push-extend') the best way to store an
> incremental array or another alternatives?

The name should be a hint that this works on vectors, not on
multi-dimensional arrays.

On the other hand, the whole idea of an incremental array is a little
odd: usually an array is a contiguous memory area, with fast access
through offsetting from the base address. Changing the dimensions would
in effect mean re-allocating the whole array, so it is supported only
for special cases (one-dimensional).

So, why not use a vector of vectors or structs, instead of a n x 3 array
?

--
From: Sungwoo, Lim
Subject: Re: How can I extend array
Date: 
Message-ID: <051220001416112643%sungwoo@cad.strath.ac.uk>
In article <·················@solibri.com>, Martti Halminen
<···············@solibri.com> wrote:

> "Sungwoo, Lim" wrote:
> 
> > I got a differen problem.
> > In following code, I tried to store the points of a stroke with
> > 'vector-push-extend' because I don't know the necessary array size
> > until I release the mouse button.
> > I got the error about 'bad fill-pointer' here.
> > 
> > My question is,
> > First, how can I use 'fill-pointer' with multiple dimension?
> 
> You can't. Fill-pointer only works for one-dimensional arrays. On the
> other hand, why are you using an n x 3 array for your points? It would
> be cleaner if you used a one-dimensional array, i.e. a vector, for your
> points; each point would be an object with all the coordinate
> information for that point, either a vector or a struct.
> 
> > Second, I thought the 'vector' in an array could be represented as
> > (aref stroke-array stroke-index 0), but seems wrong?
> 
> This refers to whatever you have stored in the [stroke-index, 0] cell of
> your array; in your case, a number, but it could be any lisp object
> whatsoever in the general case. There isn't a way to refer to larger
> subparts of a general array (beyond some tricks with displaced arrays),
> you are always pointing to either the whole array or to a specific item
> in the array. The item can be a vector or whatever, there is no
> requirement for it to be a simple number (unless you define it with that
> type).
> 
> > Third, 'next-x' and 'next-y' should be a new-element in
> > 'vector-push-extend' function, but when I run that line, lisp complains
> > that the next-x is not the unbounded variable... what's wrong?
> 
> I'd have thought it complains because the value of (aref stroke-array
> stroke-index 0) isn't a vector.
> 
> 
> > Finally, is this (using 'vector-push-extend') the best way to store an
> > incremental array or another alternatives?
> 
> The name should be a hint that this works on vectors, not on
> multi-dimensional arrays.
> 
> On the other hand, the whole idea of an incremental array is a little
> odd: usually an array is a contiguous memory area, with fast access
> through offsetting from the base address. Changing the dimensions would
> in effect mean re-allocating the whole array, so it is supported only
> for special cases (one-dimensional).
> 
> So, why not use a vector of vectors or structs, instead of a n x 3 array
> ?
> 
> --

Thanks, =)
I modified the code, but still doesn't work. ;(
Did I used vector in here correctly?
Sungwoo

;-----------------------------------------------------
(defclass simple-drawing-item (dialog-item) ())

(setf stroke-limit 0)
(setf coord-z 0)

(defmethod dialog-item-action ((view simple-drawing-item))
  (let ((where (view-mouse-position view)))
    (#_moveto (point-h where) (point-v where))
    (setf max-x (setf first-x (point-h where)))
    (setf max-y (setf first-y (point-v where)))
    (setf min-x (setf first-x (point-h where))) 
    (setf min-y (setf first-y (point-v where))) 
    (setf stroke-limit 1)
    (setf stroke-index 0)
    (setf stroke-array (make-array 3 :fill-pointer1))
    (setf (aref stroke-array stroke-index) first-x)
    (setf (aref stroke-array stroke-index) first-y)
    (setf (aref stroke-array stroke-index) coord-z)

    (with-pen-saved
      (set-pen-mode view :patOr)   
      (loop while (mouse-down-p)
            for previous-x = first-x then next-x
            for previous-y = first-y then next-y
            do (let* ((pos (view-mouse-position view))) 
                 (#_lineto (point-h pos) (point-v pos))
                 (setf next-x (point-h pos))
                 (setf next-y (point-v pos))
                 (set-initial-region next-x next-y)   
                 (when (or (/= previous-x next-x) (/= previous-y
next-y))
                   (incf stroke-limit) 
                   (incf stroke-index)
                   (vector-push-extend next-x (aref stroke-array
stroke-index))
                   (vector-push-extend next-y (aref stroke-array
stroke-index))
                   (vector-push-extend coord-z (aref stroke-array
stroke-index))
))
                                    finally (setf last-x next-x last-y
next-y))) 
;      (set-rect-region view min-x min-y max-x max-y) ; this is buggy
))
From: Martti Halminen
Subject: Re: How can I extend array
Date: 
Message-ID: <3A2D21D8.B172336E@solibri.com>
"Sungwoo, Lim" wrote:

> 
> Thanks, =)
> I modified the code, but still doesn't work. ;(
> Did I used vector in here correctly?
> Sungwoo

I wouldn't say so. For example in

>     (setf (aref stroke-array stroke-index) first-x)
>     (setf (aref stroke-array stroke-index) first-y)
>     (setf (aref stroke-array stroke-index) coord-z)

you are setting the value to first-x, then the same place to first-y and
finally to coord-z, so only the last one has any effect.

You should try something like:

(defstruct point x y (z 0))

...

(setf (aref stroke-array stroke-index) (make-point :x first-x :y
first-y))

...

(vector-push-extend (make-point :x next-x :y next-y) stroke-array)


etc.

--
From: Sungwoo, Lim
Subject: Re: How can I extend array
Date: 
Message-ID: <061220001620227191%sungwoo@cad.strath.ac.uk>
In article <·················@solibri.com>, Martti Halminen
<···············@solibri.com> wrote:

I tried this way... and got the error as follow.

;------------------------------------------------------------
(defclass simple-drawing-item (dialog-item) ())

(setf stroke-limit 0)
(setf coord-z 0)

(defmethod dialog-item-action ((view simple-drawing-item))
  (let ((where (view-mouse-position view)))
    (#_moveto (point-h where) (point-v where))
    (setf max-x (setf first-x (point-h where))) 
    (setf max-y (setf first-y (point-v where))) 
    (setf min-x (setf first-x (point-h where))) 
    (setf min-y (setf first-y (point-v where))) 
    (setf stroke-limit 1)
    (setf stroke-index 0)
    (setf stroke-array (make-array 3 :adjustable t
                                     :fill-pointer 3
                                     :initial-contents (list first-x
first-y coord-z)))

    (with-pen-saved
      (set-pen-mode view :patOr)   
      (loop while (mouse-down-p)
            for previous-x = first-x then next-x
            for previous-y = first-y then next-y
            do (let* ((pos (view-mouse-position view))) 
                 (#_lineto (point-h pos) (point-v pos))
                 (setf next-x (point-h pos))
                 (setf next-y (point-v pos))
                 (set-initial-region next-x next-y)   
                 (when (or (/= previous-x next-x) (/= previous-y
next-y))
                   (incf stroke-limit) 
                   (incf stroke-index)
                   (vector-push-extend next-x (aref stroke-array 1))
                   (vector-push-extend next-y (aref stroke-array 2))
                   (vector-push-extend 0 (aref stroke-array 3))))
           finally (setf last-x next-x last-y next-y))) 
;      (set-rect-region view min-x min-y max-x max-y) ; this is buggy
))
------------------------------------------------------------------------
*** Break during event processing! Standin event processor created. ***
**** Original event processor will continue when break loop exits. ****
> Error in process Initial: 117 is not an array with a fill pointer.
> While executing: FILL-POINTER
> Type Command-. to abort.
See the Restarts� menu item for further choices.
1 > 
------------------------------------------------------------------------

Frist, I don't know why the number 117 is pop in here... 
(The number is the y coordinate of first point.)

Second, this 'vector-push-extend' function seems givea result as
((x1 x2 x3 ...) (y1 y2 y3 ...) (z1 z2 z3 ...)) rather than
((x1 y2 z3) (x2 y2 z2) (x3 y3 z3) ...)
Am I right or wrong? If I am right, I want to get the latter result.
Is it possible to do that with vector or should I return to multiple
dimension array?
Any comment please?
Thanks,

Sungwoo
From: Kent M Pitman
Subject: Re: How can I extend array
Date: 
Message-ID: <sfwu28hse7g.fsf@world.std.com>
"Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:

>                    (vector-push-extend next-x (aref stroke-array 1))
>                    (vector-push-extend next-y (aref stroke-array 2))
>                    (vector-push-extend 0 (aref stroke-array 3))))

> *** Break during event processing! Standin event processor created. ***
> **** Original event processor will continue when break loop exits. ****
> > Error in process Initial: 117 is not an array with a fill pointer.
> > While executing: FILL-POINTER

> Frist, I don't know why the number 117 is pop in here... 
> (The number is the y coordinate of first point.)

VECTOR-PUSH-EXTEND takes an array, not an array reference.  I didn't look
carefully at your program, but are you sure you don't mean to just be
doing (VECTOR-PUSH-EXTEND next-x stroke-array), etc.?

> Second, this 'vector-push-extend' function seems givea result as
> ((x1 x2 x3 ...) (y1 y2 y3 ...) (z1 z2 z3 ...)) rather than
> ((x1 y2 z3) (x2 y2 z2) (x3 y3 z3) ...)
> Am I right or wrong?

It extends a linear array.  If you go back to the example I sent, you'll
see that how it worked was to view the 2d array as linear (elements in
the order dictated by row major storage)  by displacing another linear array
to the same storage as the 2d one.  This works in some cases but won't
work in others.  It will work if you are filling a complete array or
contiguous array segment by row major traversal only.  I don't know what the
"..."'s in your question are, so I don't know how to answer.

Consider a two-d array

 [ [ a b c ]
   [ d e f ] ]

The storage is laid out linearly as [ a b c d e f ]
VECTOR-PUSH-EXTEND works by moving left to right in the linear storage.
Whatever elements it stores onto in moving in that order are affected
in the 2d array if the 1d array is displaced to the 2d one's storage.

> If I am right, I want to get the latter result.

I can't figure out what this means.

> Is it possible to do that with vector or should I return to multiple
> dimension array?

I can't understand this question either.  Worked examples, or at least
small code fragments, are better.  Examples of return values without
the code (or at least the shape of the code) that made them don't really
make it clear, at least to me.
From: Martti Halminen
Subject: Re: How can I extend array
Date: 
Message-ID: <3A2F91C5.797E752B@solibri.com>
"Sungwoo, Lim" wrote:

> I tried this way... and got the error as follow.

>     (setf stroke-array (make-array 3 :adjustable t
>                                      :fill-pointer 3
>                                      :initial-contents (list first-x
> first-y coord-z)))

<snip>

>                    (vector-push-extend next-x (aref stroke-array 1))

> > Error in process Initial: 117 is not an array with a fill pointer.

> Frist, I don't know why the number 117 is pop in here...
> (The number is the y coordinate of first point.)

Well, you did put first-y as the value of the second element in
stroke-array. And that is what (aref stroke-array 1) returns. Why are
you surprised?

If you'd bother reading the documentation on vector-push-extend, you'd
find out that it wants a vector as its second argument. So why are you
trying to use an element of the vector, instead of the vector itself?

Also, why are you trying to store the individual coordinates separately,
instead of storing just the point objects? Come to think of it, your
view-mouse-position -function seems to return quite usable points,
whatever the data structure is. Why not store those directly, instead of
ripping them apart and re-storing the contents in a more clumsy way?




> Second, this 'vector-push-extend' function seems givea result as
> ((x1 x2 x3 ...) (y1 y2 y3 ...) (z1 z2 z3 ...)) rather than
> ((x1 y2 z3) (x2 y2 z2) (x3 y3 z3) ...)
> Am I right or wrong? If I am right, I want to get the latter result.
> Is it possible to do that with vector or should I return to multiple
> dimension array?
> Any comment please?

How about something like this?

(defmethod dialog-item-action ((view simple-drawing-item))
  (let ((where (view-mouse-position view))
        (next-point nil))
    (#_moveto (point-h where) (point-v where))
    (setf stroke-index 0)
    (setf stroke-array
      (make-array 3 :adjustable t
                  :fill-pointer 1
                  :initial-contents where))

    (with-pen-saved
      (set-pen-mode view :patOr)   
      (loop while (mouse-down-p)
            for previous-point = where then next-point
            do (let* ((pos (view-mouse-position view))) 
                 (#_lineto (point-h pos) (point-v pos))
                 (setf next-point pos)
                 (set-initial-region (point-h pos)(point-v pos))
                 (unless (same-point-p previous-point next-point)
                   (incf stroke-index)
                   (vector-push-extend next-point stroke-array)
                   ))))
    stroke-array))
                   
   ;; I stripped some of the side-effects, where I didn't have a good
idea ;; what to do with them.     

--
From: Sungwoo, Lim
Subject: Re: How can I extend array
Date: 
Message-ID: <071220001650359024%sungwoo@cad.strath.ac.uk>
In article <·················@solibri.com>, Martti Halminen
<···············@solibri.com> wrote:

> Also, why are you trying to store the individual coordinates separately,
> instead of storing just the point objects? Come to think of it, your
> view-mouse-position -function seems to return quite usable points,
> whatever the data structure is. Why not store those directly, instead of
> ripping them apart and re-storing the contents in a more clumsy way?
> 
Because I had a small confusion with my ignorance. =)
I tried very silly thing which separate each coordinates and store
within multiple dimension... but now I know that I don't have to do
that.
BTW, I modified the code as below, and it works well. 
Thanks for your help, guys. =)

Sungwoo
;--------------------------------
(defmethod dialog-item-action ((view simple-drawing-item))
  (let ((where (view-mouse-position view)))
    (#_moveto (point-h where) (point-v where))
    (setf max-x (setf first-x (point-h where))) 
    (setf max-y (setf first-y (point-v where))) 
    (setf min-x (setf first-x (point-h where))) 
    (setf min-y (setf first-y (point-v where))) 
    (setf stroke-limit 1)
    (setf stroke-index 0)
    (stroke-array first-x first-y coord-z)
    (with-pen-saved
      (set-pen-mode view :patOr)   
      (loop while (mouse-down-p)
            for previous-x = first-x then next-x
            for previous-y = first-y then next-y
            do (let* ((pos (view-mouse-position view))) 
                 (#_lineto (point-h pos) (point-v pos))
                 (setf next-x (point-h pos))
                 (setf next-y (point-v pos))
                 (set-initial-region next-x next-y) 
                 (when (or (/= previous-x next-x) (/= previous-y
next-y))
                   (vector-push-extend next-x stroke-array-x)
                   (vector-push-extend next-y stroke-array-y)
                   (vector-push-extend 0 stroke-array-z)))
            finally (setf last-x next-x    
                          last-y next-y   
                          stroke-limit (array-total-size stroke-array-x)
                          stroke-index (- stroke-limit 1)))) 
;      (set-rect-region view min-x min-y max-x max-y) ; this is buggy
))

(defun stroke-array (x y z)
    (setf stroke-array-x (make-array (list stroke-limit) 
                                     :adjustable t
                                     :fill-pointer 1
                                     :initial-contents (list x)))
    (setf stroke-array-y (make-array (list stroke-limit) 
                                     :adjustable t
                                     :fill-pointer 1
                                     :initial-contents (list y)))
    (setf stroke-array-z (make-array (list stroke-limit) 
                                     :adjustable t
                                     :fill-pointer 1
                                     :initial-contents (list z))))
From: Kent M Pitman
Subject: Re: How can I extend array
Date: 
Message-ID: <sfwbsuq3oc1.fsf@world.std.com>
"Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:

> First, how can I use 'fill-pointer' with multiple dimension?

Your message asks a bunch of questions but this one I will 
answer narrowly out of context in case the answer is helpful
in this or some other case...

 (DEFUN SHOW2D (ARRAY &OPTIONAL (NAME "a"))
   (LET ((*PRINT-ARRAY* NIL))
     (FORMAT T "~&~A = ~S" NAME ARRAY))
   (DOTIMES (I (ARRAY-DIMENSION ARRAY 0))
     (DOTIMES (J (ARRAY-DIMENSION ARRAY 1))
       (FORMAT T "~&~A[~D,~D] =  ~S~%" NAME I J (AREF ARRAY I J)))))

 (SHOW2D
   (LET* ((M 4)
          (FOO  (MAKE-ARRAY (LIST M 3)))
          (FOO1 (MAKE-ARRAY (* M 3) :FILL-POINTER 0 :DISPLACED-TO FOO)))
     (DOTIMES (I M)
       (VECTOR-PUSH-EXTEND (LIST I 'A) FOO1)
       (VECTOR-PUSH-EXTEND (LIST I 'B) FOO1)
       (VECTOR-PUSH-EXTEND (LIST I 'C) FOO1))
     FOO))
 a = #<SIMPLE-ARRAY T (4 3) 203FD5EC>
 a[0,0] =  (0 A)
 a[0,1] =  (0 B)
 a[0,2] =  (0 C)
 a[1,0] =  (1 A)
 a[1,1] =  (1 B)
 a[1,2] =  (1 C)
 a[2,0] =  (2 A)
 a[2,1] =  (2 B)
 a[2,2] =  (2 C)
 a[3,0] =  (3 A)
 a[3,1] =  (3 B)
 a[3,2] =  (3 C)
 => NIL
From: Sungwoo, Lim
Subject: Re: How can I extend array
Date: 
Message-ID: <051220001543348475%sungwoo@cad.strath.ac.uk>
In article <···············@world.std.com>, Kent M Pitman
<······@world.std.com> wrote:

> "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> 
> > First, how can I use 'fill-pointer' with multiple dimension?
> 
> Your message asks a bunch of questions but this one I will 
> answer narrowly out of context in case the answer is helpful
> in this or some other case...
> 
>  (DEFUN SHOW2D (ARRAY &OPTIONAL (NAME "a"))
>    (LET ((*PRINT-ARRAY* NIL))
>      (FORMAT T "~&~A = ~S" NAME ARRAY))
>    (DOTIMES (I (ARRAY-DIMENSION ARRAY 0))
>      (DOTIMES (J (ARRAY-DIMENSION ARRAY 1))
>        (FORMAT T "~&~A[~D,~D] =  ~S~%" NAME I J (AREF ARRAY I J)))))
> 
>  (SHOW2D
>    (LET* ((M 4)
>           (FOO  (MAKE-ARRAY (LIST M 3)))
>           (FOO1 (MAKE-ARRAY (* M 3) :FILL-POINTER 0 :DISPLACED-TO FOO)))
>      (DOTIMES (I M)
>        (VECTOR-PUSH-EXTEND (LIST I 'A) FOO1)
>        (VECTOR-PUSH-EXTEND (LIST I 'B) FOO1)
>        (VECTOR-PUSH-EXTEND (LIST I 'C) FOO1))
>      FOO))
>  a = #<SIMPLE-ARRAY T (4 3) 203FD5EC>
>  a[0,0] =  (0 A)
>  a[0,1] =  (0 B)
>  a[0,2] =  (0 C)
>  a[1,0] =  (1 A)
>  a[1,1] =  (1 B)
>  a[1,2] =  (1 C)
>  a[2,0] =  (2 A)
>  a[2,1] =  (2 B)
>  a[2,2] =  (2 C)
>  a[3,0] =  (3 A)
>  a[3,1] =  (3 B)
>  a[3,2] =  (3 C)
>  => NIL

Thanks, =)

The code shows me how it works.
I may have to change to one dimension array, but still very nice to see
various examples which can't find from textbook.
Thanks again.

Sungwoo
From: Marc Battyani
Subject: Re: How can I extend array
Date: 
Message-ID: <90j497$kbj$1@reader1.fr.uu.net>
"Kent M Pitman" <······@world.std.com> wrote in message
····················@world.std.com...
> "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
>
> > First, how can I use 'fill-pointer' with multiple dimension?
>
> Your message asks a bunch of questions but this one I will
> answer narrowly out of context in case the answer is helpful
> in this or some other case...
>
>  (DEFUN SHOW2D (ARRAY &OPTIONAL (NAME "a"))
>    (LET ((*PRINT-ARRAY* NIL))
>      (FORMAT T "~&~A = ~S" NAME ARRAY))
>    (DOTIMES (I (ARRAY-DIMENSION ARRAY 0))
>      (DOTIMES (J (ARRAY-DIMENSION ARRAY 1))
>        (FORMAT T "~&~A[~D,~D] =  ~S~%" NAME I J (AREF ARRAY I J)))))
>
>  (SHOW2D
>    (LET* ((M 4)
>           (FOO  (MAKE-ARRAY (LIST M 3)))
>           (FOO1 (MAKE-ARRAY (* M 3) :FILL-POINTER 0 :DISPLACED-TO FOO)))
>      (DOTIMES (I M)
>        (VECTOR-PUSH-EXTEND (LIST I 'A) FOO1)
>        (VECTOR-PUSH-EXTEND (LIST I 'B) FOO1)
>        (VECTOR-PUSH-EXTEND (LIST I 'C) FOO1))
>      FOO))

Why VECTOR-PUSH-EXTEND instead of VECTOR-PUSH? The FOO array is not
adjustable. Or am I missing a point?

CL-USER 51 > (SHOW2D
   (LET* ((M 4)
          (FOO  (MAKE-ARRAY (LIST M 3)))
          (FOO1 (MAKE-ARRAY (* M 3) :FILL-POINTER 0 :DISPLACED-TO FOO)))
     (DOTIMES (I 5)
       (VECTOR-PUSH-EXTEND (LIST I 'A) FOO1)
       (VECTOR-PUSH-EXTEND (LIST I 'B) FOO1)
       (VECTOR-PUSH-EXTEND (LIST I 'C) FOO1))
     FOO))

Error: In a call to vector-push-extend: #((0 a) (0 b) (0 c) (1 a) (1 b) (1
c) (2 a) (2 b) (2 c) (3 a) (3 b) (3 c)) is not of type (satisfies
adjustable-array-p).
  1 (abort) Return to level 0.
  2 Return to top loop level 0.

Marc
From: Kent M Pitman
Subject: Re: How can I extend array
Date: 
Message-ID: <sfw1yvmix8i.fsf@world.std.com>
"Marc Battyani" <·············@fractalconcept.com> writes:

> Why VECTOR-PUSH-EXTEND instead of VECTOR-PUSH? The FOO array is not
> adjustable. Or am I missing a point?

Because I just always use VECTOR-PUSH-EXTEND.  I prefer to get an error
signaled if I overrun the buffer.  VECTOR-PUSH doesn't guarantee that, and
many vendors have (in what I believe is at least conforming and maybe even
intentional in the design of VECTOR-PUSH, though I wasn't involved in that)
decided to quietly ignore vector overruns.  e.g., LispWorks 4.1 does this,
which I belive is "correct" behavior.

  (LET ((X (MAKE-ARRAY 5 :FILL-POINTER 0))) 
    (DOTIMES (I 10) (VECTOR-PUSH I X))
    X)
  => #(0 1 2 3 4)


> CL-USER 51 > (SHOW2D
>    (LET* ((M 4)
>           (FOO  (MAKE-ARRAY (LIST M 3)))
>           (FOO1 (MAKE-ARRAY (* M 3) :FILL-POINTER 0 :DISPLACED-TO FOO)))
>      (DOTIMES (I 5)
>        (VECTOR-PUSH-EXTEND (LIST I 'A) FOO1)
>        (VECTOR-PUSH-EXTEND (LIST I 'B) FOO1)
>        (VECTOR-PUSH-EXTEND (LIST I 'C) FOO1))
>      FOO))
> 
> Error: In a call to vector-push-extend: #((0 a) (0 b) (0 c) (1 a) (1 b) (1
> c) (2 a) (2 b) (2 c) (3 a) (3 b) (3 c)) is not of type (satisfies
> adjustable-array-p).
>   1 (abort) Return to level 0.
>   2 Return to top loop level 0.

I know the change you're asking me to do is to add :ADJUSTABLE T, but
supposing that I don't do that, do you really prefer the behavior you 
get with VECTOR-PUSH in the above example?  I know I don't.  I *want*
that error.
From: Bernhard Pfahringer
Subject: Re: How can I extend array
Date: 
Message-ID: <90mpgm$4fn$1@hummel.cs.waikato.ac.nz>
In article <···············@world.std.com>,
Kent M Pitman  <······@world.std.com> wrote:
...
>>           (FOO  (MAKE-ARRAY (LIST M 3)))
>>           (FOO1 (MAKE-ARRAY (* M 3) :FILL-POINTER 0 :DISPLACED-TO FOO)))
>
...
>I know the change you're asking me to do is to add :ADJUSTABLE T, but
>supposing that I don't do that, do you really prefer the behavior you 
>get with VECTOR-PUSH in the above example?  I know I don't.  I *want*
>that error.
>

So that leaves the question of what should be happening if you really
would add :ADJUSTABLE T ? Especially once the size of FOO1 overruns
the size of FOO (which is not ADJUSTABLE). I would have expected an
error message at that point when VECTOR-PUSH-EXTEND calls ADJUST-ARRAY
on FOO1 to make more space. Interestingly, at least one CL implementation
does do the following: FOO1 is extended *and* looses its sharing with
FOO. Is this justified by the standard? I am not sure, but I suspect
it is, but it is definitely counter-intuitive behavior.

So in summary not including :ADJUSTABLE T seems like a very reasonable choice.

Bernhard
-- 
--------------------------------------------------------------------------
Bernhard Pfahringer       Dept. of Computer Science, University of Waikato
http://www.cs.waikato.ac.nz/~bernhard                       +64 7 838 4041
--------------------------------------------------------------------------