From: jrwats
Subject: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <b2017ad8-a072-4f62-97f4-fea76d05700c@v16g2000prc.googlegroups.com>
Hi all - this is not for a school project or anything (I'm a full-
timer at the software company ppl love to hate), but I was trying to
do an exercise in the back of ch 6 of Wilensky's book, Comon
LISPcraft.  Anyway the challenge is to code up the solution to the
transposition of a matrix (with the underlying implementation being a
list - not a 2d - that is of course too easy).  My solution was a
DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of
the matrix (storing it as a list) and conses is it to the operation
applied to the rest of the matrix.  It was the only way I could think
of to do this and only visit each element once. Can you do this non-
destructively and only visit each element once?

(defun pop-1st-col (mat)
"destructively returns 1st column of matrix"
  (cond
    ((null mat) nil)
    (t (let ((el (caar mat)))
         (setf (car mat) (cdar mat))
         (cons el (pop-1st-col (cdr mat)))))))

(defun transpose-d (mat)
"destructively transpose matrix"
  (cond
    ((null (car mat)) nil)
    (t (cons (pop-1st-col mat)
             (transpose-d mat)))))

(defmacro transpose (mat)
    `(setf ,mat (transpose-d ,mat)))

From: Paul Donnelly
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <87fxnyc8zy.fsf@plap.localdomain>
jrwats <······@gmail.com> writes:

> Hi all - this is not for a school project or anything (I'm a full-
> timer at the software company ppl love to hate), but I was trying to
> do an exercise in the back of ch 6 of Wilensky's book, Comon
> LISPcraft.  Anyway the challenge is to code up the solution to the
> transposition of a matrix (with the underlying implementation being a
> list - not a 2d - that is of course too easy).  My solution was a
> DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of
> the matrix (storing it as a list) and conses is it to the operation
> applied to the rest of the matrix.  It was the only way I could think
> of to do this and only visit each element once. Can you do this non-
> destructively and only visit each element once?
>
> (defun pop-1st-col (mat)
> "destructively returns 1st column of matrix"
>   (cond
>     ((null mat) nil)
>     (t (let ((el (caar mat)))
>          (setf (car mat) (cdar mat))
>          (cons el (pop-1st-col (cdr mat)))))))
>
> (defun transpose-d (mat)
> "destructively transpose matrix"
>   (cond
>     ((null (car mat)) nil)
>     (t (cons (pop-1st-col mat)
>              (transpose-d mat)))))
>
> (defmacro transpose (mat)
>     `(setf ,mat (transpose-d ,mat)))

Algorithms aside, I wouldn't do that. When you define TRANSPOSE as a
macro you can't pass it as a function argument, and in any case it's
way out of the ordinary for a routine to go and modify variable
bindings (except those whose express purpose is to do so -- PUSH,
SETF, and so on). Functions that trash their input are not wonderful,
but they will fit into the ecosystem. Just give them a clear name
(NTRANSPOSE would be good) and let programmers manually SET any
necessary Fs. Think about it: with a transpose macro you need to
create a temporary variable for it to rebind --

(let ((matrix (list (list 1 2)
                    (list 4 5))))
  (transpose matrix)
  (foo matrix))

vs.

(foo (ntranspose (list (list 1 2)
                       (list 4 5))))

Of course you do have the TRANSPOSE-D function. That is the place to
stop.
From: William James
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <d6910dcc-f25c-4c5c-bf7c-517c6bfb2ff9@e39g2000hsf.googlegroups.com>
On Sep 17, 10:57 pm, jrwats <······@gmail.com> wrote:
> Hi all - this is not for a school project or anything (I'm a full-
> timer at the software company ppl love to hate), but I was trying to
> do an exercise in the back of ch 6 of Wilensky's book, Comon
> LISPcraft.  Anyway the challenge is to code up the solution to the
> transposition of a matrix (with the underlying implementation being a
> list - not a 2d - that is of course too easy).  My solution was a
> DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of
> the matrix (storing it as a list) and conses is it to the operation
> applied to the rest of the matrix.  It was the only way I could think
> of to do this and only visit each element once. Can you do this non-
> destructively and only visit each element once?
>
> (defun pop-1st-col (mat)
> "destructively returns 1st column of matrix"
>   (cond
>     ((null mat) nil)
>     (t (let ((el (caar mat)))
>          (setf (car mat) (cdar mat))
>          (cons el (pop-1st-col (cdr mat)))))))
>
> (defun transpose-d (mat)
> "destructively transpose matrix"
>   (cond
>     ((null (car mat)) nil)
>     (t (cons (pop-1st-col mat)
>              (transpose-d mat)))))
>
> (defmacro transpose (mat)
>     `(setf ,mat (transpose-d ,mat)))

Ruby:

[[2,3,4],[55,66,77],[88,99,111]].transpose
    ==>[[2, 55, 88], [3, 66, 99], [4, 77, 111]]

list = [[2,3,4],[55,66,77],[88,99,111]]
(0...list[0].size).inject([]){|ary,i| ary << list.map{|a| a[i]}}
    ==>[[2, 55, 88], [3, 66, 99], [4, 77, 111]]
From: Ali
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <0ec54a0d-4119-47df-9817-890e88b4e4c0@m73g2000hsh.googlegroups.com>
On Sep 18, 9:45 am, William James <·········@yahoo.com> wrote:

> Ruby:
>
> [[2,3,4],[55,66,77],[88,99,111]].transpose
>     ==>[[2, 55, 88], [3, 66, 99], [4, 77, 111]]
>
> list = [[2,3,4],[55,66,77],[88,99,111]]
> (0...list[0].size).inject([]){|ary,i| ary << list.map{|a| a[i]}}
>     ==>[[2, 55, 88], [3, 66, 99], [4, 77, 111]]

__Off topic__

We've seen a couple of code examples from you lately. The code is
arguably quite short, even after adding standard spacing which you
remove.
Although the above example looks a bit like cat sick, some of your
Ruby code is actually quite readable.

Here the complements end. Unfortunately for you, William, there are
things which Common Lisp code can do that Ruby code can't and never
can do.
Clearly you have "spirit" and want to show us what a good time you're
having.

But for the above reason, nothing you put in a Ruby code example will
convince people that Ruby is a better way to program.

Besides, don't you feel really, really silly repeatedly posting to the
wrong newsgroup?
From: Slobodan Blazeski
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <28fa542f-82c2-4cf3-8e50-8c59d6764b66@f63g2000hsf.googlegroups.com>
William James wrote:
> On Sep 17, 10:57 pm, jrwats <······@gmail.com> wrote:
> > Hi all - this is not for a school project or anything (I'm a full-
> > timer at the software company ppl love to hate), but I was trying to
> > do an exercise in the back of ch 6 of Wilensky's book, Comon
> > LISPcraft.  Anyway the challenge is to code up the solution to the
> > transposition of a matrix (with the underlying implementation being a
> > list - not a 2d - that is of course too easy).  My solution was a
> > DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of
> > the matrix (storing it as a list) and conses is it to the operation
> > applied to the rest of the matrix.  It was the only way I could think
> > of to do this and only visit each element once. Can you do this non-
> > destructively and only visit each element once?
> >
> > (defun pop-1st-col (mat)
> > "destructively returns 1st column of matrix"
> >   (cond
> >     ((null mat) nil)
> >     (t (let ((el (caar mat)))
> >          (setf (car mat) (cdar mat))
> >          (cons el (pop-1st-col (cdr mat)))))))
> >
> > (defun transpose-d (mat)
> > "destructively transpose matrix"
> >   (cond
> >     ((null (car mat)) nil)
> >     (t (cons (pop-1st-col mat)
> >              (transpose-d mat)))))
> >
> > (defmacro transpose (mat)
> >     `(setf ,mat (transpose-d ,mat)))
>
> Ruby:
Which part of common lisp solution you have problem to understand ?
>
> [[2,3,4],[55,66,77],[88,99,111]].transpose
>     ==>[[2, 55, 88], [3, 66, 99], [4, 77, 111]]
>
> list = [[2,3,4],[55,66,77],[88,99,111]]
> (0...list[0].size).inject([]){|ary,i| ary << list.map{|a| a[i]}}
>     ==>[[2, 55, 88], [3, 66, 99], [4, 77, 111]]
J:

  ls =: i. 2 3
  ls =: i. 2 3
  ls
0 1 2
3 4 5
   0 |: ls
0 3
1 4
2 5
   ls
0 1 2
3 4 5

Now try transposing multidimensional matrix on other axis
lst =: i. 2 3 4
   lst
 0  1  2  3
 4  5  6  7
 8  9 10 11

12 13 14 15
16 17 18 19
20 21 22 23
   0 |: lst
 0 12
 1 13
 2 14
 3 15

 4 16
 5 17
 6 18
 7 19

 8 20
 9 21
10 22
11 23
   1 |: lst
 0  4  8
 1  5  9
 2  6 10
 3  7 11

12 16 20
13 17 21
14 18 22
15 19 23
   2 |: lst
 0  1  2  3
 4  5  6  7
 8  9 10 11

12 13 14 15
16 17 18 19
20 21 22 23

bobi
From: André Thieme
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <gaun0b$pod$1@registered.motzarella.org>
William James schrieb:

> Ruby:
> 
> [[2,3,4],[55,66,77],[88,99,111]].transpose
>     ==>[[2, 55, 88], [3, 66, 99], [4, 77, 111]]
> 
> list = [[2,3,4],[55,66,77],[88,99,111]]
> (0...list[0].size).inject([]){|ary,i| ary << list.map{|a| a[i]}}
>     ==>[[2, 55, 88], [3, 66, 99], [4, 77, 111]]


Again, nothing special about these solutions.
You can do them in Lisp also like that.
It is right that the written Ruby code is shorter for:
list[0]  and  a[i]
Because in Lisp you would have a getter function, like
(aref 0 list)  or  (nth i a)
Although it would be easy to allow the same syntax for accessing
elements from a container (like lists, arrays, ...) the same way
as you did in Ruby, by introducing syntax.
Otherwise you could do the rest in Lisp exactly the same:
(... 0 (length list[0]))
And you could make use of the << function as well.

