From: Sungwoo, Lim
Subject: Iteration within specific intervals?
Date: 
Message-ID: <281120001128346404%sungwoo@cad.strath.ac.uk>
Hello,

I would like to calculate following codes within a specific iteration
over a sequence of integers. 

(setf total-distance 0)
(setf respective-distance 
   (sqrt (+ (expt (- ref-point-x stroke-point-x) 2) 
            (expt (- ref-point-y stroke-point-y) 2))))
(setf total-distance (+ total-distance respective-distance)))

Suppose that the whole stroke points (N) are in an Array form, and I
want to get a specific points with the intervals (M).

For example, if N = 100 and M = 3, then 
3, 6, 9, 12, ... 99th point are used to calculate the above code.
The value of 'stroke-point-x' and 'stroke-point-y' should be changed
with every iteration.

In addition, the ref-point (R) are also in an Array form, and I want to
get every points one by one when the stroke point (N) is changed.

For example, Array R has {1, ... , 33} and Array N has {1, ... , 100},
then calculate the above code with R(1), N(3)
                                   R(2), N(6)
                                   ...
                                  R(32), N(96)
                                  R(33), N(99)

  
1. In this case, which function could I use?
   I took a look the function 'do' and 'dotimes', but still vague.
2. How can I perform two iteration simultaneously?
3. How can I get the nth element in ARRAY?

Sorry about too buggy question.
Thanks for your help. =)

Sungwoo

From: Sungwoo, Lim
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <281120001323453036%sungwoo@cad.strath.ac.uk>
In article <··························@cad.strath.ac.uk>, Sungwoo, Lim
<·······@cad.strath.ac.uk> wrote:

If I use loop macro as below,

(loop for x from 0 to 50
      for y from 0 to 300
  collect (list x y))

Maybe I could perform iteration with two values.
To give an interval, below simple example may works...

(loop for x from 0 to 50 
      for y from 0 upto 300 by 6
  collect (list x y))

It looks works. 
Any other suggestion please? 
Thanks,

Sungwoo
From: Marco Antoniotti
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <y6c8zq487dn.fsf@octagon.mrl.nyu.edu>
"Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:

> In article <··························@cad.strath.ac.uk>, Sungwoo, Lim
> <·······@cad.strath.ac.uk> wrote:
> 
> If I use loop macro as below,
> 
> (loop for x from 0 to 50
>       for y from 0 to 300
>   collect (list x y))
> 
> Maybe I could perform iteration with two values.
> To give an interval, below simple example may works...
> 
> (loop for x from 0 to 50 
>       for y from 0 upto 300 by 6
>   collect (list x y))
> 
> It looks works. 
> Any other suggestion please? 

Isn't the second form pretty much what you asked for? :)

Cheers

-- 
Marco Antoniotti =============================================================
NYU Bioinformatics Group			 tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                          fax  +1 - 212 - 995 4122
New York, NY 10003, USA				 http://galt.mrl.nyu.edu/valis
             Like DNA, such a language [Lisp] does not go out of style.
			      Paul Graham, ANSI Common Lisp
From: Sungwoo, Lim
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <281120001544371955%sungwoo@cad.strath.ac.uk>
In article <···············@octagon.mrl.nyu.edu>, Marco Antoniotti
<·······@cs.nyu.edu> wrote:

> "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> 
> > In article <··························@cad.strath.ac.uk>, Sungwoo, Lim
> > <·······@cad.strath.ac.uk> wrote:
> > 
> > If I use loop macro as below,
> > 
> > (loop for x from 0 to 50
> >       for y from 0 to 300
> >   collect (list x y))
> > 
> > Maybe I could perform iteration with two values.
> > To give an interval, below simple example may works...
> > 
> > (loop for x from 0 to 50 
> >       for y from 0 upto 300 by 6
> >   collect (list x y))
> > 
> > It looks works. 
> > Any other suggestion please? 
> 
> Isn't the second form pretty much what you asked for? :)
> 
> Cheers

Yeap. I think so. =)
Cheers,

Sungwoo
From: Joe Marshall
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <8zq4gm5v.fsf@content-integrity.com>
I'm not sure I understand the problem fully, but is this on the right
track? 

