[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

suspicious definition of type in CLHS

Jim Newton

11/16/2015 12:35:00 PM

CLHS 4.1 defines type as follows: A type is a (possibly infinite) set of objects.

I'm trying to write an article which potentially non-lispers may read, and that definition seems problematic to me, especially in the presence of the SATISFIES types taking function redefinition into account, and also types defined by classes in the presence both of CHANGE-CLASS and class redefinition.

It seems to me that a type is really a set of objects at a particular time slice of an executing program.

E.g.

(defun F (x)
(member x '(1 2 3))

(typep 3 '(satisfies F))
==> t

(defun F (x)
(member x '(2 4 6))

(typep 3 '(satisfies F))
==> nil

The type (satisfies F), ie., the set of objects belonging to this type, changes as the program is executing.

Does anyone know whether this subtlety is addressed anywhere in the specification.
Or should it just be considered obvious?

10 Answers

TibetanMonkey, the Beach Cruiser Philosopher

1/3/2013 12:32:00 AM

0

On Jan 2, 12:31 pm, Gunner <gunnera...@gmail.com> wrote:
> On Wed, 2 Jan 2013 07:00:21 -0800 (PST), "TibetanMonkey, the Beach
>
>
>
>
>
>
>
>
>
> Cruiser Philosopher" <thetibetanmon...@gmail.com> wrote:
> >On Jan 2, 1:35 am, Gunner <gunnera...@gmail.com> wrote:
> >> On Tue, 1 Jan 2013 21:14:43 -0800 (PST), "TibetanMonkey, the Beach
>
> >> Cruiser Philosopher" <thetibetanmon...@gmail.com> wrote:
>
> >> >> Actually..the bullies ride the bicycles, in my experience.
>
> >> >Not much a cyclist can do against a man behind 5 tons of steel.
>
> >> Tell that to the North Vietnamese
>
> >Regrettably the cyclists are not armed. Respect would come from an RPG
> >slung across your back.
>
> Why arent they armed? No CCW in your state?
>
> I always have a gun on my person, biking etc etc
>
> However respect isnt given..its earned.

Like I said, I prefer an RPG or a machete.

Hey, I may even be lucky!

"Dude...First of all it does not matter what the law says it really
depends on the cops, they could see it as a knife (weapon) or see it
as a tool (non-weapon). Furthermore you will pass through dozens of
jurisdictions where is/isn't/is/isn't/is/isn't/is etc....in a short
period of time thus even if you know what the law is, it changes so
often that it is not funny.

Your best bet is to strap the machete to your pack openly and treat it
like camping equipment."

http://www.survivalistboards.com/showthread.ph...

***

I figure that if the cops don't like me they'll take me in until I
hire the Jewish lawyer to get me out.

Because, as you are already know, it's all about money.

Pascal J. Bourguignon

11/16/2015 1:35:00 PM

0

Jim Newton <jimka.issy@gmail.com> writes:

> CLHS 4.1 defines type as follows: A type is a (possibly infinite) set of objects.
>
> I'm trying to write an article which potentially non-lispers may read,
> and that definition seems problematic to me, especially in the
> presence of the SATISFIES types taking function redefinition into
> account, and also types defined by classes in the presence both of
> CHANGE-CLASS and class redefinition.
>
> It seems to me that a type is really a set of objects at a particular
> time slice of an executing program.

This is perfectly correct.

> E.g.
>
> (defun F (x)
> (member x '(1 2 3))
>
> (typep 3 '(satisfies F))
> ==> t
>
> (defun F (x)
> (member x '(2 4 6))
>
> (typep 3 '(satisfies F))
> ==> nil
>
> The type (satisfies F), ie., the set of objects belonging to this
> type, changes as the program is executing.
>
> Does anyone know whether this subtlety is addressed anywhere in the
> specification. Or should it just be considered obvious?

It is rather obvious that type checking in CL must be done at run-time,
and can hardly be done at compilation time without global analysis
(which AFAIK, is implemented by no CL implementation).

(And even, the result of global analysis can be that it is not possible
to determine before run-time what a type will be, given READ+EVAL).


--
__Pascal Bourguignon__ http://www.informat...
â??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

Jim Newton

11/16/2015 2:20:00 PM

0

Even without function nor class redefinition you can have examples such as the following.

(setf x (make-instance 'A))
(typep x 'A)
==> t
(change-class x 'B)
(typep x 'A)
==> nil

Carlos

11/16/2015 4:08:00 PM

0

[Jim Newton <jimka.issy@gmail.com>, 2015-11-16 04:34]
> CLHS 4.1 defines type as follows: A type is a (possibly infinite) set
> of objects.
>
> I'm trying to write an article which potentially non-lispers may
> read, and that definition seems problematic to me, especially in the
> presence of the SATISFIES types taking function redefinition into
> account, and also types defined by classes in the presence both of
> CHANGE-CLASS and class redefinition.
>
> It seems to me that a type is really a set of objects at a particular
> time slice of an executing program.
>
> E.g.
>
> (defun F (x)
> (member x '(1 2 3))
>
> (typep 3 '(satisfies F))
> ==> t
>
> (defun F (x)
> (member x '(2 4 6))
>
> (typep 3 '(satisfies F))
> ==> nil
>
> The type (satisfies F), ie., the set of objects belonging to this
> type, changes as the program is executing.
>
> Does anyone know whether this subtlety is addressed anywhere in the
> specification. Or should it just be considered obvious?
>

I think it's obvious. Even without using CHANGE-CLASS or redefining the
"satisfies" function, just by creating objects you change a type's
membership.

--


Barry Margolin

11/16/2015 4:15:00 PM

0

In article <c8f0e409-a51d-4345-bb3d-8c93230df1a1@googlegroups.com>,
Jim Newton <jimka.issy@gmail.com> wrote:

> Even without function nor class redefinition you can have examples such as
> the following.

He mentioned CHANGE-CLASS in the OP.

Basically, the answer is that CL's definition of type is dynamic, since
it allows both redefining types and reassigning types. What's the
problem with that?

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Barry Margolin

11/16/2015 4:19:00 PM

0

In article <20151116170808.199f541c@samara.DOMA>,
Carlos <angus@quovadis.com.ar> wrote:

> [Jim Newton <jimka.issy@gmail.com>, 2015-11-16 04:34]
> > CLHS 4.1 defines type as follows: A type is a (possibly infinite) set
> > of objects.
> >
> > I'm trying to write an article which potentially non-lispers may
> > read, and that definition seems problematic to me, especially in the
> > presence of the SATISFIES types taking function redefinition into
> > account, and also types defined by classes in the presence both of
> > CHANGE-CLASS and class redefinition.
> >
> > It seems to me that a type is really a set of objects at a particular
> > time slice of an executing program.
> >
> > E.g.
> >
> > (defun F (x)
> > (member x '(1 2 3))
> >
> > (typep 3 '(satisfies F))
> > ==> t
> >
> > (defun F (x)
> > (member x '(2 4 6))
> >
> > (typep 3 '(satisfies F))
> > ==> nil
> >
> > The type (satisfies F), ie., the set of objects belonging to this
> > type, changes as the program is executing.
> >
> > Does anyone know whether this subtlety is addressed anywhere in the
> > specification. Or should it just be considered obvious?
> >
>
> I think it's obvious. Even without using CHANGE-CLASS or redefining the
> "satisfies" function, just by creating objects you change a type's
> membership.

That's true in pretty much every language.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Kaz Kylheku

11/16/2015 8:19:00 PM

0

On 2015-11-16, Barry Margolin <barmar@alum.mit.edu> wrote:
> In article <20151116170808.199f541c@samara.DOMA>,
> Carlos <angus@quovadis.com.ar> wrote:
>> I think it's obvious. Even without using CHANGE-CLASS or redefining the
>> "satisfies" function, just by creating objects you change a type's
>> membership.
>
> That's true in pretty much every language.

That depends on whether you regard "members of a class" to be the set of all
possible instances that could ever be, or just the set of actual instances
tht are.

Kalle Olavi Niemitalo

11/16/2015 8:23:00 PM

0

Jim Newton <jimka.issy@gmail.com> writes:

> especially in the presence of the SATISFIES types taking
> function redefinition into account, and also types defined by
> classes in the presence both of CHANGE-CLASS and class
> redefinition.

Also the CONS compound type specifier.

(let ((x (cons t t)))
(values (prog1 (typep x '(cons symbol integer))
(setf (cdr x) 0))
(typep x '(cons symbol integer))))

Pascal Costanza

11/16/2015 8:33:00 PM

0

On 16/11/2015 13:34, Jim Newton wrote:
> CLHS 4.1 defines type as follows: A type is a (possibly infinite) set of objects.
>
> I'm trying to write an article which potentially non-lispers may read, and that definition seems problematic to me, especially in the presence of the SATISFIES types taking function redefinition into account, and also types defined by classes in the presence both of CHANGE-CLASS and class redefinition.
>
> It seems to me that a type is really a set of objects at a particular time slice of an executing program.
>
> E.g.
>
> (defun F (x)
> (member x '(1 2 3))
>
> (typep 3 '(satisfies F))
> ==> t
>
> (defun F (x)
> (member x '(2 4 6))
>
> (typep 3 '(satisfies F))
> ==> nil
>
> The type (satisfies F), ie., the set of objects belonging to this type, changes as the program is executing.
>
> Does anyone know whether this subtlety is addressed anywhere in the specification.
> Or should it just be considered obvious?

It should be considered obvious.

Please keep in mind that the notion of 'type' is typically considered to
be a syntactic concept, at least in statically typed languages, which is
very different from the notion of 'type' in Common Lisp. You probably
already know that, but if not, this may be the cause why you consider
this problematic.

Pascal

--
My website: http:/...
Common Lisp Document Repository: http://cdr.eu...
Closer to MOP & ContextL: http://common-lisp.net/proje...
The views expressed are my own, and not those of my employer.

Pascal J. Bourguignon

11/16/2015 8:38:00 PM

0

Kalle Olavi Niemitalo <kon@iki.fi> writes:

> Jim Newton <jimka.issy@gmail.com> writes:
>
>> especially in the presence of the SATISFIES types taking
>> function redefinition into account, and also types defined by
>> classes in the presence both of CHANGE-CLASS and class
>> redefinition.
>
> Also the CONS compound type specifier.
>
> (let ((x (cons t t)))
> (values (prog1 (typep x '(cons symbol integer))
> (setf (cdr x) 0))
> (typep x '(cons symbol integer))))

Indeed. Let's remember that the type is not attached to the variable X,
but to the value currently bound to the variable X, and if this value is
mutable (without changing the binding), that can indeed change its
relationship with types.

Also, to add one more dynamism (unrelated to types, but still funny to
mention):

(shadow 'typep)
(declaim (notinline typep))
(defun typep (v y) (cl:typep v y))
(let ((x (cons t t)))
(values (prog1 (typep x '(cons symbol integer))
(setf (fdefinition 'typep)
(lambda (v y)
(declaim (ignore v y))
(zerop (random 2)))))
(typep x '(cons symbol integer))))


--
__Pascal Bourguignon__ http://www.informat...
â??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