Whatever you come up with in Ruby: you can do the same in Lisp.
The algorithm can be the same. You can solve this task in a
functional programming style, in an imperative style, you could
do it with your own classes/methods, whatever.
The only thing you are showing here are some operators, like the
2-ary �...� and the 2-ary �<<� and the 2-ary �[]�.
Those will be written in lisp style and with other names.
But in principle you can do:
(... from to)
([] 0 list)
([] i a)

What you showed is really nothing spectecular and no Lisper will
be impressed about it. Nothing was shown which would help to reduce
the complexity of the algorithm.
If the function �transpose� would be called �trsps� then you win
nothing. If you access an element out of a container, be it a list,
array or an element of an instance of your own (container) class:
doing it via an operator (built into the language syntax) or via
a getter/setter function does not affect your thinking about the
algorithm.
print myGetter(instance, 14)
or
print instance<14>
or
(print (<> instance 14))

is all the same. No complexity reduction in the algorithm.
Interesting would be if you showed a solution that really reduced
the difficulty of the problem itself. Like:
�Computer, look up what is meant by matrix transposition and develop
code to do just that�.
Then this would be nice and impressive. Although typing this needs
a few more moments (more chars) it is far easier, complexity wise.
That is where we want to go. Telling the computer what to do, but not
how to do it.


Andr�
-- 
From: Kenny
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <48d1f2bb$0$5630$607ed4bc@cv.net>
jrwats wrote:
> Hi all - this is not for a school project or anything (I'm a full-
> timer at the software company ppl love to hate),..

Lisp, schmisp, STFU and tell us what everyone thinks about the 
Gates-Seinfeld commercials!

I am skeptical, but I know enough not to judge a sitcom on the first 10 
minutes.

Is this about MS, or is this about Gates? Respond as "Ilias" if you need 
cover.

hth, kzo
From: jrwats
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <ea1903f7-9f06-4350-84cb-c66fc0d700c7@p10g2000prf.googlegroups.com>
On Sep 17, 11:18 pm, Kenny <·········@gmail.com> wrote:
> jrwats wrote:
> > Hi all - this is not for a school project or anything (I'm a full-
> > timer at the software company ppl love to hate),..
>
> Lisp, schmisp, STFU and tell us what everyone thinks about the
> Gates-Seinfeld commercials!

I saw the one where they went to some ranom family's house.  Got bored
and went back to work.

>
> I am skeptical, but I know enough not to judge a sitcom on the first 10
> minutes.
>

uh why?  Sitcoms judge you in less.

> Is this about MS, or is this about Gates? Respond as "Ilias" if you need
> cover.

Are you asking about the commercials or if I'm trolling
comp.lang.lisp?  I think the commercials are about improving the
perception of the company.
From: namekuseijin
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <19142cf0-97d1-40cf-8485-24ddfb7743e3@r66g2000hsg.googlegroups.com>
On Sep 18, 4:04 am, jrwats <······@gmail.com> wrote:
> On Sep 17, 11:18 pm, Kenny <·········@gmail.com> wrote:
> > jrwats wrote:
> > > Hi all - this is not for a school project or anything (I'm a full-
> > > timer at the software company ppl love to hate),..
>
> > Lisp, schmisp, STFU and tell us what everyone thinks about the
> > Gates-Seinfeld commercials!
>
> I saw the one where they went to some ranom family's house.  Got bored
> and went back to work.
>
> > I am skeptical, but I know enough not to judge a sitcom on the first 10
> > minutes.
>
> uh why?  Sitcoms judge you in less.

Seinfeld the sitcom was exceptionally fun to watch, until season 5.
Very humorous take on everyday events, with its observational kind of
humor.  Then, they lost co-creator Larry David as writer and the
series went into a caricature of itself with too much zaniness for its
own good...  I suggest you start from the beginning to understand
where so much acclaim comes from...
From: Pascal J. Bourguignon
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <7cljxpg72s.fsf@pbourguignon.anevia.com>
jrwats <······@gmail.com> writes:
>> Is this about MS, or is this about Gates? Respond as "Ilias" if you need
>> cover.
>
> Are you asking about the commercials or if I'm trolling
> comp.lang.lisp?  I think the commercials are about improving the
> perception of the company.

Sometimes, just doing a commercial, any commercial, worsen the
perception of the company...

-- 
__Pascal Bourguignon__
From: Thomas M. Hermann
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <7d819a6d-cc64-48dd-be4b-5472f9e4ecea@d77g2000hsb.googlegroups.com>
On Sep 18, 1:18 am, Kenny <·········@gmail.com> wrote:
> Lisp, schmisp, STFU and tell us what everyone thinks about the
> Gates-Seinfeld commercials!

Man, Kenneth, you're so 5 minutes ago.

http://www.engadget.com/2008/09/17/microsofts-new-ads-seinfeld-and-gates-out-hodgman-lookalike-i/
From: Pascal J. Bourguignon
Subject: Seinfeld [Was: Coding challenge! non-destructuve matrix transpose]
Date: 
Message-ID: <87tzcej5zz.fsf_-_@hubble.informatimago.com>
Kenny <·········@gmail.com> writes:
> Lisp, schmisp, STFU and tell us what everyone thinks about the
> Gates-Seinfeld commercials!

Won't that definitely break Seinfeld's image?


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

"Specifications are for the weak and timid!"
From: Kenny
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix transpose]
Date: 
Message-ID: <48d254c2$0$4987$607ed4bc@cv.net>
Pascal J. Bourguignon wrote:
> Kenny <·········@gmail.com> writes:
> 
>>Lisp, schmisp, STFU and tell us what everyone thinks about the
>>Gates-Seinfeld commercials!
> 
> 
> Won't that definitely break Seinfeld's image?
> 

I can read that two ways. Do you mean by associating with Satan he loses 
popularity? Or that these commercials are so deadly he will lose his 
reputation for being funny? Both? Other______________________________?

kt
From: George Neuner
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix transpose]
Date: 
Message-ID: <ina6d4lkq8o4a8isik1rlvl0ie1eb5deib@4ax.com>
On Thu, 18 Sep 2008 09:16:51 -0400, Kenny <·········@gmail.com> wrote:

>Pascal J. Bourguignon wrote:
>> Kenny <·········@gmail.com> writes:
>> 
>>>Lisp, schmisp, STFU and tell us what everyone thinks about the
>>>Gates-Seinfeld commercials!
>> 
>> 
>> Won't that definitely break Seinfeld's image?
>> 
>
>I can read that two ways. Do you mean by associating with Satan he loses 
>popularity? Or that these commercials are so deadly he will lose his 
>reputation for being funny? Both? Other______________________________?
>

Or that he'll finally _gain_ a reputation for being funny.  Honestly
Seinfeld was the least funny person on that show.  I don't know anyone
who likes him - or even thinks he's funny - and I could never figure
out why that show was so popular.  I attributed Seinfeld's success to
the dumbing of the audience.

George
From: Raffael Cavallaro
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix transpose]
Date: 
Message-ID: <gb0h44$js5$1@aioe.org>
On 2008-09-19 00:40:54 -0400, George Neuner <········@comcast.net> said:

>  I attributed Seinfeld's success to
> the dumbing of the audience.

It was a New York thing. The show relied almost exclusively on the 
audience either:
1. having a New York middle class world view and sense of humor or,
2. finding such people absurd and wanting to deride and laugh at them.
That's why the show ended with the cast on trial for being caricatures 
of inconsiderate New Yorkers.

This sort of urban me-generation humor was predictably popular with 
northeastern and west coast urban audiences (as well as with urbanites 
elsewhere and anyone who liked to laugh at their foibles).

I (and all of my family) found it funny becuase it resonated with our 
experiences (we're from NYC). Friends from the suburban midwest often 
found it pointless and thought the characters simply abrasive and 
selfish.
From: namekuseijin
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix 	transpose]
Date: 
Message-ID: <9cb68ad8-9160-4954-8323-7e058959ffbb@34g2000hsh.googlegroups.com>
On Sep 19, 12:39 pm, Raffael Cavallaro <················@pas-d'espam-
s'il-vous-plait-mac.com> wrote:
> On 2008-09-19 00:40:54 -0400, George Neuner <········@comcast.net> said:
>
> >  I attributed Seinfeld's success to
> > the dumbing of the audience.
>
> It was a New York thing. The show relied almost exclusively on the
> audience either:
> 1. having a New York middle class world view and sense of humor or,
> 2. finding such people absurd and wanting to deride and laugh at them.
> That's why the show ended with the cast on trial for being caricatures
> of inconsiderate New Yorkers.
>
> This sort of urban me-generation humor was predictably popular with
> northeastern and west coast urban audiences (as well as with urbanites
> elsewhere and anyone who liked to laugh at their foibles).
>
> I (and all of my family) found it funny becuase it resonated with our
> experiences (we're from NYC). Friends from the suburban midwest often
> found it pointless and thought the characters simply abrasive and
> selfish.

I'm neither american nor dumb.
From: Raffael Cavallaro
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <gb115b$p0v$1@aioe.org>
On 2008-09-19 15:38:22 -0400, namekuseijin <············@gmail.com> said:

> I'm neither american nor dumb.

This is not an exhaustive partitioning of the types of people I spoke about:

"as well as with urbanites elsewhere and anyone who liked to laugh at 
their foibles."

from which I would conclude that, if you liked the show Seinfeld, you 
are either an urbanite, someone who likes to laugh at their foibles, or 
both.
From: namekuseijin
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix 	transpose]
Date: 
Message-ID: <1351a483-4266-49b9-8a61-77e4cd26b0d3@e53g2000hsa.googlegroups.com>
On Sep 19, 5:13 pm, Raffael Cavallaro <················@pas-d'espam-
s'il-vous-plait-mac.com> wrote:
> On 2008-09-19 15:38:22 -0400, namekuseijin <············@gmail.com> said:
>
> > I'm neither american nor dumb.
>
> This is not an exhaustive partitioning of the types of people I spoke about:
>
> "as well as with urbanites elsewhere and anyone who liked to laugh at
> their foibles."
>
> from which I would conclude that, if you liked the show Seinfeld, you
> are either an urbanite, someone who likes to laugh at their foibles, or
> both.

I can relate to people in other situations/contexts -- I'm in an urban
region, but not to the extent of NYrs.  I don't have to be a Jew,
Italian or Irish to understand their context and enjoy their
particular cultural artifacts.