(do ((ref-index      0 (1+ ref-index))
     (stroke-index   0 (+ stroke-index stride))
     (total-distance 0 (let* ((ref-point    (aref ref-array ref-index))
                              (ref-point-x  ???)
                              (ref-point-y  ???)
                              (stroke-point (aref stroke-array stroke-index))
                              (stroke-point-x ???)
                              (stroke-point-y ???))
                          (+ total-distance
                             (sqrt (+ (expt (- ref-point-x stroke-point-x) 2)
                                      (expt (- ref-point-y stroke-point-y) 2)))))))
     ((or (> ref-index   ref-limit)
          (> strok-index stroke-limit)) total-distance))


"Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:

> Hello,
> 
> I would like to calculate following codes within a specific iteration
> over a sequence of integers. 
> 
> (setf total-distance 0)
> (setf respective-distance 
>    (sqrt (+ (expt (- ref-point-x stroke-point-x) 2) 
>             (expt (- ref-point-y stroke-point-y) 2))))
> (setf total-distance (+ total-distance respective-distance)))
> 
> Suppose that the whole stroke points (N) are in an Array form, and I
> want to get a specific points with the intervals (M).
> 
> For example, if N = 100 and M = 3, then 
> 3, 6, 9, 12, ... 99th point are used to calculate the above code.
> The value of 'stroke-point-x' and 'stroke-point-y' should be changed
> with every iteration.
> 
> In addition, the ref-point (R) are also in an Array form, and I want to
> get every points one by one when the stroke point (N) is changed.
> 
> For example, Array R has {1, ... , 33} and Array N has {1, ... , 100},
> then calculate the above code with R(1), N(3)
>                                    R(2), N(6)
>                                    ...
>                                   R(32), N(96)
>                                   R(33), N(99)
> 
>   
> 1. In this case, which function could I use?
>    I took a look the function 'do' and 'dotimes', but still vague.
> 2. How can I perform two iteration simultaneously?
> 3. How can I get the nth element in ARRAY?
> 
> Sorry about too buggy question.
> Thanks for your help. =)
> 
> Sungwoo


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Sungwoo, Lim
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <281120001613336746%sungwoo@cad.strath.ac.uk>
Wow... I think you got what I want with 'do' macro. =)
What is (ref-point-x ???) ?
It looks that I need something more to extract from ref-point to
ref-point-x and ref-point-y? 

Thanks for your help. =)

Sungwoo


In article <············@content-integrity.com>, Joe Marshall
<···@content-integrity.com> wrote:

> I'm not sure I understand the problem fully, but is this on the right
> track? 
> 
> (do ((ref-index      0 (1+ ref-index))
>      (stroke-index   0 (+ stroke-index stride))
>      (total-distance 0 (let* ((ref-point    (aref ref-array ref-index))
>                               (ref-point-x  ???)
>                               (ref-point-y  ???)
>                               (stroke-point (aref stroke-array stroke-index))
>                               (stroke-point-x ???)
>                               (stroke-point-y ???))
>                           (+ total-distance
>                              (sqrt (+ (expt (- ref-point-x stroke-point-x) 2)
>                                       (expt (- ref-point-y stroke-point-y)
> 2)))))))
>      ((or (> ref-index   ref-limit)
>           (> strok-index stroke-limit)) total-distance))
> 
> 
> "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> 
> > Hello,
> > 
> > I would like to calculate following codes within a specific iteration
> > over a sequence of integers. 
> > 
> > (setf total-distance 0)
> > (setf respective-distance 
> >    (sqrt (+ (expt (- ref-point-x stroke-point-x) 2) 
> >             (expt (- ref-point-y stroke-point-y) 2))))
> > (setf total-distance (+ total-distance respective-distance)))
> > 
> > Suppose that the whole stroke points (N) are in an Array form, and I
> > want to get a specific points with the intervals (M).
> > 
> > For example, if N = 100 and M = 3, then 
> > 3, 6, 9, 12, ... 99th point are used to calculate the above code.
> > The value of 'stroke-point-x' and 'stroke-point-y' should be changed
> > with every iteration.
> > 
> > In addition, the ref-point (R) are also in an Array form, and I want to
> > get every points one by one when the stroke point (N) is changed.
> > 
> > For example, Array R has {1, ... , 33} and Array N has {1, ... , 100},
> > then calculate the above code with R(1), N(3)
> >                                    R(2), N(6)
> >                                    ...
> >                                   R(32), N(96)
> >                                   R(33), N(99)
> > 
> >   
> > 1. In this case, which function could I use?
> >    I took a look the function 'do' and 'dotimes', but still vague.
> > 2. How can I perform two iteration simultaneously?
> > 3. How can I get the nth element in ARRAY?
> > 
> > Sorry about too buggy question.
> > Thanks for your help. =)
> > 
> > Sungwoo
> 
> 
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Raymond Wiker
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <86k89ogj8w.fsf@raw.grenland.fast.no>
"Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:

