From: Wade Humeniuk
Subject: Re: LISP PROGRAMMING
Date: 
Message-ID: <U9ccd.28684$qU.13151@clgrps13>
sharda mishra wrote:
> Hello every one
> 
> PLEASE help me  writing the following program in LISP language
> ;-
> 
> Write a LISP function ODD-REVERSE  which reverses the elements
> occuring at odd numbered position but keeps the elements at even
> numbered position in their given position.
> 
> for example:-
> 
> ODD-REVERSE  '(5 7 (6 4 )3 12 (2 1) 9)) returns the list
> 
> (9 7  12  3 (6 4) (2 1) 5)

Your example does not seem to match the description.  The first element
is in a even position and is not swapped. Indexes start from 0.

Your homework was probably already due so here is another solution.
You will need to find, learn and install the ITERATE package, or translate it
into loop.

(defun odd-reverse (list)
   (let ((length (length list)))
     (cond
      ((<= length 3) list)
      (t
       (let ((list (copy-list list))
             (first-odd 1)
             (last-odd (- length (if (evenp length) 1 2))))
         (iter
           (for foi from first-odd by 2)
           (for loi from last-odd by -2)
           (if (<= loi foi)
               (return list)
             (rotatef (elt list foi) (elt list loi)))))))))

CL-USER 29 > (odd-reverse '(5 7 (6 4 )3 12 (2 1) 9))
(5 (2 1) (6 4) 3 12 7 9)

Wade

From: Pascal Costanza
Subject: Re: LISP PROGRAMMING
Date: 
Message-ID: <ckrm86$igv$1@newsreader2.netcologne.de>
Wade Humeniuk wrote:
> sharda mishra wrote:
> 
>> Hello every one
>>
>> PLEASE help me  writing the following program in LISP language
>> ;-
>>
>> Write a LISP function ODD-REVERSE  which reverses the elements
>> occuring at odd numbered position but keeps the elements at even
>> numbered position in their given position.
>>
>> for example:-
>>
>> ODD-REVERSE  '(5 7 (6 4 )3 12 (2 1) 9)) returns the list
>>
>> (9 7  12  3 (6 4) (2 1) 5)
> 
> 
> Your example does not seem to match the description.  The first element
> is in a even position and is not swapped. Indexes start from 0.
> 
> Your homework was probably already due so here is another solution.

(defun odd-reverse (list)
   (let ((result
          (loop for (odd even) on list by #'cddr
                collect odd into odds
                collect even into evens
                finally (return (loop for odd in (reverse odds)
                                      for even in evens
                                      collect odd
                                      collect even)))))
     (subseq result 0 (list-length list))))


Pascal

-- 
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
From: Tayssir John Gabbour
Subject: Re: LISP PROGRAMMING
Date: 
Message-ID: <866764be.0410161722.6b1cb64a@posting.google.com>
Pascal Costanza <········@web.de> wrote in message news:<············@newsreader2.netcologne.de>...
> (defun odd-reverse (list)
>    (let ((result
>           (loop for (odd even) on list by #'cddr
>                 collect odd into odds
>                 collect even into evens
>                 finally (return (loop for odd in (reverse odds)
>                                       for even in evens
>                                       collect odd
>                                       collect even)))))
>      (subseq result 0 (list-length list))))

Another viewpoint:

(defun reverse-odd-elems (list)
  (loop with v       = (coerce list 'simple-vector)
        with len     = (length list)
        with odd-len = (if (evenp len) len (1- len))
        for i from 0 upto (floor odd-len 2)
        when (oddp i) do (rotatef (aref v i) (aref v (- odd-len i)))
        finally (return (coerce v 'list))))


This is what I call "array oriented programming." 

Someone was surprised recently when I mentioned that Common Lisp
supported object-oriented programming. AAUGH. I can't even imagine
what people think about Lisp's bad-ass arrays.


MfG,
Tayssir

..
Want a good video talk on the standardization of Common Lisp's OOP
subsystem?
http://www.archive.org/movies/details-db.php?collection=opensource_movies&collectionid=AV_Geek_Skip_20021211091208&PHPSESSID=d9de32ce5c3acf73e1f3663f7c6ecd38
From: Pascal Costanza
Subject: Video on CLOS, was Re: LISP PROGRAMMING
Date: 
Message-ID: <ckube3$54j$2@newsreader2.netcologne.de>
Tayssir John Gabbour wrote:

> Want a good video talk on the standardization of Common Lisp's OOP
> subsystem?
> http://www.archive.org/movies/details-db.php?collection=opensource_movies&collectionid=AV_Geek_Skip_20021211091208&PHPSESSID=d9de32ce5c3acf73e1f3663f7c6ecd38

Very nice find! Thanks a lot for that. I've found it exciting to see the 
stage CLOS has been in in 1987. (The syntax for eql specializers at that 
time is quite shocking though. ;)

Very impressive how far ahead of their time the CLOS designers were...


Pascal

-- 
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
From: Tayssir John Gabbour
Subject: Re: Video on CLOS, was Re: LISP PROGRAMMING
Date: 
Message-ID: <866764be.0410172327.1226d7ed@posting.google.com>
Pascal Costanza <········@web.de> wrote in message news:<············@newsreader2.netcologne.de>...
> Tayssir John Gabbour wrote:
> > Want a good video talk on the standardization of Common Lisp's OOP
> > subsystem?
> > http://www.archive.org/movies/details-db.php?collection=opensource_movies&collectionid=AV_Geek_Skip_20021211091208&PHPSESSID=d9de32ce5c3acf73e1f3663f7c6ecd38
> 
> Very nice find! Thanks a lot for that. I've found it exciting to see the 
> stage CLOS has been in in 1987. (The syntax for eql specializers at that 
> time is quite shocking though. ;)
> 
> Very impressive how far ahead of their time the CLOS designers were...

There's more where that came from.
http://www.archive.org/movies/movieslisting-browse.php?collection=opensource_movies&cat=Technology:%20Computers:%20History
http://www.cs.ualberta.ca/research/videos/distdate.php
http://murl.microsoft.com/ContentMap.asp

Unfortunately the Tom Knight talk on symbolic computers seems missing,
and I'm asking about it. (Apparently he was working at Symbolics.) I'm
watching the William Clinger talk "Compiler Optimization for Symbolic
Languages" right now.

The Alan Kay one was interesting; I think the most interesting order
is to see part 2 first. I assume that was the one you mentioned to me
about the three types of thinking, Pascal.

In contrast, while I've only seen the first few minutes so far, John
Backus's FP talk was a bit freaky. It was interesting to think in
terms of composing operators... but for some reason it seemed he
started pushing it in a boring, reductionist, engineering way. In the
same way that databases have that shockingly dull veneer to make it
more respectable to businessmen.

There's a number of other ones I haven't found on digital video yet,
like Hillis and Steele's stuff on the Connection Machine. Also Rattner
might have something interesting on parallel stuff for Erlisp. (Or
not, I don't know.)

If someone knows how to find these various things on tape, I hope
there's some way we can obtain and digitize them.

MfG,
Tayssir
From: Pascal Costanza
Subject: Re: Video on CLOS, was Re: LISP PROGRAMMING
Date: 
Message-ID: <cl1gpv$h6a$4@newsreader2.netcologne.de>
Tayssir John Gabbour wrote:

> There's more where that came from.
> http://www.archive.org/movies/movieslisting-browse.php?collection=opensource_movies&cat=Technology:%20Computers:%20History
> http://www.cs.ualberta.ca/research/videos/distdate.php
> http://murl.microsoft.com/ContentMap.asp

Cool.

> The Alan Kay one was interesting; I think the most interesting order
> is to see part 2 first. I assume that was the one you mentioned to me
> about the three types of thinking, Pascal.

Er, no. Does he mention that?


Pascal

-- 
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
From: Tayssir John Gabbour
Subject: Re: Video on CLOS, was Re: LISP PROGRAMMING
Date: 
Message-ID: <866764be.0410182131.15b67af2@posting.google.com>
Pascal Costanza <········@web.de> wrote in message news:<············@newsreader2.netcologne.de>...
> Tayssir John Gabbour wrote:
> > There's more where that came from.
> > http://www.archive.org/movies/movieslisting-browse.php?collection=opensource_movies&cat=Technology:%20Computers:%20History
> > http://www.cs.ualberta.ca/research/videos/distdate.php
> > http://murl.microsoft.com/ContentMap.asp
> 
> Cool.
> 
> > The Alan Kay one was interesting; I think the most interesting order
> > is to see part 2 first. I assume that was the one you mentioned to me
> > about the three types of thinking, Pascal.
> 
> Er, no. Does he mention that?

Yeah, "doing with images makes symbols." Three different models of
thinking. Though you had a different view of the three, and instead of
the "doing" thing, you substituted the one that's kind of hard to
articulate. "Progression," I believe, where things are progressions.

Interestingly, I think Lisp fits not only with that progression model,
but also in the "doing" model. What do people say about Lisp? It's a
ball of mud, mudball of strength. Tactile. I'm curious what the
Interlisp model was like -- visual? Or maybe something altogether
different.
http://groups.google.com/groups?q=common+lisp+killed+interlisp

(Thanks to Bill Clementson for putting this on his blog, reminding me
to post this response sitting in my emacs buffer. ;)


MfG,
Tayssir

..
"I think, oftentimes, the person that knows they can't win is allowed
to speak the most freely."
http://66.90.75.92/suprnova//torrents/2800/Crossfire-20041015-John_Stewart-avi.torrent
http://homepage.mac.com/njenson/movies/jonstewartcrossfire.html
http://transcripts.cnn.com/TRANSCRIPTS/0410/15/cf.01.html

Something more substantive (realaudio):
http://media5.bloomberg.com:443/cgi-bin/getavfile.cgi?A=19030995
From: Pascal Costanza
Subject: Re: Video on CLOS, was Re: LISP PROGRAMMING
Date: 
Message-ID: <cl6pvl$gsg$1@newsreader2.netcologne.de>
Tayssir John Gabbour wrote:
> Pascal Costanza <········@web.de> wrote in message news:<············@newsreader2.netcologne.de>...
> 
>>Tayssir John Gabbour wrote:
>>
>>>The Alan Kay one was interesting; I think the most interesting order
>>>is to see part 2 first. I assume that was the one you mentioned to me
>>>about the three types of thinking, Pascal.
>>
>>Er, no. Does he mention that?
> 
> Yeah, "doing with images makes symbols." Three different models of
> thinking. Though you had a different view of the three, and instead of
> the "doing" thing, you substituted the one that's kind of hard to
> articulate. "Progression," I believe, where things are progressions.

Yep, something along these lines. I have read that in an article 
elsewhere on the web, unrelated to computer science - unfortunately, I 
don't recall the exact context anymore. I will check out the Alan Kay 
videos.

> Interestingly, I think Lisp fits not only with that progression model,
> but also in the "doing" model. What do people say about Lisp? It's a
> ball of mud, mudball of strength. Tactile. I'm curious what the
> Interlisp model was like -- visual? Or maybe something altogether
> different.
> http://groups.google.com/groups?q=common+lisp+killed+interlisp

The fact that Lisp code can contain any kind of object makes Lisp very 
"three dimensional" for me, and this is very different to the text-based 
approach taken by almost all other programming languages. To me that's 
one of the essential reasons why Lisp is still ahead of everything else 
in spite of other languages picking up isolated features.


Pascal

-- 
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
From: Pascal Bourguignon
Subject: Re: LISP PROGRAMMING
Date: 
Message-ID: <874qkumnc8.fsf@thalassa.informatimago.com>
Pascal Costanza <········@web.de> writes:

> Wade Humeniuk wrote:
> > sharda mishra wrote:
> >
> >> Hello every one
> >>
> >> PLEASE help me  writing the following program in LISP language
> >> ;-
> >>
> >> Write a LISP function ODD-REVERSE  which reverses the elements
> >> occuring at odd numbered position but keeps the elements at even
> >> numbered position in their given position.
> >>
> >> for example:-
> >>
> >> ODD-REVERSE  '(5 7 (6 4 )3 12 (2 1) 9)) returns the list
> >>
> >> (9 7  12  3 (6 4) (2 1) 5)
> > Your example does not seem to match the description.  The first
> > element
> > is in a even position and is not swapped. Indexes start from 0.
> > Your homework was probably already due so here is another solution.
> 
> (defun odd-reverse (list)
>    (let ((result
>           (loop for (odd even) on list by #'cddr
>                 collect odd into odds
>                 collect even into evens
>                 finally (return (loop for odd in (reverse odds)
>                                       for even in evens
>                                       collect odd
>                                       collect even)))))
>      (subseq result 0 (list-length list))))

Then, I prefer this one:

(defun unzip (list)
  (cond ((null list) list)
        ((null (cdr list)) (cons (cons (car list) nil) nil))
        (t (let ((sub (unzip (cddr list))))
             (cons (cons (car list)  (car sub))
                   (cons (cadr list) (cdr sub)))))));;unzip

(defun zip (list1 list2)
  (cond ((null list1) list2)
        ((null list2) list1)
        (t (cons (car list1) 
                 (cons (car list2)
                       (zip (cdr list1) (cdr list2)))))));;zip

(defun odd-reverse (list)
  (let ((lists (unzip list))) (zip (car lists) (nreverse (cdr lists)))))

because I get two reusable function for the same price...

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Voting Democrat or Republican is like choosing a cabin in the Titanic.
From: Alexander Burger
Subject: Re: LISP PROGRAMMING
Date: 
Message-ID: <2tek4jF1tmpbfU1@uni-berlin.de>
Wade Humeniuk <····································@telus.net> wrote:
> sharda mishra wrote:
> > Hello every one
> > 
> > PLEASE help me  writing the following program in LISP language
> > ;-
> > 
> > Write a LISP function ODD-REVERSE  which reverses the elements
> > occuring at odd numbered position but keeps the elements at even
> > numbered position in their given position.
> > 
> > for example:-
> > 
> > ODD-REVERSE  '(5 7 (6 4 )3 12 (2 1) 9)) returns the list
> > 
> > (9 7  12  3 (6 4) (2 1) 5)

> Your example does not seem to match the description.  The first element
> is in a even position and is not swapped. Indexes start from 0.

> Your homework was probably already due so here is another solution.

Perhaps in the Lisp'ish way:

(defun odd-reverse (Lst)
   (let ((Flg T))
      (mapcar
         (lambda (X Y)
            (if (setf Flg (not Flg)) X Y) )
         Lst
         (reverse Lst) ) ) )


- Alex
-- 
   Software Lab. Alexander Burger
   Bahnhofstr. 24a, D-86462 Langweid
   ···@software-lab.de, http://www.software-lab.de, +49 821 9907090
From: Pascal Bourguignon
Subject: Re: LISP PROGRAMMING
Date: 
Message-ID: <87vfd96brk.fsf@thalassa.informatimago.com>
Alexander Burger <···@software-lab.de> writes:
> Perhaps in the Lisp'ish way:
> 
> (defun odd-reverse (Lst)
>    (let ((Flg T))
>       (mapcar
>          (lambda (X Y)
>             (if (setf Flg (not Flg)) X Y) )
>          Lst
>          (reverse Lst) ) ) )

Nice, but wrong:

(ODD-REVERSE '(a 1)) ==> (1 1)

(I guess, that's on purpose given it's a homework ;-)

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Voting Democrat or Republican is like choosing a cabin in the Titanic.
From: Alexander Burger
Subject: Re: LISP PROGRAMMING
Date: 
Message-ID: <2tfm3uF1votldU1@uni-berlin.de>
Pascal Bourguignon <····@mouse-potato.com> wrote:
> Nice, but wrong:

> (ODD-REVERSE '(a 1)) ==> (1 1)

> (I guess, that's on purpose given it's a homework ;-)

Not really ...
More because of writing faster than thinking ;-)

- Alex
-- 
   Software Lab. Alexander Burger
   Bahnhofstr. 24a, D-86462 Langweid
   ···@software-lab.de, http://www.software-lab.de, +49 821 9907090
From: Pascal Bourguignon
Subject: Re: LISP PROGRAMMING
Date: 
Message-ID: <87brf15jna.fsf@thalassa.informatimago.com>
Alexander Burger <···@software-lab.de> writes:

> Pascal Bourguignon <····@mouse-potato.com> wrote:
> > Nice, but wrong:
> 
> > (ODD-REVERSE '(a 1)) ==> (1 1)
> 
> > (I guess, that's on purpose given it's a homework ;-)
> 
> Not really ...
> More because of writing faster than thinking ;-)

It's easily correctable:

(defun odd-reverse (lst)
  (let ((flg nil))
    (mapcar (lambda (x y) (if (setf flg (not flg)) x y)) 
            lst
            (if (evenp (length lst)) (cons 'x (reverse lst)) (reverse lst)))))

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Voting Democrat or Republican is like choosing a cabin in the Titanic.
From: Vassil Nikolov
Subject: Re: LISP PROGRAMMING
Date: 
Message-ID: <lzr7nwzpzs.fsf@janus.vassil.nikolov.names>
Pascal Bourguignon <····@mouse-potato.com> writes:

> Alexander Burger <···@software-lab.de> writes:
>
>> Pascal Bourguignon <····@mouse-potato.com> wrote:
>> > Nice, but wrong:
>> 
>> > (ODD-REVERSE '(a 1)) ==> (1 1)
>> 
>> > (I guess, that's on purpose given it's a homework ;-)
>> 
>> Not really ...
>> More because of writing faster than thinking ;-)
>
> It's easily correctable:
>
> (defun odd-reverse (lst)
>   (let ((flg nil))
>     (mapcar (lambda (x y) (if (setf flg (not flg)) x y)) 
>             lst
>             (if (evenp (length lst)) (cons 'x (reverse lst)) (reverse lst)))))

  By the way, I believe something along the lines of

    (defun odd-reverse (list)
      (mapcar (lambda (flag x y) (if flag x y)) 
              '#1=(t nil . #1#)
              list
              (if (evenp (length list)) (cons 'ignored (reverse list)) (reverse list))))

  (untested for typos and such) would be better.  I've never regretted
  avoiding variable assignment.

  ---Vassil.

-- 
Vassil Nikolov <········@poboxes.com>

Hollerith's Law of Docstrings: Everything can be summarized in 72 bytes.