From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: what is `self-typing' ? Date: Sat, 26 Dec 2009 14:32:16 +0100 Organization: Informatimago Message-ID: <87zl55n9nj.fsf@hubble.informatimago.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1261834860 24060 80.91.229.12 (26 Dec 2009 13:41:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 26 Dec 2009 13:41:00 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Dec 26 14:40:53 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NOWt3-0004eo-1O for geh-help-gnu-emacs@m.gmane.org; Sat, 26 Dec 2009 14:40:53 +0100 Original-Received: from localhost ([127.0.0.1]:59756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NOWt3-0006qt-6g for geh-help-gnu-emacs@m.gmane.org; Sat, 26 Dec 2009 08:40:53 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 77 Original-X-Trace: individual.net /GK/g80NN/dJ8zY6uDzY6gbh9mCmieWZGAQ41i4SRPe4e+DuMF Cancel-Lock: sha1:ODFiZTA2NzIyMGE2NTlkOTZhNjMwMTZlMjExZjllZGMyN2Q5ZTdkNg== sha1:OFDWIeRA5kHB/vLKrXtnWlSj3r4= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (gnu/linux) Original-Xref: news.stanford.edu gnu.emacs.help:175802 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:70875 Archived-At: waterloo writes: > I can not understand a para in Elisp manual : > > Lisp is unlike many other languages in that its objects are > "self-typing": the primitive type of each object is implicit in the > object itself.  For example, if an object is a vector, nothing can > treat it as a number; Lisp knows it is a vector, not a number. > > What is `self-typing' ? thanks As mentionned by Eli. But this require some more explaination. Some languages are defined so that variables can hold only objects of a given type (you declare the type of the variable, or it is infered automatically at compilation time). For example, C or Haskell. Since all the types of the objects are known at compilation time from the variables they're stored in, the compiler doesn't need to generate code to store the type along with the object, or along with the variable: the type is implicity. In C, typeof(42) or int a=42; typeof(a) is computed at compilation time. Some languages are defined so that variables can hold objects of different types, at different times. In that case, the type is not attached to the variable, but must be attached to the objects themselves. For example, Lisp or Smalltalk. Since it is rarely possible to know what type of object a variable will hold (some type inference can still be applied to optimize out some function, but there remains a lot of functions where type inference doesn't restrict much the possible types, the more so when global analysis is not practical or possible), then the type of each object has to be kept with the object. In Lisp, (type-of 42) or (let ((a 42)) (type-of 42)) is computed at run-time. Notably, you can write: (type-of (read)) and depending on what you enter at run-time, will get back one type or another: M-x ielm RET *** Welcome to IELM *** Type (describe-mode) for help. ELISP> (type-of (read)) Lisp expression: 42 integer ELISP> (type-of (read)) Lisp expression: "fourty-two" string ELISP> (type-of (read)) Lisp expression: fourty-two symbol ELISP> (type-of (read)) Lisp expression: (fourty two) cons ELISP> There are also languages where both things are more or less possible, you can have variables with pre-defined types holding only one type of object, and variables which can hold objects of various types, but of a same root class. For example, C++ or Java. These languages usually provide so called "Plain Old Data" types which correspond to the type of objects that can only be stored in variables with predefined types. These objects of these POD types usually don't have the type attached to them, these objects can only be stored in variables with pre-defined type. When you want to store such an object in a variable-type variable, you have to wrap it in another object, a typed object, instance of a class. In Java, you have a POD type int and an object class Integer. -- __Pascal Bourguignon__ http://www.informatimago.com/