> Wow... I think you got what I want with 'do' macro. =)
> What is (ref-point-x ???) ?
> It looks that I need something more to extract from ref-point to
> ref-point-x and ref-point-y? 

        I guess the assumption is that ref-point is a lisp `struct',
with members x and y. ref-point-x and ref-point-y are 
then accessor methods for x and y in instances of ref-point. Further,
ref-array holds an array of ref-points. Similarly for stroke-point... 

-- 
Raymond Wiker
·············@fast.no
From: Joe Marshall
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <r93wf3hd.fsf@content-integrity.com>
"Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:

> Wow... I think you got what I want with 'do' macro. =)
> What is (ref-point-x ???) ?
> It looks that I need something more to extract from ref-point to
> ref-point-x and ref-point-y? 

Well, presumably a point has an x and y coordinate, but the array
seems to be one dimensional.  If the array were two dimensional, then
rather than this:

(let* ((ref-point    (aref ref-array ref-index))
       (ref-point-x  ???)
       (ref-point-y  ???)

I would write this:

(let ((ref-point-x (aref ref-array ref-index 0))
      (ref-point-y (aref ref-array ref-index 1)))

or some variation on this.



> 
> Thanks for your help. =)
> 
> Sungwoo
> 
> 
> In article <············@content-integrity.com>, Joe Marshall
> <···@content-integrity.com> wrote:
> 
> > I'm not sure I understand the problem fully, but is this on the right
> > track? 
> > 
> > (do ((ref-index      0 (1+ ref-index))
> >      (stroke-index   0 (+ stroke-index stride))
> >      (total-distance 0 (let* ((ref-point    (aref ref-array ref-index))
> >                               (ref-point-x  ???)
> >                               (ref-point-y  ???)
> >                               (stroke-point (aref stroke-array stroke-index))
> >                               (stroke-point-x ???)
> >                               (stroke-point-y ???))
> >                           (+ total-distance
> >                              (sqrt (+ (expt (- ref-point-x stroke-point-x) 2)
> >                                       (expt (- ref-point-y stroke-point-y)
> > 2)))))))
> >      ((or (> ref-index   ref-limit)
> >           (> strok-index stroke-limit)) total-distance))
> > 
> > 
> > "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> > 
> > > Hello,
> > > 
> > > I would like to calculate following codes within a specific iteration
> > > over a sequence of integers. 
> > > 
> > > (setf total-distance 0)
> > > (setf respective-distance 
> > >    (sqrt (+ (expt (- ref-point-x stroke-point-x) 2) 
> > >             (expt (- ref-point-y stroke-point-y) 2))))
> > > (setf total-distance (+ total-distance respective-distance)))
> > > 
> > > Suppose that the whole stroke points (N) are in an Array form, and I
> > > want to get a specific points with the intervals (M).
> > > 
> > > For example, if N = 100 and M = 3, then 
> > > 3, 6, 9, 12, ... 99th point are used to calculate the above code.
> > > The value of 'stroke-point-x' and 'stroke-point-y' should be changed
> > > with every iteration.
> > > 
> > > In addition, the ref-point (R) are also in an Array form, and I want to
> > > get every points one by one when the stroke point (N) is changed.
> > > 
> > > For example, Array R has {1, ... , 33} and Array N has {1, ... , 100},
> > > then calculate the above code with R(1), N(3)
> > >                                    R(2), N(6)
> > >                                    ...
> > >                                   R(32), N(96)
> > >                                   R(33), N(99)
> > > 
> > >   
> > > 1. In this case, which function could I use?
> > >    I took a look the function 'do' and 'dotimes', but still vague.
> > > 2. How can I perform two iteration simultaneously?
> > > 3. How can I get the nth element in ARRAY?
> > > 
> > > Sorry about too buggy question.
> > > Thanks for your help. =)
> > > 
> > > Sungwoo
> > 
> > 
> > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> > -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Sungwoo, Lim
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <281120001657295639%sungwoo@cad.strath.ac.uk>
The stroke-array stores every points of a sketch stroke.
Basically, the stroke-array is three dimensional coordinates, but for
now, only x and y coordinates will be used as (x, y, 0).
If I don't use z coordinates right now, is it ok to leave it and code
as 

(let ((ref-point-x (aref ref-array ref-index 0))
      (ref-point-y (aref ref-array ref-index 1)))

or should I consider about third coordinates as well?
Many Thanks,

Sungwoo


In article <············@content-integrity.com>, Joe Marshall
<···@content-integrity.com> wrote:

> "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> 
> > Wow... I think you got what I want with 'do' macro. =)
> > What is (ref-point-x ???) ?
> > It looks that I need something more to extract from ref-point to
> > ref-point-x and ref-point-y? 
> 
> Well, presumably a point has an x and y coordinate, but the array
> seems to be one dimensional.  If the array were two dimensional, then
> rather than this:
> 
> (let* ((ref-point    (aref ref-array ref-index))
>        (ref-point-x  ???)
>        (ref-point-y  ???)
> 
> I would write this:
> 
> (let ((ref-point-x (aref ref-array ref-index 0))
>       (ref-point-y (aref ref-array ref-index 1)))
> 
> or some variation on this.
> 
> 
> 
> > 
> > Thanks for your help. =)
> > 
> > Sungwoo
> > 
> > 
> > In article <············@content-integrity.com>, Joe Marshall
> > <···@content-integrity.com> wrote:
> > 
> > > I'm not sure I understand the problem fully, but is this on the right
> > > track? 
> > > 
> > > (do ((ref-index      0 (1+ ref-index))
> > >      (stroke-index   0 (+ stroke-index stride))
> > >      (total-distance 0 (let* ((ref-point    (aref ref-array ref-index))
> > >                               (ref-point-x  ???)
> > >                               (ref-point-y  ???)
> > >                               (stroke-point (aref stroke-array
> stroke-index))
> > >                               (stroke-point-x ???)
> > >                               (stroke-point-y ???))
> > >                           (+ total-distance
> > >                              (sqrt (+ (expt (- ref-point-x
> stroke-point-x) 2)
> > >                                       (expt (- ref-point-y stroke-point-y)
> > > 2)))))))
> > >      ((or (> ref-index   ref-limit)
> > >           (> strok-index stroke-limit)) total-distance))
> > > 
> > > 
> > > "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> > > 
> > > > Hello,
> > > > 
> > > > I would like to calculate following codes within a specific iteration
> > > > over a sequence of integers. 
> > > > 
> > > > (setf total-distance 0)
> > > > (setf respective-distance 
> > > >    (sqrt (+ (expt (- ref-point-x stroke-point-x) 2) 
> > > >             (expt (- ref-point-y stroke-point-y) 2))))
> > > > (setf total-distance (+ total-distance respective-distance)))
> > > > 
> > > > Suppose that the whole stroke points (N) are in an Array form, and I
> > > > want to get a specific points with the intervals (M).
> > > > 
> > > > For example, if N = 100 and M = 3, then 
> > > > 3, 6, 9, 12, ... 99th point are used to calculate the above code.
> > > > The value of 'stroke-point-x' and 'stroke-point-y' should be changed
> > > > with every iteration.
> > > > 
> > > > In addition, the ref-point (R) are also in an Array form, and I want to
> > > > get every points one by one when the stroke point (N) is changed.
> > > > 
> > > > For example, Array R has {1, ... , 33} and Array N has {1, ... , 100},
> > > > then calculate the above code with R(1), N(3)
> > > >                                    R(2), N(6)
> > > >                                    ...
> > > >                                   R(32), N(96)
> > > >                                   R(33), N(99)
> > > > 
> > > >   
> > > > 1. In this case, which function could I use?
> > > >    I took a look the function 'do' and 'dotimes', but still vague.
> > > > 2. How can I perform two iteration simultaneously?
> > > > 3. How can I get the nth element in ARRAY?
> > > > 
> > > > Sorry about too buggy question.
> > > > Thanks for your help. =)
> > > > 
> > > > Sungwoo
> > > 
> > > 
> > > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> > > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> > > -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
> 
> 
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Joe Marshall
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <elzwf2uz.fsf@content-integrity.com>
"Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:

> The stroke-array stores every points of a sketch stroke.
> Basically, the stroke-array is three dimensional coordinates, but for
> now, only x and y coordinates will be used as (x, y, 0).
> If I don't use z coordinates right now, is it ok to leave it and code
> as 
> 
> (let ((ref-point-x (aref ref-array ref-index 0))
>       (ref-point-y (aref ref-array ref-index 1)))
> 
> or should I consider about third coordinates as well?

Well, those choices are up to you.  I certainly would plan for the
third co-ordinate if it is already allocated (so when you upgrade, it
just magically works).



> Many Thanks,
> 
> Sungwoo
> 
> 
> In article <············@content-integrity.com>, Joe Marshall
> <···@content-integrity.com> wrote:
> 
> > "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> > 
> > > Wow... I think you got what I want with 'do' macro. =)
> > > What is (ref-point-x ???) ?
> > > It looks that I need something more to extract from ref-point to
> > > ref-point-x and ref-point-y? 
> > 
> > Well, presumably a point has an x and y coordinate, but the array
> > seems to be one dimensional.  If the array were two dimensional, then
> > rather than this:
> > 
> > (let* ((ref-point    (aref ref-array ref-index))
> >        (ref-point-x  ???)
> >        (ref-point-y  ???)
> > 
> > I would write this:
> > 
> > (let ((ref-point-x (aref ref-array ref-index 0))
> >       (ref-point-y (aref ref-array ref-index 1)))
> > 
> > or some variation on this.
> > 
> > 
> > 
> > > 
> > > Thanks for your help. =)
> > > 
> > > Sungwoo
> > > 
> > > 
> > > In article <············@content-integrity.com>, Joe Marshall
> > > <···@content-integrity.com> wrote:
> > > 
> > > > I'm not sure I understand the problem fully, but is this on the right
> > > > track? 
> > > > 
> > > > (do ((ref-index      0 (1+ ref-index))
> > > >      (stroke-index   0 (+ stroke-index stride))
> > > >      (total-distance 0 (let* ((ref-point    (aref ref-array ref-index))
> > > >                               (ref-point-x  ???)
> > > >                               (ref-point-y  ???)
> > > >                               (stroke-point (aref stroke-array
> > stroke-index))
> > > >                               (stroke-point-x ???)
> > > >                               (stroke-point-y ???))
> > > >                           (+ total-distance
> > > >                              (sqrt (+ (expt (- ref-point-x
> > stroke-point-x) 2)
> > > >                                       (expt (- ref-point-y stroke-point-y)
> > > > 2)))))))
> > > >      ((or (> ref-index   ref-limit)
> > > >           (> strok-index stroke-limit)) total-distance))
> > > > 
> > > > 
> > > > "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> > > > 
> > > > > Hello,
> > > > > 
> > > > > I would like to calculate following codes within a specific iteration
> > > > > over a sequence of integers. 
> > > > > 
> > > > > (setf total-distance 0)
> > > > > (setf respective-distance 
> > > > >    (sqrt (+ (expt (- ref-point-x stroke-point-x) 2) 
> > > > >             (expt (- ref-point-y stroke-point-y) 2))))
> > > > > (setf total-distance (+ total-distance respective-distance)))
> > > > > 
> > > > > Suppose that the whole stroke points (N) are in an Array form, and I
> > > > > want to get a specific points with the intervals (M).
> > > > > 
> > > > > For example, if N = 100 and M = 3, then 
> > > > > 3, 6, 9, 12, ... 99th point are used to calculate the above code.
> > > > > The value of 'stroke-point-x' and 'stroke-point-y' should be changed
> > > > > with every iteration.
> > > > > 
> > > > > In addition, the ref-point (R) are also in an Array form, and I want to
> > > > > get every points one by one when the stroke point (N) is changed.
> > > > > 
> > > > > For example, Array R has {1, ... , 33} and Array N has {1, ... , 100},
> > > > > then calculate the above code with R(1), N(3)
> > > > >                                    R(2), N(6)
> > > > >                                    ...
> > > > >                                   R(32), N(96)
> > > > >                                   R(33), N(99)
> > > > > 
> > > > >   
> > > > > 1. In this case, which function could I use?
> > > > >    I took a look the function 'do' and 'dotimes', but still vague.
> > > > > 2. How can I perform two iteration simultaneously?
> > > > > 3. How can I get the nth element in ARRAY?
> > > > > 
> > > > > Sorry about too buggy question.
> > > > > Thanks for your help. =)
> > > > > 
> > > > > Sungwoo
> > > > 
> > > > 
> > > > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> > > > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> > > > -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
> > 
> > 
> > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> > -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Sungwoo, Lim
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <281120001832017843%sungwoo@cad.strath.ac.uk>
Maybe two different version could be used?
I am not sure that the 'loop' code is correct, but if so,
which one gives fast performance?
And which one is recommended to use?
Thanks,

;-----------------------------------------------------
(do ((ref-index      0 (1+ ref-index))
     (stroke-index   0 (+ stroke-index stride))
     (total-distance 0 (let ((ref-point-x (aref ref-array ref-index 0))
                             (ref-point-y (aref ref-array ref-index 1))
                             (stroke-point-x (aref stroke-array
stroke-index 0))
                             (stroke-point-y (aref stroke-array
stroke-index 1)))
                         (+ total-distance
                            (sqrt (+ (expt (- ref-point-x
stroke-point-x) 2)
                                     (expt (- ref-point-y
stroke-point-y) 2)))))))
    ((or (> ref-index   ref-limit)
         (> stroke-index stroke-limit)) total-distance))

;-----------------------------------------------------
(loop for ref-index from 0 to ref-limit 
      for stroke-index from 0 upto stroke-limit by strives

      collect (let ((ref-point-x (aref ref-array ref-index 0))
                    (ref-point-y (aref ref-array ref-index 1))
                    (stroke-point-x (aref stroke-array stroke-index 0))
                    (stroke-point-y (aref stroke-array stroke-index 1)))
                (setf total-distance (+ total-distance 
                                        (setf respective-distance 
                                              (sqrt (+ (expt (-
ref-point-x stroke-point-x) 2) 
                                                       (expt (-
ref-point-y stroke-point-y) 2))))))))    
;-----------------------------------------------------

Sungwoo


In article <············@content-integrity.com>, Joe Marshall
<···@content-integrity.com> wrote:

> "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> 
> > The stroke-array stores every points of a sketch stroke.
> > Basically, the stroke-array is three dimensional coordinates, but for
> > now, only x and y coordinates will be used as (x, y, 0).
> > If I don't use z coordinates right now, is it ok to leave it and code
> > as 
> > 
> > (let ((ref-point-x (aref ref-array ref-index 0))
> >       (ref-point-y (aref ref-array ref-index 1)))
> > 
> > or should I consider about third coordinates as well?
> 
> Well, those choices are up to you.  I certainly would plan for the
> third co-ordinate if it is already allocated (so when you upgrade, it
> just magically works).
> 
> 
> 
> > Many Thanks,
> > 
> > Sungwoo
> > 
> > 
> > In article <············@content-integrity.com>, Joe Marshall
> > <···@content-integrity.com> wrote:
> > 
> > > "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> > > 
> > > > Wow... I think you got what I want with 'do' macro. =)
> > > > What is (ref-point-x ???) ?
> > > > It looks that I need something more to extract from ref-point to
> > > > ref-point-x and ref-point-y? 
> > > 
> > > Well, presumably a point has an x and y coordinate, but the array
> > > seems to be one dimensional.  If the array were two dimensional, then
> > > rather than this:
> > > 
> > > (let* ((ref-point    (aref ref-array ref-index))
> > >        (ref-point-x  ???)
> > >        (ref-point-y  ???)
> > > 
> > > I would write this:
> > > 
> > > (let ((ref-point-x (aref ref-array ref-index 0))
> > >       (ref-point-y (aref ref-array ref-index 1)))
> > > 
> > > or some variation on this.
> > > 
> > > 
> > > 
> > > > 
> > > > Thanks for your help. =)
> > > > 
> > > > Sungwoo
> > > > 
> > > > 
> > > > In article <············@content-integrity.com>, Joe Marshall
> > > > <···@content-integrity.com> wrote:
> > > > 
> > > > > I'm not sure I understand the problem fully, but is this on the right
> > > > > track? 
> > > > > 
> > > > > (do ((ref-index      0 (1+ ref-index))
> > > > >      (stroke-index   0 (+ stroke-index stride))
> > > > >      (total-distance 0 (let* ((ref-point    (aref ref-array
> ref-index))
> > > > >                               (ref-point-x  ???)
> > > > >                               (ref-point-y  ???)
> > > > >                               (stroke-point (aref stroke-array
> > > stroke-index))
> > > > >                               (stroke-point-x ???)
> > > > >                               (stroke-point-y ???))
> > > > >                           (+ total-distance
> > > > >                              (sqrt (+ (expt (- ref-point-x
> > > stroke-point-x) 2)
> > > > >                                       (expt (- ref-point-y
> stroke-point-y)
> > > > > 2)))))))
> > > > >      ((or (> ref-index   ref-limit)
> > > > >           (> strok-index stroke-limit)) total-distance))
> > > > > 
> > > > > 
> > > > > "Sungwoo, Lim" <·······@cad.strath.ac.uk> writes:
> > > > > 
> > > > > > Hello,
> > > > > > 
> > > > > > I would like to calculate following codes within a specific
> > > > > > iteration
> > > > > > over a sequence of integers. 
> > > > > > 
> > > > > > (setf total-distance 0)
> > > > > > (setf respective-distance 
> > > > > >    (sqrt (+ (expt (- ref-point-x stroke-point-x) 2) 
> > > > > >             (expt (- ref-point-y stroke-point-y) 2))))
> > > > > > (setf total-distance (+ total-distance respective-distance)))
> > > > > > 
> > > > > > Suppose that the whole stroke points (N) are in an Array form, and I
> > > > > > want to get a specific points with the intervals (M).
> > > > > > 
> > > > > > For example, if N = 100 and M = 3, then 
> > > > > > 3, 6, 9, 12, ... 99th point are used to calculate the above code.
> > > > > > The value of 'stroke-point-x' and 'stroke-point-y' should be changed
> > > > > > with every iteration.
> > > > > > 
> > > > > > In addition, the ref-point (R) are also in an Array form, and I
> > > > > > want to
> > > > > > get every points one by one when the stroke point (N) is changed.
> > > > > > 
> > > > > > For example, Array R has {1, ... , 33} and Array N has {1, ... ,
> > > > > > 100},
> > > > > > then calculate the above code with R(1), N(3)
> > > > > >                                    R(2), N(6)
> > > > > >                                    ...
> > > > > >                                   R(32), N(96)
> > > > > >                                   R(33), N(99)
> > > > > > 
> > > > > >   
> > > > > > 1. In this case, which function could I use?
> > > > > >    I took a look the function 'do' and 'dotimes', but still vague.
> > > > > > 2. How can I perform two iteration simultaneously?
> > > > > > 3. How can I get the nth element in ARRAY?
> > > > > > 
> > > > > > Sorry about too buggy question.
> > > > > > Thanks for your help. =)
> > > > > > 
> > > > > > Sungwoo
> > > > > 
> > > > > 
> > > > > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> > > > > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> > > > > -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
> > > 
> > > 
> > > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> > > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> > > -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
> 
> 
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Thomas A. Russ
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <ymiaeaizj6a.fsf@sevak.isi.edu>
The two iteration constructs should be roughly similar in performance.
You should use the one that you find easiest to understand and maintain.

BTW, a simpler version of your Loop code would be:

(loop for ref-index from 0 to ref-limit 
      for stroke-index from 0 upto stroke-limit by stride
      sum (sqrt (+ (expt (- (aref ref-array ref-index 0)
			    (aref stroke-array stroke-index 0))
                         2) 
                   (expt (- (aref ref-array ref-index 1)
			    (aref stroke-array stroke-index 1))
                         2))))

If this code is truly a performance bottleneck for you, you might want
to use multiplication for squaring instead of calling EXPT, since
(depending on what the compiler does) it could be a lot faster:

(loop for ref-index from 0 to ref-limit 
      for stroke-index from 0 upto stroke-limit by stride
      as delta-x = (- (aref ref-array ref-index 0)
	              (aref stroke-array stroke-index 0))
      as delta-y = (- (aref ref-array ref-index 0)
	              (aref stroke-array stroke-index 1))
      sum (sqrt (+ (* delta-x delta-x) (* delta-y delta-y))))



-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Sungwoo, Lim
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <301120001121497404%sungwoo@cad.strath.ac.uk>
Many thanks. =)

Sungwoo


In article <···············@sevak.isi.edu>, Thomas A. Russ
<···@sevak.isi.edu> wrote:

> The two iteration constructs should be roughly similar in performance.
> You should use the one that you find easiest to understand and maintain.
> 
> BTW, a simpler version of your Loop code would be:
> 
> (loop for ref-index from 0 to ref-limit 
>       for stroke-index from 0 upto stroke-limit by stride
>       sum (sqrt (+ (expt (- (aref ref-array ref-index 0)
>                             (aref stroke-array stroke-index 0))
>                          2) 
>                    (expt (- (aref ref-array ref-index 1)
>                             (aref stroke-array stroke-index 1))
>                          2))))
> 
> If this code is truly a performance bottleneck for you, you might want
> to use multiplication for squaring instead of calling EXPT, since
> (depending on what the compiler does) it could be a lot faster:
> 
> (loop for ref-index from 0 to ref-limit 
>       for stroke-index from 0 upto stroke-limit by stride
>       as delta-x = (- (aref ref-array ref-index 0)
>                       (aref stroke-array stroke-index 0))
>       as delta-y = (- (aref ref-array ref-index 0)
>                       (aref stroke-array stroke-index 1))
>       sum (sqrt (+ (* delta-x delta-x) (* delta-y delta-y))))
From: Xenophon Fenderson the Carbon(d)ated
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <w4oaeagyz0x.fsf@lovecraft.irtnog.org>
>>>>> "Thomas" == Thomas A Russ <···@sevak.isi.edu> writes:

    Thomas> If this code is truly a performance bottleneck for you,
    Thomas> you might want to use multiplication for squaring instead
    Thomas> of calling EXPT, since (depending on what the compiler
    Thomas> does) it could be a lot faster:

Couldn't one define a compiler macro for this purpose?  E.g.,

(DEFINE-COMPILER-MACRO EXPT (&WHOLE FORM ARG POWER)
  (COND
   ((= POWER 2) `(* ,ARG ,ARG))
   (T FORM)))