I enjoyed the observational humor, the double crossed subjects in each
show, the jokes, the stand-up comedy in the beginning and end, the
character traits etc.
From: Raffael Cavallaro
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <gb176u$g9e$2@aioe.org>
On 2008-09-19 16:52:34 -0400, namekuseijin <············@gmail.com> said:

> I don't have to be a Jew,
> Italian or Irish to understand their context and enjoy their
> particular cultural artifacts.
> 
> I enjoyed the observational humor, the double crossed subjects in each
> show, the jokes, the stand-up comedy in the beginning and end, the
> character traits etc.

Yes, but my point is that many others cannot or do not. They don't find 
the character of George Costanza amusing - they simply find his 
behavior selfish and offensive. This fact was parodied in the final 
episode of the show itself where the entire Seinfeld crew was put on 
trial essentially for being offensive, selfish New Yorkers.
From: namekuseijin
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix 	transpose]
Date: 
Message-ID: <b133d9b8-c48b-4821-8672-616b6090292f@y21g2000hsf.googlegroups.com>
On 19 set, 18:56, Raffael Cavallaro <················@pas-d'espam-s'il-
vous-plait-mac.com> wrote:
> They don't find
> the character of George Costanza amusing - they simply find his
> behavior selfish and offensive.

It may well be.

> This fact was parodied in the final
> episode of the show itself where the entire Seinfeld crew was put on
> trial essentially for being offensive, selfish New Yorkers.

Like I said, the entire thing after season 5 is a self-parody.
From: Kenny
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <48d44ad2$0$4973$607ed4bc@cv.net>
Raffael Cavallaro wrote:
> On 2008-09-19 16:52:34 -0400, namekuseijin <············@gmail.com> said:
> 
>> I don't have to be a Jew,
>> Italian or Irish to understand their context and enjoy their
>> particular cultural artifacts.
>>
>> I enjoyed the observational humor, the double crossed subjects in each
>> show, the jokes, the stand-up comedy in the beginning and end, the
>> character traits etc.
> 
> 
> Yes, but my point is that many others cannot or do not. They don't find 
> the character of George Costanza amusing - they simply find his behavior 
> selfish and offensive. This fact was parodied in the final episode of 
> the show itself where the entire Seinfeld crew was put on trial 
> essentially for being offensive, selfish New Yorkers.
> 

New Yorkers are not offensive. The joke is a good one (The proper way to 
ask for directions in NYC? "Excuse me, can you tell me the way to 
Lincoln Center, or should I go fuck myself?") but the reality is New 
Yorkers are so nice they will gladly give you directions whether or not 
they know the way.

In another thread I explained that the mentally ill are often the most 
compassionate because of what they have endured. Something like that.

kt
From: Kenny
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <48d41d35$0$4972$607ed4bc@cv.net>
namekuseijin wrote:
> On Sep 19, 12:39 pm, Raffael Cavallaro <················@pas-d'espam-
> s'il-vous-plait-mac.com> wrote:
> 
>>On 2008-09-19 00:40:54 -0400, George Neuner <········@comcast.net> said:
>>
>>
>>> I attributed Seinfeld's success to
>>>the dumbing of the audience.
>>
>>It was a New York thing. The show relied almost exclusively on the
>>audience either:
>>1. having a New York middle class world view and sense of humor or,
>>2. finding such people absurd and wanting to deride and laugh at them.
>>That's why the show ended with the cast on trial for being caricatures
>>of inconsiderate New Yorkers.
>>
>>This sort of urban me-generation humor was predictably popular with
>>northeastern and west coast urban audiences (as well as with urbanites
>>elsewhere and anyone who liked to laugh at their foibles).
>>
>>I (and all of my family) found it funny becuase it resonated with our
>>experiences (we're from NYC). Friends from the suburban midwest often
>>found it pointless and thought the characters simply abrasive and
>>selfish.
> 
> 
> I'm neither american nor dumb.

I am American, dumb, lived in NYC the whole time, love comedy, and 
thought the show pointless and unfunny. Costanza was great, tho.

kt
From: Raffael Cavallaro
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <gb176c$g9e$1@aioe.org>
On 2008-09-19 17:44:21 -0400, Kenny <·········@gmail.com> said:

> I am American, dumb, lived in NYC the whole time, love comedy, and 
> thought the show pointless and unfunny. Costanza was great, tho.

great but not funny?
From: Kenny
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <48d4499c$0$4987$607ed4bc@cv.net>
Raffael Cavallaro wrote:
> On 2008-09-19 17:44:21 -0400, Kenny <·········@gmail.com> said:
> 
>> I am American, dumb, lived in NYC the whole time, love comedy, and 
>> thought the show pointless and unfunny. Costanza was great, tho.
> 
> 
> great but not funny?
> 

He could not save the material, but the material could not hide his genius.
From: Raffael Cavallaro
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <gb1t43$sbc$1@aioe.org>
On 2008-09-19 20:53:48 -0400, Kenny <·········@gmail.com> said:

> He could not save the material, but the material could not hide his genius.

But clearly there is an audience for precisely this sort of pointless 
material - Larry David has another successful show - Curb Your 
Enthusiasm - which is really nothing more than Seinfeld transplanted to 
LA.
From: George Neuner
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <u059d4p9gc3a357hmlnb1s498pt0rd9f4h@4ax.com>
On Sat, 20 Sep 2008 00:10:43 -0400, Raffael Cavallaro
<················@pas-d'espam-s'il-vous-plait-mac.com> wrote:

>On 2008-09-19 20:53:48 -0400, Kenny <·········@gmail.com> said:
>
>> He could not save the material, but the material could not hide his genius.
>
>But clearly there is an audience for precisely this sort of pointless 
>material - Larry David has another successful show - Curb Your 
>Enthusiasm - which is really nothing more than Seinfeld transplanted to 
>LA.

And it is just as stupid as Seinfeld.

George
From: Kenny
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <48d4e85c$0$4888$607ed4bc@cv.net>
George Neuner wrote:
> On Sat, 20 Sep 2008 00:10:43 -0400, Raffael Cavallaro
> <················@pas-d'espam-s'il-vous-plait-mac.com> wrote:
> 
> 
>>On 2008-09-19 20:53:48 -0400, Kenny <·········@gmail.com> said:
>>
>>
>>>He could not save the material, but the material could not hide his genius.
>>
>>But clearly there is an audience for precisely this sort of pointless 
>>material - Larry David has another successful show - Curb Your 
>>Enthusiasm - which is really nothing more than Seinfeld transplanted to 
>>LA.

Nahhhhh. Read on

> 
> 
> And it is just as stupid as Seinfeld.

But the stupidities provide premises for the improv scenes and the show 
is fundamentally an improv show. One has to understand that to really 
enjoy it. ie, Larry is trying to get the kid to do something and the 
kid's instructions are to refuse no matter what. So we get these 
incredibly tense and awkward scenes, but the joke is how brutally 
intractable are Larry's foils and how he plays off that with (hopefully) 
honest astonishment/frustration.

The perfect NYC sitcom for me was Barney Miller. Seinfeld in his show 
and standup eliminates emotion and story where comedy gets its power, 
which is why Seinfeld fans would never laugh during the show. They would 
turn to each and say, "That is so funny." and talk about it at the water 
cooler the next day and episodes would become part of our culture, but 
they never made people laugh.

kt
From: namekuseijin
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix 	transpose]
Date: 
Message-ID: <ae2db826-cc9e-4abb-b152-91cfb9ad27ea@r66g2000hsg.googlegroups.com>
On 20 set, 09:11, Kenny <·········@gmail.com> wrote:
> which is why Seinfeld fans would never laugh during the show. They would
> turn to each and say, "That is so funny." and talk about it at the water
> cooler the next day and episodes would become part of our culture, but
> they never made people laugh.

You know you're obviously wrong.  I used to LOL hard during the show.

But I see a pattern here:  old Lispers don't have any sense of
humor? ;)

So, if all you know are a bunch of other old Lispers, then yes, no one
finds it funny or at most find it funny but doesn't laugh... :P
From: Kenny
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <48d5270c$0$4873$607ed4bc@cv.net>
namekuseijin wrote:
> On 20 set, 09:11, Kenny <·········@gmail.com> wrote:
> 
>>which is why Seinfeld fans would never laugh during the show. They would
>>turn to each and say, "That is so funny." and talk about it at the water
>>cooler the next day and episodes would become part of our culture, but
>>they never made people laugh.
> 
> 
> You know you're obviously wrong.  I used to LOL hard during the show.

What did you think of Kramer?

kt
From: Marco Antoniotti
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix 	transpose]
Date: 
Message-ID: <b4428432-3c50-4ee2-886b-09d113043424@l42g2000hsc.googlegroups.com>
On Sep 20, 6:38 pm, Kenny <·········@gmail.com> wrote:
> namekuseijin wrote:
> > On 20 set, 09:11, Kenny <·········@gmail.com> wrote:
>
> >>which is why Seinfeld fans would never laugh during the show. They would
> >>turn to each and say, "That is so funny." and talk about it at the water
> >>cooler the next day and episodes would become part of our culture, but
> >>they never made people laugh.
>
> > You know you're obviously wrong.  I used to LOL hard during the show.
>
> What did you think of Kramer?

Hey Kenny!  It is "The Kramer"!  And moreover, do you guys realize
that you are talking about nothing? :)

Cheers
--
Marco
From: namekuseijin
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix 	transpose]
Date: 
Message-ID: <8bad66f5-c0c3-4635-9cb1-7fb02df4cd24@t54g2000hsg.googlegroups.com>
On 20 set, 13:38, Kenny <·········@gmail.com> wrote:
> namekuseijin wrote:
> > On 20 set, 09:11, Kenny <·········@gmail.com> wrote:
>
> >>which is why Seinfeld fans would never laugh during the show. They would
> >>turn to each and say, "That is so funny." and talk about it at the water
> >>cooler the next day and episodes would become part of our culture, but
> >>they never made people laugh.
>
> > You know you're obviously wrong.  I used to LOL hard during the show.
>
> What did you think of Kramer?

He's way over-the-top, but hella fun, much like a self-confident and
awkward Costanza.

