!
> ;;Grouped into a list.
> (setf chunck (/ (array-dimension store 0) (length ls)))
> (setf chorder (loop for i from 0 to chunck collect i))
> (setf jj 0)
> (setf n 0)
> (setf arr (make-array (list (length ls) 2)))
> (while (< jj rows)
> (setf place (loop for i from jj below (+ jj chunck) collect (aref
> store i 2)))
> (setf (aref arr n 0) (aref store (+ jj (position-of-min place
> chorder)) 0))
> (setf (aref arr n 1) (aref store (+ jj (position-of-min place
> chorder)) 3))
> (setf n (1+ n))
> (setf jj (+ jj chunck)))
> ;;Store the arr array in a list.
> ;;Reset ls and Counter first.
> (setf ls nil)
> (setf counter nil)
You can collapse multiple setf's:
(setf chunck (/ (array-dimension store 0) (length ls))
chorder (loop for i from 0 to chunck collect i)
jj 0
n 0
arr (make-array (list (length ls) 2)))
(while (< jj rows)
(setf place (loop for i from jj below (+ jj chunck) collect (aref
store i 2))
(aref arr n 0) (aref store (+ jj (position-of-min place
chorder)) 0)
(aref arr n 1) (aref store (+ jj (position-of-min place
chorder)) 3)
n (1+ n)
jj (+ jj chunck)))
;;Store the arr array in a list.
;;Reset ls and Counter first.
(setf ls nil
counter nil)
--
A
.
In article <············@srv.cyf-kr.edu.pl>,
Aleksander Nabag�o <·@ap.krakow.pl> wrote:
> !
>
> > ;;Grouped into a list.
> > (setf chunck (/ (array-dimension store 0) (length ls)))
> > (setf chorder (loop for i from 0 to chunck collect i))
> > (setf jj 0)
> > (setf n 0)
> > (setf arr (make-array (list (length ls) 2)))
> > (while (< jj rows)
> > (setf place (loop for i from jj below (+ jj chunck) collect (aref
> > store i 2)))
> > (setf (aref arr n 0) (aref store (+ jj (position-of-min place
> > chorder)) 0))
> > (setf (aref arr n 1) (aref store (+ jj (position-of-min place
> > chorder)) 3))
> > (setf n (1+ n))
> > (setf jj (+ jj chunck)))
> > ;;Store the arr array in a list.
> > ;;Reset ls and Counter first.
> > (setf ls nil)
> > (setf counter nil)
> You can collapse multiple setf's:
>
> (setf chunck (/ (array-dimension store 0) (length ls))
> chorder (loop for i from 0 to chunck collect i)
> jj 0
> n 0
> arr (make-array (list (length ls) 2)))
> (while (< jj rows)
> (setf place (loop for i from jj below (+ jj chunck) collect (aref
> store i 2))
> (aref arr n 0) (aref store (+ jj (position-of-min place
> chorder)) 0)
> (aref arr n 1) (aref store (+ jj (position-of-min place
> chorder)) 3)
> n (1+ n)
> jj (+ jj chunck)))
> ;;Store the arr array in a list.
> ;;Reset ls and Counter first.
> (setf ls nil
> counter nil)
I would not start with that. I would try to get rid of SETFs if possible.
But sometimes you have the choice:
a)
(setf x (foo-x bar)
y (foo-y bar))
b)
(setf age-sum (foo bar))
(setf delta (baz 'bar))
In a) it makes sense to get the assignment into one SETF, since
they seem to set x/y coordinates. It makes moving around both together easier.
In b) these are two different code snippets possibly not closely related
by the intent of the programmer. During development keeping them
in two SETF forms makes manipulation slightly easier.
So as a 'rule' I would not collapse multiple SETFs into one, unless the
forms are somehow 'related'.
--
http://lispm.dyndns.org/
Rainer Joswig <······@lisp.de> writes:
> I would not start with that. I would try to get rid of SETFs if possible.
>
> But sometimes you have the choice:
>
> a)
>
> (setf x (foo-x bar)
> y (foo-y bar))
(with-accessors ((x foo-x)
(y foo-y)) bar
(do-something-with x y))
> b)
>
> (setf age-sum (foo bar))
> (setf delta (baz 'bar))
(let ((age-sum (foo bar))
(delta (baz 'bar)))
(do-something-with age-sum delta))
> In a) it makes sense to get the assignment into one SETF, since
> they seem to set x/y coordinates. It makes moving around both together easier.
>
> In b) these are two different code snippets possibly not closely related
> by the intent of the programmer. During development keeping them
> in two SETF forms makes manipulation slightly easier.
>
> So as a 'rule' I would not collapse multiple SETFs into one, unless the
> forms are somehow 'related'.
>
> --
> http://lispm.dyndns.org/
--
__Pascal Bourguignon__
!
Rainer Joswig napisa�(a):
>> (setf chunck (/ (array-dimension store 0) (length ls))
>> chorder (loop for i from 0 to chunck collect i)
>> jj 0
>> n 0
>> arr (make-array (list (length ls) 2)))
>> (while (< jj rows)
>> (setf place (loop for i from jj below (+ jj chunck) collect (aref
>> store i 2))
>> (aref arr n 0) (aref store (+ jj (position-of-min place
>> chorder)) 0)
>> (aref arr n 1) (aref store (+ jj (position-of-min place
>> chorder)) 3)
>> n (1+ n)
>> jj (+ jj chunck)))
>> ;;Store the arr array in a list.
>> ;;Reset ls and Counter first.
>> (setf ls nil
>> counter nil)
>
> I would not start with that.
This makes code look lighter, fewer '(' and ')'.
I would try to get rid of SETFs if possible.
The '(while P body)' may be better than '(do ...)'
only when P does not depend on initialized
and incremented counter(s), so:
(do ((jj 0 (+ jj chunck)) (n 0 (1+ n)))
((not (< jj rows)))
(setf ... ))
instead of
>> jj 0
>> n 0
>> arr (make-array (list (length ls) 2)))
>> (while (< jj rows)
>> (setf place (loop for i from jj below (+ jj chunck) collect (aref
>> store i 2))
>> (aref arr n 0) (aref store (+ jj (position-of-min place
>> chorder)) 0)
>> (aref arr n 1) (aref store (+ jj (position-of-min place
>> chorder)) 3)
>> n (1+ n)
>> jj (+ jj chunck)))
>
> But sometimes you have the choice:
>
> a)
>
> (setf x (foo-x bar)
> y (foo-y bar))
>
> b)
>
> (setf age-sum (foo bar))
> (setf delta (baz 'bar))
>
>
> In a) it makes sense to get the assignment into one SETF, since
> they seem to set x/y coordinates. It makes moving around both together easier.
>
> In b) these are two different code snippets possibly not closely related
> by the intent of the programmer. During development keeping them
> in two SETF forms makes manipulation slightly easier.
>
> So as a 'rule' I would not collapse multiple SETFs into one, unless the
> forms are somehow 'related'.
Indent or empty line is lighter than '(setf ...)':
(setf x (foo-x bar)
y (foo-y bar) ; semantically related,
; half-way abstracted
age-sum (foo bar)
delta (baz 'bar))
Sequentialy related assignments tend to pattern like:
(setf a b
b c
c d)
--
A
.
In article <············@srv.cyf-kr.edu.pl>,
Aleksander Nabag�o <·@ap.krakow.pl> wrote:
> !
>
> Rainer Joswig napisa�(a):
> >> (setf chunck (/ (array-dimension store 0) (length ls))
> >> chorder (loop for i from 0 to chunck collect i)
> >> jj 0
> >> n 0
> >> arr (make-array (list (length ls) 2)))
> >> (while (< jj rows)
> >> (setf place (loop for i from jj below (+ jj chunck) collect (aref
> >> store i 2))
> >> (aref arr n 0) (aref store (+ jj (position-of-min place
> >> chorder)) 0)
> >> (aref arr n 1) (aref store (+ jj (position-of-min place
> >> chorder)) 3)
> >> n (1+ n)
> >> jj (+ jj chunck)))
> >> ;;Store the arr array in a list.
> >> ;;Reset ls and Counter first.
> >> (setf ls nil
> >> counter nil)
> >
> > I would not start with that.
> This makes code look lighter, fewer '(' and ')'.
In Lisp the goal is not to have fewer '(' and ')' in source code.
The parentheses are a feature that group things. Using the editor commands
on S-expressions you can manipulate code with parentheses more
easily than without.
Check out:
http://www.foldr.org/~michaelw/emacs/redshank/
--
http://lispm.dyndns.org/