In my opinion, this results in clearer code, i.e. the intent to
exponentiate is not obscured by the optimization (integer multiply
instruction instead of an integer exponentiation instruction when
POWER is 2 or 3).

-- 
THE SPICE GIRLS MUST FLOW.
From: Aaron Crane
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <djhf4nmyjx.fsf@planet.dcs.ed.ac.uk>
In article <···············@lovecraft.irtnog.org>,
········@irtnog.org (Xenophon Fenderson the Carbon(d)ated) writes:
> (DEFINE-COMPILER-MACRO EXPT (&WHOLE FORM ARG POWER)
>   (COND
>    ((= POWER 2) `(* ,ARG ,ARG))
>    (T FORM)))

It would be better for the expansion to introduce a (gensymmed) temporary
variable for the argument; otherwise, an innocuous-looking fragment like

    (expt (incf foo) 2)

will fail.

-- 
Aaron Crane
From: ········@hex.net
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <wkr93sumvl.fsf@441715.i-did-not-set--mail-host-address--so-shoot-me>
>>>>> "XF" == Xenophon Fenderson the Carbon(d)ated <········@irtnog.org> writes:

>>>>> "Thomas" == Thomas A Russ <···@sevak.isi.edu> writes:
Thomas> If this code is truly a performance bottleneck for you,
Thomas> you might want to use multiplication for squaring instead
Thomas> of calling EXPT, since (depending on what the compiler
Thomas> does) it could be a lot faster:

XF> Couldn't one define a compiler macro for this purpose?  E.g.,

XF> (DEFINE-COMPILER-MACRO EXPT (&WHOLE FORM ARG POWER) (COND ((=
XF> POWER 2) `(* ,ARG ,ARG)) (T FORM)))