I know you're expecting me to say I love the Sein because of Kramer,
but I just gotta love the Sein for multiple reasons... :)
From: Kenny
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <48d5ec2c$0$4968$607ed4bc@cv.net>
namekuseijin wrote:
> On 20 set, 13:38, Kenny <·········@gmail.com> wrote:
> 
>>namekuseijin wrote:
>>
>>>On 20 set, 09:11, Kenny <·········@gmail.com> wrote:
>>
>>>>which is why Seinfeld fans would never laugh during the show. They would
>>>>turn to each and say, "That is so funny." and talk about it at the water
>>>>cooler the next day and episodes would become part of our culture, but
>>>>they never made people laugh.
>>
>>>You know you're obviously wrong.  I used to LOL hard during the show.
>>
>>What did you think of Kramer?
> 
> 
> He's way over-the-top, but hella fun, much like a self-confident and
> awkward Costanza.

"hella fun" kinda says it all, and resonates beautifully with the 
difference between falling out laughing and turning to others during a 
show and saying calmly, "That was so funny." OK, we agree on Kramer.

> 
> I know you're expecting me to say I love the Sein because of Kramer,

I feel a naggum coming on. When you think you know what I am thinking 
try to stop thinking. It was a litmus test to determine whether there 
was any hope for you. You passed. What you flunked was ESL.

> but I just gotta love the Sein for multiple reasons... :)

None of them worth mentioning, I see.

I had a friend I respected greatly who loved the show. He said the 
writing was terrific. Oops.

Kinda interesting how the world fell in love with an unfunny comedy. 
Seinfeld's stand-up is the same: story-less, emotion-less, just 
recognition-full. The vapdity of observational humor laid bare.

You can have your Seinfeld, I'll take Bruce and Carlin, RIP.

kzo
From: namekuseijin
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix 	transpose]
Date: 
Message-ID: <f1782d53-269f-4c9b-ab9c-06009117fe44@k13g2000hse.googlegroups.com>
On 21 set, 03:39, Kenny <·········@gmail.com> wrote:
> I feel a naggum coming on.

I see.

> > but I just gotta love the Sein for multiple reasons... :)
>
> None of them worth mentioning, I see.

I won't enumerate them in every single post, because this already
offtopic thread is becoming increasingly boring.  You may look up my
previous posts.

> I had a friend I respected greatly who loved the show. He said the
> writing was terrific. Oops.

It was. :)

> Kinda interesting how the world fell in love with an unfunny comedy.

Since you're a funny guy yourself, I'll give you the benefit of
doubt. ;)
From: Kenny
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <48d6b6de$0$5649$607ed4bc@cv.net>
namekuseijin wrote:
> On 21 set, 03:39, Kenny <·········@gmail.com> wrote:
>>I had a friend I respected greatly who loved the show. He said the
>>writing was terrific. Oops.
> 
> 
> It was. :)
> 

Sorry, I meant that as a negative. He was a huge admirer yet did not 
even say "funny", he said "great writing". That is once removed from humor.

Humor is a surprise, which is why we convulse, instinctively contracting 
the abdomen (our weakest spot) to protect it, expelling air only 
incidentally forming the laugh sound.

Stop, you are hurting me, is accurate.

> 
>>Kinda interesting how the world fell in love with an unfunny comedy.
> 
> 
> Since you're a funny guy yourself, I'll give you the benefit of
> doubt. ;)

Thx! Don't get me wrong, as I said, Seinfeld was the genius and apex of 
found humor. But what he proved was that story matters because even as I 
admire his skill I find him and all the many who walk the same path 
empty the way I find new age music pleasant but so void of content it is 
the only music I can listen to while programming. (Not that I do!)

Richard Pryor got to the heart with stories and characters and more than 
a little profanity. Seinfeld disdains profanity as a shortcut to a laugh 
and it is, he just misses that that shortcut is not as lame as his own 
chosen shortcut, familiarity. Not that Pryor does not touch on emotions 
we all understand (aka familiarity) but what Seinfeld does is talk about 
what happened to the other sock when one goes missing during a laundry. 
Familiarity yes, emotion no.

Elsewhere you said this was getting boring. If that is your level of 
appreciation for humor, of course you like Seinfeld. I read an interview 
with Jon Stewart where he said he had done that, he had perfected it, he 
had it down, the craft and art of stand up, the mechanics of The Joke. 
It was not what he wanted to do. It was not enough.

Something like that.

kt
From: namekuseijin
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix 	transpose]
Date: 
Message-ID: <c51f80d3-1d2e-40bd-8369-50a3bd8a3124@26g2000hsk.googlegroups.com>
On 21 set, 18:04, Kenny <·········@gmail.com> wrote:
> namekuseijin wrote:
> > On 21 set, 03:39, Kenny <·········@gmail.com> wrote:
> >>I had a friend I respected greatly who loved the show. He said the
> >>writing was terrific. Oops.
>
> > It was. :)
>
> Sorry, I meant that as a negative.

I knew. :)

> He was a huge admirer yet did not
> even say "funny", he said "great writing". That is once removed from humor.

It had great writing.  And great humor. :)

Perhaps he just emphasized the former...

> Humor is a surprise, which is why we convulse, instinctively contracting
> the abdomen (our weakest spot) to protect it, expelling air only
> incidentally forming the laugh sound.

There are jokes like that, indeed.  There are more subtle ones, too.
Seinfeld was pretty much about the latter, and reserved the best bits
of the former to the characters Kramer and Costanza. :)

> Stop, you are hurting me, is accurate.

Anyway, this little anecdote is very interesting.  Did you read it
somewhere or figure it out by yourself?

> Thx! Don't get me wrong, as I said, Seinfeld was the genius and apex of
> found humor. But what he proved was that story matters because even as I
> admire his skill I find him and all the many who walk the same path
> empty the way I find new age music pleasant but so void of content it is
> the only music I can listen to while programming. (Not that I do!)

I take it you don't like a show about nothing? ;)

> Richard Pryor got to the heart with stories and characters and more than
> a little profanity. Seinfeld disdains profanity as a shortcut to a laugh
> and it is, he just misses that that shortcut is not as lame as his own
> chosen shortcut, familiarity. Not that Pryor does not touch on emotions
> we all understand (aka familiarity) but what Seinfeld does is talk about
> what happened to the other sock when one goes missing during a laundry.
> Familiarity yes, emotion no.

I guess emotion to you means dirty words? ;)
Your humor choices seem to indicate it...

> Elsewhere you said this was getting boring.

Boring in the context of cll.  You know, language flamewars are far
more entertaining than having your humor tastes challenged... :P
From: Kenny
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <48d707d1$0$4898$607ed4bc@cv.net>
namekuseijin wrote:
> On 21 set, 18:04, Kenny <·········@gmail.com> wrote:
> 
>>namekuseijin wrote:
>>
>>>On 21 set, 03:39, Kenny <·········@gmail.com> wrote:
>>>
>>>>I had a friend I respected greatly who loved the show. He said the
>>>>writing was terrific. Oops.
>>
>>>It was. :)
>>
>>Sorry, I meant that as a negative.
> 
> 
> I knew. :)
> 
> 
>>He was a huge admirer yet did not
>>even say "funny", he said "great writing". That is once removed from humor.
> 
> 
> It had great writing.  And great humor. :)
> 
> Perhaps he just emphasized the former...
> 
> 
>>Humor is a surprise, which is why we convulse, instinctively contracting
>>the abdomen (our weakest spot) to protect it, expelling air only
>>incidentally forming the laugh sound.
> 
> 
> There are jokes like that, indeed.  There are more subtle ones, too.
> Seinfeld was pretty much about the latter, and reserved the best bits
> of the former to the characters Kramer and Costanza. :)
> 
> 
>>Stop, you are hurting me, is accurate.
> 
> 
> Anyway, this little anecdote is very interesting.  Did you read it
> somewhere or figure it out by yourself?

What anecdote? Possibly you are asking about "The Act of Creation", 
Arthur Koestler.

kt
From: George Neuner
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <r1fbd45ukv188o2j9das037l0li7hpvjhd@4ax.com>
On Sat, 20 Sep 2008 12:38:34 -0400, Kenny <·········@gmail.com> wrote:

>namekuseijin wrote:
>> On 20 set, 09:11, Kenny <·········@gmail.com> wrote:
>> 
>>>which is why Seinfeld fans would never laugh during the show. They would
>>>turn to each and say, "That is so funny." and talk about it at the water
>>>cooler the next day and episodes would become part of our culture, but
>>>they never made people laugh.
>> 
>> 
>> You know you're obviously wrong.  I used to LOL hard during the show.
>
>What did you think of Kramer?
>
>kt

I've liked some of Michael Richards' work, but I was not impressed
with Kramer.  Kramer felt like a cliche - the obligatory NYC nutball -
not like some of the other sophicated but lunatic characters he has
played.

George
From: George Neuner
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <2cfbd4lh9vducepgddub7dmkehgbim6ohd@4ax.com>
On Sat, 20 Sep 2008 23:19:55 -0400, George Neuner
<········@comcast.net> wrote:

>I've liked some of Michael Richards' work, but I was not impressed
>with Kramer.  Kramer felt like a cliche - the obligatory NYC nutball -
>not like some of the other sophicated but lunatic characters he has
                           ^sophisticated
>played.

George
From: Raffael Cavallaro
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <gb4g29$j2q$1@aioe.org>
On 2008-09-20 08:11:07 -0400, Kenny <·········@gmail.com> said:

> They would turn to each and say, "That is so funny." and talk about it 
> at the water cooler the next day and episodes would become part of our 
> culture, but they never made people laugh.

This is clearly not true - seinfeld makes me and my son laugh till milk 
pours out our noses sometimes - for example when Kramer is 
"negotiating" with java world, or the festivus feats of strength.
From: Raffael Cavallaro
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <gb4gbj$k70$1@aioe.org>
On 2008-09-20 08:11:07 -0400, Kenny <·········@gmail.com> said:

> The perfect NYC sitcom for me was Barney Miller.

Wow - 70s flashback - were you a big fan of Welcome Back Kotter too?
From: Kenny
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix  transpose]
Date: 
Message-ID: <48d645e7$0$5645$607ed4bc@cv.net>
Raffael Cavallaro wrote:
> On 2008-09-20 08:11:07 -0400, Kenny <·········@gmail.com> said:
> 
>> The perfect NYC sitcom for me was Barney Miller.
> 
> 
> Wow - 70s flashback - were you a big fan of Welcome Back Kotter too?
> 

Nope. Nothing against it, tho.

