help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why are there [v e c t o r s] in Lisp?


From: Pascal J. Bourguignon
Subject: Re: why are there [v e c t o r s] in Lisp?
Date: Sat, 17 Oct 2015 18:15:47 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Emanuel Berg <embe8573@student.uu.se> writes:

> "Pascal J. Bourguignon" <pjb@informatimago.com>
> writes:
>
>> Obviously not.
>>
>> And linear algebra deals with matrices and tensors
>> etc, which are arrays!
>
> They are not called arrays but matrices so there is no
> confusing the data structure array with the linear
> algebra concept matrix.

Nobody but you is confusing arrays with matrices, since they're not the
same thing. 

vectors are arrays.
matrices are arrays.
tensors are arrays.

But you don't have arrays when you only have vectors (like in C).



Notice how in CL, there's a distinction between a 3-vector and a
1,3-matrix, or a 1,1,3-array:

cl-user> (make-array '(3))
#(0 0 0)
cl-user> (make-array '(1 3))
#2A((0 0 0))
cl-user> (make-array '(1 1 3))
#3A(((0 0 0)))

Or similary, there's a distinction between a 3,4-matrix and a
1,3,4-array:

cl-user> (make-array '(3 4))
#2A((0 0 0 0) (0 0 0 0) (0 0 0 0))
cl-user> (make-array '(1 3 4))
#3A(((0 0 0 0) (0 0 0 0) (0 0 0 0)))
cl-user> 


It's a trivial notion of subclass/superclass, if you had any object
oriented knowledge.

That said, while CL distinguishes a vector subclass of arrays, it
doesn't name a matrix subclass.


In emacs lisp, since we don't have arrays, only vectors, we have to use
tricks like in C to implement matrices or tensors:

   (type-of (make-array '(2 3))) --> vector

Happily, emacs lisp helps a little, creating a vector of vector:

   (make-array '(2 3))           --> [[nil nil nil] [nil nil nil]]

   (aref (make-array '(2 3)) 0)  --> [nil nil nil]


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

[Prev in Thread] Current Thread [Next in Thread]