XF> In my opinion, this results in clearer code, i.e. the intent to
XF> exponentiate is not obscured by the optimization (integer multiply
XF> instruction instead of an integer exponentiation instruction when
XF> POWER is 2 or 3).

On the other hand, this obscures the effect that it's using different
methods for different values.

More importantly, the macro appears to suffer from Variable Capture;
ARG may get evaluated multiple times.

XF> -- THE SPICE GIRLS MUST FLOW.

Ew...  I don't think that was what Herbert meant, not that his son
couldn't have pulled this into the "new generation" of books...
-- 
(concatenate 'string "cbbrowne" ·@hex.net")
<http://www.ntlug.org/~cbbrowne/>
Do not worry  about the bullet that  has got your name on  it. It will
hit you and it will kill  you, no questions asked. The rounds to worry
about are the ones marked: TO WHOM IT MAY CONCERN.
From: Xenophon Fenderson the Carbon(d)ated
Subject: Re: Iteration within specific intervals?
Date: 
Message-ID: <w4or93rxvjj.fsf@lovecraft.irtnog.org>
Mr. Russ also pointed out that my compiler macro on EXPT is not
allowed, as it may over-write an implementation's pre-existing macro
on same.  I neglected to read all the way through the documentation on
DEFINE-COMPILER-MACRO.  :(

The quote "THE SPICE GIRLS MUST FLOW." is Stephen Tanner's fault, not
mine.  :) Search in alt.religion.kibology around 4 August 1997 for the
original message.

-- 
"Yippee!  We will have to celebrate by having sex sometime."