I do like to sign things "Epstein's Mother".

kt
From: George Neuner
Subject: Re: Seinfeld [Was: Coding challenge! non-destructuve matrix transpose]
Date: 
Message-ID: <0o29d454vlne5t3r0ea4e8ecaj8pn9408i@4ax.com>
On Fri, 19 Sep 2008 11:39:48 -0400, Raffael Cavallaro
<················@pas-d'espam-s'il-vous-plait-mac.com> wrote:

>On 2008-09-19 00:40:54 -0400, George Neuner <········@comcast.net> said:
>
>>  I attributed Seinfeld's success to
>> the dumbing of the audience.
>
>It was a New York thing. The show relied almost exclusively on the 
>audience either:
>1. having a New York middle class world view and sense of humor or,
>2. finding such people absurd and wanting to deride and laugh at them.
>That's why the show ended with the cast on trial for being caricatures 
>of inconsiderate New Yorkers.
>
>This sort of urban me-generation humor was predictably popular with 
>northeastern and west coast urban audiences (as well as with urbanites 
>elsewhere and anyone who liked to laugh at their foibles).
>
>I (and all of my family) found it funny becuase it resonated with our 
>experiences (we're from NYC). Friends from the suburban midwest often 
>found it pointless and thought the characters simply abrasive and 
>selfish.

Self centered and abrasive describes some other sit-coms that I've
enjoyed.  With "Seinfeld" I just thought the show was stupid.

I'm around the corner in Boston and I get to NYC several times a year.
I know that as a visitor I don't get the same effect as a native, but
Seinfeld in no way tallies with my NYC experiences.  Generally I've
found that the average New Yorker is nicer and more helpful than the
average Bostonian - at least in NYC most people take the trouble to
flip you off if they don't want to talk to you ... in Boston they just
act like you're not there.  Despite living here, I consider Boston to
be one of the rudest and most socially isolating cities I have ever
been in.

A number of years ago I spent a month in London.  Upon arriving home
and seeing anew just how rude everyone here is, I was tempted to get
back on the plane.

George
From: John Thingstad
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <op.uhnukbsqut4oq5@pandora.alfanett.no>
P� Thu, 18 Sep 2008 05:57:00 +0200, skrev jrwats <······@gmail.com>:

> Hi all - this is not for a school project or anything (I'm a full-
> timer at the software company ppl love to hate), but I was trying to
> do an exercise in the back of ch 6 of Wilensky's book, Comon
> LISPcraft.  Anyway the challenge is to code up the solution to the
> transposition of a matrix (with the underlying implementation being a
> list - not a 2d - that is of course too easy).  My solution was a
> DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of
> the matrix (storing it as a list) and conses is it to the operation
> applied to the rest of the matrix.  It was the only way I could think
> of to do this and only visit each element once. Can you do this non-
> destructively and only visit each element once?
>
> (defun pop-1st-col (mat)
> "destructively returns 1st column of matrix"
>   (cond
>     ((null mat) nil)
>     (t (let ((el (caar mat)))
>          (setf (car mat) (cdar mat))
>          (cons el (pop-1st-col (cdr mat)))))))
>
> (defun transpose-d (mat)
> "destructively transpose matrix"
>   (cond
>     ((null (car mat)) nil)
>     (t (cons (pop-1st-col mat)
>              (transpose-d mat)))))
>
> (defmacro transpose (mat)
>     `(setf ,mat (transpose-d ,mat)))

 From PAIP:

(defun matrix-transpose (matrix)
   "Turn a matrix on its side."
   (if matrix (apply #'mapcar #'list matrix)))


--------------
John Thingstad
From: namekuseijin
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <4425375c-1cf8-41e4-9074-11ae5d06d837@k7g2000hsd.googlegroups.com>
On 18 set, 01:54, "John Thingstad" <·······@online.no> wrote:
> På Thu, 18 Sep 2008 05:57:00 +0200, skrev jrwats <······@gmail.com>:
> > Hi all - this is not for a school project or anything (I'm a full-
> > timer at the software company ppl love to hate), but I was trying to
> > do an exercise in the back of ch 6 of Wilensky's book, Comon
> > LISPcraft.  Anyway the challenge is to code up the solution to the
> > transposition of a matrix (with the underlying implementation being a
> > list - not a 2d - that is of course too easy).  My solution was a
> > DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of...
>
> (defun matrix-transpose (matrix)
>    "Turn a matrix on its side."
>    (if matrix (apply #'mapcar #'list matrix)))

Party pooper.  Well, at least he may have some fun reimplementing
mapcar or list...
From: Marco Antoniotti
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <fb6e3141-b54a-47db-9938-8e970e7521d0@d1g2000hsg.googlegroups.com>
On Sep 18, 7:34 am, namekuseijin <············@gmail.com> wrote:
> On 18 set, 01:54, "John Thingstad" <·······@online.no> wrote:
>
> > På Thu, 18 Sep 2008 05:57:00 +0200, skrev jrwats <······@gmail.com>:
> > > Hi all - this is not for a school project or anything (I'm a full-
> > > timer at the software company ppl love to hate), but I was trying to
> > > do an exercise in the back of ch 6 of Wilensky's book, Comon
> > > LISPcraft.  Anyway the challenge is to code up the solution to the
> > > transposition of a matrix (with the underlying implementation being a
> > > list - not a 2d - that is of course too easy).  My solution was a
> > > DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of...
>
> > (defun matrix-transpose (matrix)
> >    "Turn a matrix on its side."
> >    (if matrix (apply #'mapcar #'list matrix)))
>
> Party pooper.  Well, at least he may have some fun reimplementing
> mapcar or list...

Isn't that what they did with Ruby and other SLDJs?

Cheers
--
Marco
From: John Thingstad
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <op.uhnw5uc5ut4oq5@pandora.alfanett.no>
P� Thu, 18 Sep 2008 07:34:42 +0200, skrev namekuseijin  
<············@gmail.com>:

> On 18 set, 01:54, "John Thingstad" <·······@online.no> wrote:
>> P� Thu, 18 Sep 2008 05:57:00 +0200, skrev jrwats <······@gmail.com>:
>> > Hi all - this is not for a school project or anything (I'm a full-
>> > timer at the software company ppl love to hate), but I was trying to
>> > do an exercise in the back of ch 6 of Wilensky's book, Comon
>> > LISPcraft. �Anyway the challenge is to code up the solution to the
>> > transposition of a matrix (with the underlying implementation being a
>> > list - not a 2d - that is of course too easy). �My solution was a
>> > DESTRUCTIVE one which actually accumulates and �REMOVES 1st column  
>> of...
>>
>> (defun matrix-transpose (matrix)
>> � �"Turn a matrix on its side."
>> � �(if matrix (apply #'mapcar #'list matrix)))
>
> Party pooper.  Well, at least he may have some fun reimplementing
> mapcar or list...

Not so fast. I left a hole for the reader to fix.. apply is bound by the  
restriction call-arguments-limit which by spec is >= 50. (mapcar #'list  
'(1 2 3) '(4 5 6) '(7 8 9)) etc. will not work for more than 50 rows.  
Seeing how this approach works make it work for a arbitrary number of rows.

--------------
John Thingstad
From: jrwats
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <62a7350f-0a85-44ba-be41-b771712366bd@o40g2000prn.googlegroups.com>
> Not so fast. I left a hole for the reader to fix.. apply is bound by the  
> restriction call-arguments-limit which by spec is >= 50. (mapcar #'list  
> '(1 2 3) '(4 5 6) '(7 8 9)) etc. will not work for more than 50 rows.  
> Seeing how this approach works make it work for a arbitrary number of rows.
>
in slime (running sbcl)
my call-arguments-limit is call-arguments-limit 536870911... leaving
me completely disappointed about how much more verbose my inferior
solution was.
From: jrwats
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <217203b5-1dd4-42af-a998-8b74fd8832a8@q5g2000prf.googlegroups.com>
> Not so fast. I left a hole for the reader to fix.. apply is bound by the  
> restriction call-arguments-limit which by spec is >= 50. (mapcar #'list  
> '(1 2 3) '(4 5 6) '(7 8 9)) etc. will not work for more than 50 rows.  
> Seeing how this approach works make it work for a arbitrary number of rows.
>

Regarding my ineptness:
I don't feel so bad as the introduction to apply and mapcar are 20
pages after the end of ch. 6 :P
From: alien_guy
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <pan.2008.09.18.14.22.39@l.org>
On Thu, 18 Sep 2008 07:50:08 +0200, John Thingstad wrote:
> (mapcar #'list '(1 2 3) '(4 5 6) '(7 8 9)) etc. will not work
> for more than 50 rows.

*may* not *will*
most CL implementations have a much larger call-arguments-limit
From: John Thingstad
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <op.uhomcck2ut4oq5@pandora.alfanett.no>
P� Thu, 18 Sep 2008 16:22:39 +0200, skrev alien_guy <·@l.org>:

> On Thu, 18 Sep 2008 07:50:08 +0200, John Thingstad wrote:
>> (mapcar #'list '(1 2 3) '(4 5 6) '(7 8 9)) etc. will not work
>> for more than 50 rows.
>
> *may* not *will*
> most CL implementations have a much larger call-arguments-limit

Quite so. Also both rows and cols have this limit. Nevertheless, as I  
discovered the other day, gcl has a limit of 64. So it is still dangerous  
to assume this is always the case. Perhaps it is better to do something  
like this:


(defvar *list-matrix-max* call-arguments-limit
   "Limit to the size matrix-transpose can handle is given by the number of  
arguments \
a function can be called with.")

(defmethod matrix-p ((candidate list))
   (and
    (consp candidate)
    (or (< (length candidate) 2)
        (and
         (every #'consp candidate)
         (let* ((lengths (mapcar #'length candidate))
                (n (first lengths)))
           (every (lambda (c) (= c n)) (rest lengths)))))))

(deftype list-matrix () `(and list (satisfies matrix-p)))

(defmethod matrix-arity ((matrix list))
   "Return the matrix rows, colums on stack."
   (values (length (first matrix)) (length matrix)))

(defmethod matrix-transpose ((matrix list))
   (check-type matrix list-matrix)
   (multiple-value-bind (rows cols) (matrix-arity matrix)
       (if (and (<= rows *list-matrix-max*) (<= cols *list-matrix-max*))
         (apply #'mapcar #'list matrix)
         (error "Matrix to large for this function. (Max is ~D x ~:*~D)"  
*list-matrix-max*))))

(defun test ()
   (let ((*list-matrix-max* 50) ; set it to ANSI minimum value for  
call-arguments-limit
         (a '((1 2 3) (4 5 6) (7 8 9)))
         (b (loop repeat 100 collect (loop repeat 100 collect (random  
10000)))))
     (and
      (equal (matrix-transpose a) '((1 4 7) (2 5 8) (3 6 9)))
      (not (ignore-errors (matrix-transpose b))))))


--------------
John Thingstad
From: Pascal J. Bourguignon
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <87prn1jfox.fsf@hubble.informatimago.com>
"John Thingstad" <·······@online.no> writes:
> (defmethod matrix-transpose ((matrix list))
>   (check-type matrix list-matrix)
>   (multiple-value-bind (rows cols) (matrix-arity matrix)
>       (if (and (<= rows *list-matrix-max*) (<= cols *list-matrix-max*))
>         (apply #'mapcar #'list matrix)
>         (error "Matrix to large for this function. (Max is ~D x
> ~:*~D)"  *list-matrix-max*))))

Detecting the limit is nice. Overcoming it is better.

C/USER[5]> (let ((matrix (list (list 11 12 13) (list 21 22 23))))
  (values
   (loop
      :with matrix = (copy-list matrix) ; note we copy only the pointers to the
                                        ; columns, to be able to advance them.
      :while (some (function identity) matrix)
      :collect (loop
                  :for column :on matrix
                  :collect (pop (car column))))
   matrix))
((11 21) (12 22) (13 23)) ;
((11 12 13) (21 22 23))

C/USER[6]> (let* ((matrix (loop :for i :below (* 2 call-arguments-limit)
                  :collect (loop :for j :below (* 3/2 call-arguments-limit)
                              :collect (* i j))))
       (transposed (loop
                      :with matrix = (copy-list matrix)
                      :while (some (function identity) matrix)
                      :collect (loop
                                  :for column :on matrix
                                  :collect (pop (car column))))))

  (loop :for i :below (* 2 call-arguments-limit)
     :do (loop :for j :below (* 3/2 call-arguments-limit)
            :do (assert
                 (eql (elt (elt matrix i j))  (elt (elt transposed j i))))))
  :success)

:SUCCESS ; -- takes a long time.

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

"This statement is false."            In Lisp: (defun Q () (eq nil (Q)))
From: John Thingstad
Subject: Re: Coding challenge! non-destructuve matrix transpose
Date: 
Message-ID: <op.uhpb41h2ut4oq5@pandora.alfanett.no>
P� Thu, 18 Sep 2008 23:40:30 +0200, skrev Pascal J. Bourguignon  
<···@informatimago.com>:

> Detecting the limit is nice. Overcoming it is better.
>
> C/USER[5]> (let ((matrix (list (list 11 12 13) (list 21 22 23))))
>   (values
>    (loop
>       :with matrix = (copy-list matrix) ; note we copy only the pointers  
> to the
>                                         ; columns, to be able to advance  
> them.
>       :while (some (function identity) matrix)
>       :collect (loop
>                   :for column :on matrix
>                   :collect (pop (car column))))
>    matrix))
> ((11 21) (12 22) (13 23)) ;
> ((11 12 13) (21 22 23))
>

Or.. You could combine them! (This one should have less overhead.)

(defmethod matrix-transpose ((matrix list))
   (check-type matrix list-matrix)
   (multiple-value-bind (row-length column-length) (matrix-arity matrix)
     (if (< (max row-length column-length) *list-matrix-max*)
       (apply #'mapcar #'list matrix)
       (let ((colums (make-array (length matrix) :initial-contents matrix))
           result-row result)
         (dotimes (i row-length (nreverse result))
           (setf result-row nil)
           (push
            (dotimes (j column-length (nreverse result-row))
              (push (pop (aref colums j)) result-row))
            result)))))))

--------------
John Thingstad
From: Slobodan Blazeski
Subject: How apply #'mapcar #'list matrix works?
Date: 
Message-ID: <3f41da19-ab05-487f-9ffd-85a8401ca803@34g2000hsh.googlegroups.com>
John Thingstad wrote:
> P� Thu, 18 Sep 2008 05:57:00 +0200, skrev jrwats <······@gmail.com>:
>
> > Hi all - this is not for a school project or anything (I'm a full-
> > timer at the software company ppl love to hate), but I was trying to
> > do an exercise in the back of ch 6 of Wilensky's book, Comon
> > LISPcraft.  Anyway the challenge is to code up the solution to the
> > transposition of a matrix (with the underlying implementation being a
> > list - not a 2d - that is of course too easy).  My solution was a
> > DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of
> > the matrix (storing it as a list) and conses is it to the operation
> > applied to the rest of the matrix.  It was the only way I could think
> > of to do this and only visit each element once. Can you do this non-
> > destructively and only visit each element once?
> >
> > (defun pop-1st-col (mat)
> > "destructively returns 1st column of matrix"
> >   (cond
> >     ((null mat) nil)
> >     (t (let ((el (caar mat)))
> >          (setf (car mat) (cdar mat))
> >          (cons el (pop-1st-col (cdr mat)))))))
> >
> > (defun transpose-d (mat)
> > "destructively transpose matrix"
> >   (cond
> >     ((null (car mat)) nil)
> >     (t (cons (pop-1st-col mat)
> >              (transpose-d mat)))))
> >
> > (defmacro transpose (mat)
> >     `(setf ,mat (transpose-d ,mat)))
>
>  From PAIP:
>
> (defun matrix-transpose (matrix)
>    "Turn a matrix on its side."
>    (if matrix (apply #'mapcar #'list matrix)))
Though I've seen that solution I don't understand why it's working,
could someone please *macroexpand* it for me as I don't understand how
apply is working here.
apply expects a function then arguments, but mapcar expects a function
than arguments too. So what actually happenshere? Apply binds it's
functio to mapcar + list and treats matrix as argument?

thanks
bobi

>
>
> --------------
> John Thingstad
From: Slobodan Blazeski
Subject: Re: How apply #'mapcar #'list matrix works?
Date: 
Message-ID: <9fbb802b-d57b-43d9-8465-fbae4279bfbb@m3g2000hsc.googlegroups.com>
Slobodan Blazeski wrote:
> John Thingstad wrote:
> > P� Thu, 18 Sep 2008 05:57:00 +0200, skrev jrwats <······@gmail.com>:
> >
> > > Hi all - this is not for a school project or anything (I'm a full-
> > > timer at the software company ppl love to hate), but I was trying to
> > > do an exercise in the back of ch 6 of Wilensky's book, Comon
> > > LISPcraft.  Anyway the challenge is to code up the solution to the
> > > transposition of a matrix (with the underlying implementation being a
> > > list - not a 2d - that is of course too easy).  My solution was a
> > > DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of
> > > the matrix (storing it as a list) and conses is it to the operation
> > > applied to the rest of the matrix.  It was the only way I could think
> > > of to do this and only visit each element once. Can you do this non-
> > > destructively and only visit each element once?
> > >
> > > (defun pop-1st-col (mat)
> > > "destructively returns 1st column of matrix"
> > >   (cond
> > >     ((null mat) nil)
> > >     (t (let ((el (caar mat)))
> > >          (setf (car mat) (cdar mat))
> > >          (cons el (pop-1st-col (cdr mat)))))))
> > >
> > > (defun transpose-d (mat)
> > > "destructively transpose matrix"
> > >   (cond
> > >     ((null (car mat)) nil)
> > >     (t (cons (pop-1st-col mat)
> > >              (transpose-d mat)))))
> > >
> > > (defmacro transpose (mat)
> > >     `(setf ,mat (transpose-d ,mat)))
> >
> >  From PAIP:
> >
> > (defun matrix-transpose (matrix)
> >    "Turn a matrix on its side."
> >    (if matrix (apply #'mapcar #'list matrix)))
> Though I've seen that solution I don't understand why it's working,
> could someone please *macroexpand* it for me as I don't understand how
> apply is working here.
> apply expects a function then arguments, but mapcar expects a function
> than arguments too. So what actually happenshere? Apply binds it's
> functio to mapcar + list and treats matrix as argument?
Ok I understand list elements are treated as arguments to apply
(apply #'mapcar #'list '((1 2) (3 4) (5 6)))
((1 3 5) (2 4 6))
(mapcar #'list '(1 2) '(3 4) '(5 6))
((1 3 5) (2 4 6))


>
> thanks
> bobi
>
> >
> >
> > --------------
> > John Thingstad
From: Rainer Joswig
Subject: Re: How apply #'mapcar #'list matrix works?
Date: 
Message-ID: <joswig-28C1A9.13483818092008@news-europe.giganews.com>
In article 
<····································@34g2000hsh.googlegroups.com>,
 Slobodan Blazeski <·················@gmail.com> wrote:

> John Thingstad wrote:
> > P? Thu, 18 Sep 2008 05:57:00 +0200, skrev jrwats <······@gmail.com>:
> >
> > > Hi all - this is not for a school project or anything (I'm a full-
> > > timer at the software company ppl love to hate), but I was trying to
> > > do an exercise in the back of ch 6 of Wilensky's book, Comon
> > > LISPcraft.  Anyway the challenge is to code up the solution to the
> > > transposition of a matrix (with the underlying implementation being a
> > > list - not a 2d - that is of course too easy).  My solution was a
> > > DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of
> > > the matrix (storing it as a list) and conses is it to the operation
> > > applied to the rest of the matrix.  It was the only way I could think
> > > of to do this and only visit each element once. Can you do this non-
> > > destructively and only visit each element once?
> > >
> > > (defun pop-1st-col (mat)
> > > "destructively returns 1st column of matrix"
> > >   (cond
> > >     ((null mat) nil)
> > >     (t (let ((el (caar mat)))
> > >          (setf (car mat) (cdar mat))
> > >          (cons el (pop-1st-col (cdr mat)))))))
> > >
> > > (defun transpose-d (mat)
> > > "destructively transpose matrix"
> > >   (cond
> > >     ((null (car mat)) nil)
> > >     (t (cons (pop-1st-col mat)
> > >              (transpose-d mat)))))
> > >
> > > (defmacro transpose (mat)
> > >     `(setf ,mat (transpose-d ,mat)))
> >
> >  From PAIP:
> >
> > (defun matrix-transpose (matrix)
> >    "Turn a matrix on its side."
> >    (if matrix (apply #'mapcar #'list matrix)))
> Though I've seen that solution I don't understand why it's working,
> could someone please *macroexpand* it for me as I don't understand how
> apply is working here.
> apply expects a function then arguments, but mapcar expects a function
> than arguments too. So what actually happenshere? Apply binds it's
> functio to mapcar + list and treats matrix as argument?

(apply #'mapcar #'list '((1 2) (3 4)))

=>

(mapcar #'list '(1 2) '(3 4))

=>

(list (list 1 3)
      (list 2 4))

=>

((1 3) (2 4))


> 
> thanks
> bobi
> 
> >
> >
> > --------------
> > John Thingstad

-- 
http://lispm.dyndns.org/
From: Slobodan Blazeski
Subject: Re: How apply #'mapcar #'list matrix works?
Date: 
Message-ID: <b03a55df-6a94-47c8-a4bc-6c059c61cbb8@e39g2000hsf.googlegroups.com>
I understand it on my own but thanks anyway.
Could we control the transpose matrix like in my j example, using this
idiom?

bobi



Rainer Joswig wrote:
> In article
> <····································@34g2000hsh.googlegroups.com>,
>  Slobodan Blazeski <·················@gmail.com> wrote:
>
> > John Thingstad wrote:
> > > P? Thu, 18 Sep 2008 05:57:00 +0200, skrev jrwats <······@gmail.com>:
> > >
> > > > Hi all - this is not for a school project or anything (I'm a full-
> > > > timer at the software company ppl love to hate), but I was trying to
> > > > do an exercise in the back of ch 6 of Wilensky's book, Comon
> > > > LISPcraft.  Anyway the challenge is to code up the solution to the
> > > > transposition of a matrix (with the underlying implementation being a
> > > > list - not a 2d - that is of course too easy).  My solution was a
> > > > DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of
> > > > the matrix (storing it as a list) and conses is it to the operation
> > > > applied to the rest of the matrix.  It was the only way I could think
> > > > of to do this and only visit each element once. Can you do this non-
> > > > destructively and only visit each element once?
> > > >
> > > > (defun pop-1st-col (mat)
> > > > "destructively returns 1st column of matrix"
> > > >   (cond
> > > >     ((null mat) nil)
> > > >     (t (let ((el (caar mat)))
> > > >          (setf (car mat) (cdar mat))
> > > >          (cons el (pop-1st-col (cdr mat)))))))
> > > >
> > > > (defun transpose-d (mat)
> > > > "destructively transpose matrix"
> > > >   (cond
> > > >     ((null (car mat)) nil)
> > > >     (t (cons (pop-1st-col mat)
> > > >              (transpose-d mat)))))
> > > >
> > > > (defmacro transpose (mat)
> > > >     `(setf ,mat (transpose-d ,mat)))
> > >
> > >  From PAIP:
> > >
> > > (defun matrix-transpose (matrix)
> > >    "Turn a matrix on its side."
> > >    (if matrix (apply #'mapcar #'list matrix)))
> > Though I've seen that solution I don't understand why it's working,
> > could someone please *macroexpand* it for me as I don't understand how
> > apply is working here.
> > apply expects a function then arguments, but mapcar expects a function
> > than arguments too. So what actually happenshere? Apply binds it's
> > functio to mapcar + list and treats matrix as argument?
>
> (apply #'mapcar #'list '((1 2) (3 4)))
>
> =>
>
> (mapcar #'list '(1 2) '(3 4))
>
> =>
>
> (list (list 1 3)
>       (list 2 4))
>
> =>
>
> ((1 3) (2 4))
>
>
> >
> > thanks
> > bobi
> >
> > >
> > >
> > > --------------
> > > John Thingstad
>
> --
> http://lispm.dyndns.org/
From: Pascal J. Bourguignon
Subject: Re: How apply #'mapcar #'list matrix works?
Date: 
Message-ID: <7chc8dfxxe.fsf@pbourguignon.anevia.com>
Slobodan Blazeski <·················@gmail.com> writes:

> John Thingstad wrote:
>> P� Thu, 18 Sep 2008 05:57:00 +0200, skrev jrwats <······@gmail.com>:
>>
>> > Hi all - this is not for a school project or anything (I'm a full-
>> > timer at the software company ppl love to hate), but I was trying to
>> > do an exercise in the back of ch 6 of Wilensky's book, Comon
>> > LISPcraft.  Anyway the challenge is to code up the solution to the
>> > transposition of a matrix (with the underlying implementation being a
>> > list - not a 2d - that is of course too easy).  My solution was a
>> > DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of
>> > the matrix (storing it as a list) and conses is it to the operation
>> > applied to the rest of the matrix.  It was the only way I could think
>> > of to do this and only visit each element once. Can you do this non-
>> > destructively and only visit each element once?
>> >
>> > (defun pop-1st-col (mat)
>> > "destructively returns 1st column of matrix"
>> >   (cond
>> >     ((null mat) nil)
>> >     (t (let ((el (caar mat)))
>> >          (setf (car mat) (cdar mat))
>> >          (cons el (pop-1st-col (cdr mat)))))))
>> >
>> > (defun transpose-d (mat)
>> > "destructively transpose matrix"
>> >   (cond
>> >     ((null (car mat)) nil)
>> >     (t (cons (pop-1st-col mat)
>> >              (transpose-d mat)))))
>> >
>> > (defmacro transpose (mat)
>> >     `(setf ,mat (transpose-d ,mat)))
>>
>>  From PAIP:
>>
>> (defun matrix-transpose (matrix)
>>    "Turn a matrix on its side."
>>    (if matrix (apply #'mapcar #'list matrix)))
> Though I've seen that solution I don't understand why it's working,
> could someone please *macroexpand* it for me as I don't understand how
> apply is working here.
> apply expects a function then arguments, but mapcar expects a function
> than arguments too. So what actually happenshere? Apply binds it's
> functio to mapcar + list and treats matrix as argument?


(defun quote-it (it) `(quote ,it))

(defun expand-apply ( fun &rest args)
  (let* ((first-args (butlast   args))
         (last-args  (car (last args)))
         (all-args   (append first-args last-args))
         (*print-right-margin* nil)
         result )
    (format t "~%   ~S ~%" `(apply ',fun ,@(mapcar (function quote-it) args)))
    (format t ";; is equivalent to:~%   ~S~%"
            (setf result 
                  `(funcall ',fun
                            ,@(mapcar (function quote-it) all-args))))
    (cond
      ((eq (function mapcar) fun)
       #-clisp (error "How to get the name of a function?")
       (format t ";; is equivalent to:~%   ~S~%"
               (setf result
                     `(,(system::function-name (function mapcar))
                        ,@(mapcar (function quote-it) all-args)))
               result)
       (when (eq 'mapcar (system::function-name (function mapcar)))
         (format t ";; is equivalent to:~%   ~S~%"
                 (setf result
                       `(cons (funcall ',(first all-args)
                                       ,@(mapcar (compose quote-it first)
                                                 (rest all-args)))
                              (,(system::function-name (function mapcar))
                                ',(first all-args)
                                ,@(mapcar (compose quote-it rest)
                                          (rest all-args)))))))))
    result))


(let ((matrix (list (list 11 12 13) (list 21 22 23))))
  (eval (expand-apply #'mapcar #'list matrix)))

   (APPLY '#<SYSTEM-FUNCTION MAPCAR> '#<SYSTEM-FUNCTION LIST> '((11 12 13) (21 22 23))) 
;; is equivalent to:
   (FUNCALL '#<SYSTEM-FUNCTION MAPCAR> '#<SYSTEM-FUNCTION LIST> '(11 12 13) '(21 22 23))
;; is equivalent to:
   (MAPCAR '#<SYSTEM-FUNCTION LIST> '(11 12 13) '(21 22 23))
;; is equivalent to:
   (CONS (FUNCALL '#<SYSTEM-FUNCTION LIST> '11 '21) (MAPCAR '#<SYSTEM-FUNCTION LIST> '(12 13) '(22 23)))

--> ((11 21) (12 22) (13 23))



(let ((matrix (list (list 11 12 13) (list 21 22 23) (list 31 32 33)  (list 41 42 43))))
  (eval (expand-apply #'mapcar #'list matrix)))

   (APPLY '#<SYSTEM-FUNCTION MAPCAR> '#<SYSTEM-FUNCTION LIST> '((11 12 13) (21 22 23) (31 32 33) (41 42 43))) 
;; is equivalent to:
   (FUNCALL '#<SYSTEM-FUNCTION MAPCAR> '#<SYSTEM-FUNCTION LIST> '(11 12 13) '(21 22 23) '(31 32 33) '(41 42 43))
;; is equivalent to:
   (MAPCAR '#<SYSTEM-FUNCTION LIST> '(11 12 13) '(21 22 23) '(31 32 33) '(41 42 43))
;; is equivalent to:
   (CONS (FUNCALL '#<SYSTEM-FUNCTION LIST> '11 '21 '31 '41) (MAPCAR '#<SYSTEM-FUNCTION LIST> '(12 13) '(22 23) '(32 33) '(42 43)))

--> ((11 21 31 41) (12 22 32 42) (13 23 33 43))



Alternatively, you could do this:


(shadow '(apply mapcar list))
(defun apply  (&rest args) (cl:apply (function cl:apply)  args))
(defun mapcar (&rest args) (cl:apply (function cl:mapcar) args))
(defun list   (&rest args) (cl:apply (function cl:list)   args))
(trace apply mapcar list)

(let ((matrix (list (list 11 12 13) (list 21 22 23) (list 31 32 33)  (list 41 42 43))))
  (apply #'mapcar #'list matrix))

(untrace apply mapcar list)
(mapcar (function unintern) '(apply mapcar list))
(mapcar (function import)   '(cl:apply cl:mapcar cl:list))

;; We need to redefine our functions, because TRACE is not specified to work on CL functions.


;; This would display:

 1. Trace: (LIST '11 '12 '13)
 1. Trace: LIST ==> (11 12 13)
 1. Trace: (LIST '21 '22 '23)
 1. Trace: LIST ==> (21 22 23)
 1. Trace: (LIST '31 '32 '33)
 1. Trace: LIST ==> (31 32 33)
 1. Trace: (LIST '41 '42 '43)
 1. Trace: LIST ==> (41 42 43)
 1. Trace: (LIST '(11 12 13) '(21 22 23) '(31 32 33) '(41 42 43))
 1. Trace: LIST ==> ((11 12 13) (21 22 23) (31 32 33) (41 42 43))
 1. Trace: (APPLY '#<COMPILED-FUNCTION TRACED-MAPCAR> '#<COMPILED-FUNCTION TRACED-LIST> '((11 12 13) (21 22 23) (31 32 33) (41 42 43)))
  2. Trace: (MAPCAR '#<COMPILED-FUNCTION TRACED-LIST> '(11 12 13) '(21 22 23) '(31 32 33) '(41 42 43))
   3. Trace: (LIST '11 '21 '31 '41)
   3. Trace: LIST ==> (11 21 31 41)
   3. Trace: (LIST '12 '22 '32 '42)
   3. Trace: LIST ==> (12 22 32 42)
   3. Trace: (LIST '13 '23 '33 '43)
   3. Trace: LIST ==> (13 23 33 43)
  2. Trace: MAPCAR ==> ((11 21 31 41) (12 22 32 42) (13 23 33 43))
 1. Trace: APPLY ==> ((11 21 31 41) (12 22 32 42) (13 23 33 43))
((11 21 31 41) (12 22 32 42) (13 23 33 43))



-- 
__Pascal Bourguignon__
From: Slobodan Blazeski
Subject: Re: How apply #'mapcar #'list matrix works?
Date: 
Message-ID: <59a164c7-54e0-4ec6-a8d9-880943fa19a7@t54g2000hsg.googlegroups.com>
Why do people who complain about savages of cll give ONE, single your
reply about deleting files as example and they NEVER mention COUNTLESS
replies like below.
You can't get reply with such quality like below even from $300 per
hour consultants.

Long live the Pascal.
Long live the cll.

bobi
Hat off singing La Marseillaise




Pascal J. Bourguignon wrote:
> Slobodan Blazeski <·················@gmail.com> writes:
>
> > John Thingstad wrote:
> >> P� Thu, 18 Sep 2008 05:57:00 +0200, skrev jrwats <······@gmail.com>:
> >>
> >> > Hi all - this is not for a school project or anything (I'm a full-
> >> > timer at the software company ppl love to hate), but I was trying to
> >> > do an exercise in the back of ch 6 of Wilensky's book, Comon
> >> > LISPcraft.  Anyway the challenge is to code up the solution to the
> >> > transposition of a matrix (with the underlying implementation being a
> >> > list - not a 2d - that is of course too easy).  My solution was a
> >> > DESTRUCTIVE one which actually accumulates and  REMOVES 1st column of
> >> > the matrix (storing it as a list) and conses is it to the operation
> >> > applied to the rest of the matrix.  It was the only way I could think
> >> > of to do this and only visit each element once. Can you do this non-
> >> > destructively and only visit each element once?
> >> >
> >> > (defun pop-1st-col (mat)
> >> > "destructively returns 1st column of matrix"
> >> >   (cond
> >> >     ((null mat) nil)
> >> >     (t (let ((el (caar mat)))
> >> >          (setf (car mat) (cdar mat))
> >> >          (cons el (pop-1st-col (cdr mat)))))))
> >> >
> >> > (defun transpose-d (mat)
> >> > "destructively transpose matrix"
> >> >   (cond
> >> >     ((null (car mat)) nil)
> >> >     (t (cons (pop-1st-col mat)
> >> >              (transpose-d mat)))))
> >> >
> >> > (defmacro transpose (mat)
> >> >     `(setf ,mat (transpose-d ,mat)))
> >>
> >>  From PAIP:
> >>
> >> (defun matrix-transpose (matrix)
> >>    "Turn a matrix on its side."
> >>    (if matrix (apply #'mapcar #'list matrix)))
> > Though I've seen that solution I don't understand why it's working,
> > could someone please *macroexpand* it for me as I don't understand how
> > apply is working here.
> > apply expects a function then arguments, but mapcar expects a function
> > than arguments too. So what actually happenshere? Apply binds it's
> > functio to mapcar + list and treats matrix as argument?
>
>
> (defun quote-it (it) `(quote ,it))
>
> (defun expand-apply ( fun &rest args)
>   (let* ((first-args (butlast   args))
>          (last-args  (car (last args)))
>          (all-args   (append first-args last-args))
>          (*print-right-margin* nil)
>          result )
>     (format t "~%   ~S ~%" `(apply ',fun ,@(mapcar (function quote-it) args)))
>     (format t ";; is equivalent to:~%   ~S~%"
>             (setf result
>                   `(funcall ',fun
>                             ,@(mapcar (function quote-it) all-args))))
>     (cond
>       ((eq (function mapcar) fun)
>        #-clisp (error "How to get the name of a function?")
>        (format t ";; is equivalent to:~%   ~S~%"
>                (setf result
>                      `(,(system::function-name (function mapcar))
>                         ,@(mapcar (function quote-it) all-args)))
>                result)
>        (when (eq 'mapcar (system::function-name (function mapcar)))
>          (format t ";; is equivalent to:~%   ~S~%"
>                  (setf result
>                        `(cons (funcall ',(first all-args)
>                                        ,@(mapcar (compose quote-it first)
>                                                  (rest all-args)))
>                               (,(system::function-name (function mapcar))
>                                 ',(first all-args)
>                                 ,@(mapcar (compose quote-it rest)
>                                           (rest all-args)))))))))
>     result))
>
>
> (let ((matrix (list (list 11 12 13) (list 21 22 23))))
>   (eval (expand-apply #'mapcar #'list matrix)))
>
>    (APPLY '#<SYSTEM-FUNCTION MAPCAR> '#<SYSTEM-FUNCTION LIST> '((11 12 13) (21 22 23)))
> ;; is equivalent to:
>    (FUNCALL '#<SYSTEM-FUNCTION MAPCAR> '#<SYSTEM-FUNCTION LIST> '(11 12 13) '(21 22 23))
> ;; is equivalent to:
>    (MAPCAR '#<SYSTEM-FUNCTION LIST> '(11 12 13) '(21 22 23))
> ;; is equivalent to:
>    (CONS (FUNCALL '#<SYSTEM-FUNCTION LIST> '11 '21) (MAPCAR '#<SYSTEM-FUNCTION LIST> '(12 13) '(22 23)))
>
> --> ((11 21) (12 22) (13 23))
>
>
>
> (let ((matrix (list (list 11 12 13) (list 21 22 23) (list 31 32 33)  (list 41 42 43))))
>   (eval (expand-apply #'mapcar #'list matrix)))
>
>    (APPLY '#<SYSTEM-FUNCTION MAPCAR> '#<SYSTEM-FUNCTION LIST> '((11 12 13) (21 22 23) (31 32 33) (41 42 43)))
> ;; is equivalent to:
>    (FUNCALL '#<SYSTEM-FUNCTION MAPCAR> '#<SYSTEM-FUNCTION LIST> '(11 12 13) '(21 22 23) '(31 32 33) '(41 42 43))
> ;; is equivalent to:
>    (MAPCAR '#<SYSTEM-FUNCTION LIST> '(11 12 13) '(21 22 23) '(31 32 33) '(41 42 43))
> ;; is equivalent to:
>    (CONS (FUNCALL '#<SYSTEM-FUNCTION LIST> '11 '21 '31 '41) (MAPCAR '#<SYSTEM-FUNCTION LIST> '(12 13) '(22 23) '(32 33) '(42 43)))
>
> --> ((11 21 31 41) (12 22 32 42) (13 23 33 43))
>
>
>
> Alternatively, you could do this:
>
>
> (shadow '(apply mapcar list))
> (defun apply  (&rest args) (cl:apply (function cl:apply)  args))
> (defun mapcar (&rest args) (cl:apply (function cl:mapcar) args))
> (defun list   (&rest args) (cl:apply (function cl:list)   args))
> (trace apply mapcar list)
>
> (let ((matrix (list (list 11 12 13) (list 21 22 23) (list 31 32 33)  (list 41 42 43))))
>   (apply #'mapcar #'list matrix))
>
> (untrace apply mapcar list)
> (mapcar (function unintern) '(apply mapcar list))
> (mapcar (function import)   '(cl:apply cl:mapcar cl:list))
>
> ;; We need to redefine our functions, because TRACE is not specified to work on CL functions.
>
>
> ;; This would display:
>
>  1. Trace: (LIST '11 '12 '13)
>  1. Trace: LIST ==> (11 12 13)
>  1. Trace: (LIST '21 '22 '23)
>  1. Trace: LIST ==> (21 22 23)
>  1. Trace: (LIST '31 '32 '33)
>  1. Trace: LIST ==> (31 32 33)
>  1. Trace: (LIST '41 '42 '43)
>  1. Trace: LIST ==> (41 42 43)
>  1. Trace: (LIST '(11 12 13) '(21 22 23) '(31 32 33) '(41 42 43))
>  1. Trace: LIST ==> ((11 12 13) (21 22 23) (31 32 33) (41 42 43))
>  1. Trace: (APPLY '#<COMPILED-FUNCTION TRACED-MAPCAR> '#<COMPILED-FUNCTION TRACED-LIST> '((11 12 13) (21 22 23) (31 32 33) (41 42 43)))
>   2. Trace: (MAPCAR '#<COMPILED-FUNCTION TRACED-LIST> '(11 12 13) '(21 22 23) '(31 32 33) '(41 42 43))
>    3. Trace: (LIST '11 '21 '31 '41)
>    3. Trace: LIST ==> (11 21 31 41)
>    3. Trace: (LIST '12 '22 '32 '42)
>    3. Trace: LIST ==> (12 22 32 42)
>    3. Trace: (LIST '13 '23 '33 '43)
>    3. Trace: LIST ==> (13 23 33 43)
>   2. Trace: MAPCAR ==> ((11 21 31 41) (12 22 32 42) (13 23 33 43))
>  1. Trace: APPLY ==> ((11 21 31 41) (12 22 32 42) (13 23 33 43))
> ((11 21 31 41) (12 22 32 42) (13 23 33 43))
>
>
>
> --
> __Pascal Bourguignon__