all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* what is `self-typing' ?
@ 2009-12-26  7:53 waterloo
  2009-12-26  8:45 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: waterloo @ 2009-12-26  7:53 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 347 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 531 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: what is `self-typing' ?
  2009-12-26  7:53 what is `self-typing' ? waterloo
@ 2009-12-26  8:45 ` Eli Zaretskii
  0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2009-12-26  8:45 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sat, 26 Dec 2009 15:53:47 +0800
> From: waterloo <waterloo2005@gmail.com>
> 
> > 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

The explanation appears right there: ``self-typing'' objects are
objects that have their type implicit in the object itself.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: what is `self-typing' ?
       [not found] <mailman.210.1261814034.18930.help-gnu-emacs@gnu.org>
@ 2009-12-26 13:32 ` Pascal J. Bourguignon
  0 siblings, 0 replies; 3+ messages in thread
From: Pascal J. Bourguignon @ 2009-12-26 13:32 UTC (permalink / raw)
  To: help-gnu-emacs

waterloo <waterloo2005@gmail.com> 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/


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-12-26 13:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-26  7:53 what is `self-typing' ? waterloo
2009-12-26  8:45 ` Eli Zaretskii
     [not found] <mailman.210.1261814034.18930.help-gnu-emacs@gnu.org>
2009-12-26 13:32 ` Pascal J. Bourguignon

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.