From: Javier
Subject: Creating a new type
Date: 
Message-ID: <f4cb1611-ae1f-46a0-a015-0dde522fc526@l76g2000hse.googlegroups.com>
Ok, I want to create a new numerical type (like a set) for example:

type BUG_RANGE is range -13..34;

Ok, in Lisp, defining the type is a little dificult but possible:

(defun is-bug-range (a)
  (and (typep a 'fixnum)
       (>= a -13)
       (<= a 34)))

(deftype bug-range ()
  `(satisfies is-bug-range))

CL-USER> (typep 8 'bug-range)
T
CL-USER> (typep 89 'bug-range)
NIL

(defun check-it ()
  (let ((c 4))
    (declare (bug-range c))
    (setf c 89))) ; error, c does not satiesfies is-bug-range, which
is correct


The problem is:

CL-USER> (type-of 8)
(INTEGER 0 536870911)

I want the response from type-of to be BUG-RANGE. That is, when the
number is in the range of -13 and 34, I want the system to say that
the number is BUG-RANGE by default. Is it possible?

Another thing I want is to declare the type of a special variable, for
example, to declare it BUG-RANGE, but don't know exactly how, SBCL
produces an error when using DECLARE in the REPL:

(defparameter *jj* 8)
(declare (bug-range *jj*))
ERROR:The function BUG-RANGE is undefined.

And another problem:

(defgeneric do-something (n))

(defmethod do-something ((n fixnum))
  (print "It is not in the bug range."))

(defmethod do-something ((n bug-range))
  (print "It is in the bug range."))
ERROR: There is no class named BUG-RANGE.

Oh my god, so my new type cannot be used for methods?

Thanks.

From: ······@corporate-world.lisp.de
Subject: Re: Creating a new type
Date: 
Message-ID: <efc08916-8617-45f1-befc-29a3e0981b0b@y29g2000hsf.googlegroups.com>
On Oct 21, 4:19 pm, Javier <·······@gmail.com> wrote:
> Ok, I want to create a new numerical type (like a set) for example:
>
> type BUG_RANGE is range -13..34;
>
> Ok, in Lisp, defining the type is a little dificult but possible:

It is easy and possible:

(deftype bug-range () '(integer -13 34))

>
> (defun is-bug-range (a)
>   (and (typep a 'fixnum)
>        (>= a -13)
>        (<= a 34)))
>
> (deftype bug-range ()
>   `(satisfies is-bug-range))
>
> CL-USER> (typep 8 'bug-range)
> T
> CL-USER> (typep 89 'bug-range)
> NIL
>
> (defun check-it ()
>   (let ((c 4))
>     (declare (bug-range c))
>     (setf c 89))) ; error, c does not satiesfies is-bug-range, which
> is correct
>
> The problem is:
>
> CL-USER> (type-of 8)
> (INTEGER 0 536870911)
>
> I want the response from type-of to be BUG-RANGE. That is, when the
> number is in the range of -13 and 34, I want the system to say that
> the number is BUG-RANGE by default. Is it possible?

Not that I know.

> Another thing I want is to declare the type of a special variable, for
> example, to declare it BUG-RANGE, but don't know exactly how, SBCL
> produces an error when using DECLARE in the REPL:
>
> (defparameter *jj* 8)
> (declare (bug-range *jj*))
> ERROR:The function BUG-RANGE is undefined.

See DECLAIM and PROCLAIM.

>
> And another problem:
>
> (defgeneric do-something (n))
>
> (defmethod do-something ((n fixnum))
>   (print "It is not in the bug range."))
>
> (defmethod do-something ((n bug-range))
>   (print "It is in the bug range."))
> ERROR: There is no class named BUG-RANGE.
>
> Oh my god, so my new type cannot be used for methods?

Correct. User defined types have no corresponding classes. Dispatch
is only possible over classes and individual objects. Not types.
Common Lisp has for some types corresponding classes.
STRING for example is also the name for a class:
CL-USER 22 > (find-class 'string)
#<BUILT-IN-CLASS STRING 40F0334C83>

BUG-RANGE is not a class:

CL-USER 23 > (deftype bug-range () '(integer -13 34))
BUG-RANGE

CL-USER 24 > (find-class 'bug-range)

Error: BUG-RANGE is not the name of a class
  1 (continue) Try finding the class BUG-RANGE again
  2 (abort) Return to level 0.
  3 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other
options

CL-USER 25 : 1 >


>
> Thanks.
From: Javier
Subject: Re: Creating a new type
Date: 
Message-ID: <81053aa8-acb7-41e6-a312-3b0452a1f14d@l42g2000hsc.googlegroups.com>
On 21 oct, 16:36, ·······@corporate-world.lisp.de" <······@corporate-
world.lisp.de> wrote:
> On Oct 21, 4:19 pm, Javier <·······@gmail.com> wrote:
>
> > Ok, I want to create a new numerical type (like a set) for example:
>
> > type BUG_RANGE is range -13..34;
>
> > Ok, in Lisp, defining the type is a little dificult but possible:
>
> It is easy and possible:
>
> (deftype bug-range () '(integer -13 34))

Oh my god... :)

> Correct. User defined types have no corresponding classes. Dispatch
> is only possible over classes and individual objects. Not types.
> Common Lisp has for some types corresponding classes.
> STRING for example is also the name for a class:
> CL-USER 22 > (find-class 'string)
> #<BUILT-IN-CLASS STRING 40F0334C83>
>
> BUG-RANGE is not a class:
>
> CL-USER 23 > (deftype bug-range () '(integer -13 34))
> BUG-RANGE
>
> CL-USER 24 > (find-class 'bug-range)
>
> Error: BUG-RANGE is not the name of a class
>   1 (continue) Try finding the class BUG-RANGE again
>   2 (abort) Return to level 0.
>   3 Return to top loop level 0.
>
> Type :b for backtrace, :c <option number> to proceed,  or :? for other
> options
>
> CL-USER 25 : 1 >

So, how can I define a compatible class for bug-range?

Thank you!
From: Thomas A. Russ
Subject: Re: Creating a new type
Date: 
Message-ID: <ymiabcxe8ch.fsf@blackcat.isi.edu>
Javier <·······@gmail.com> writes:

> So, how can I define a compatible class for bug-range?

You can't.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Barry Margolin
Subject: Re: Creating a new type
Date: 
Message-ID: <barmar-E31654.23485321102008@mara100-84.onlink.net>
In article <···············@blackcat.isi.edu>,
 ···@sevak.isi.edu (Thomas A. Russ) wrote:

> Javier <·······@gmail.com> writes:
> 
> > So, how can I define a compatible class for bug-range?
> 
> You can't.

And there's a decent reason for it.

Suppose you had classes for (integer 0 10) and (integer 5 15), and 
methods of a generic function specialized on each of them.  Then you 
called the GF with the argument 8 -- which one should it run?  There's 
no obvious way to specify the class precedence list for such general 
types.

When you define classes with DEFCLASS you're forced to specify the 
hierarchical relationships.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Tomas Zellerin
Subject: Re: Creating a new type
Date: 
Message-ID: <80cd768c-142d-4dcc-8682-20def84074ec@y21g2000hsf.googlegroups.com>
> In article <···············@blackcat.isi.edu>,
>  ····@sevak.isi.edu (Thomas A. Russ) wrote:
>
> > Javier <·······@gmail.com> writes:
>
> > > So, how can I define a compatible class for bug-range?
>
> > You can't.
>
Actually, I think you can do it in using MOP (not part of Common Lisp,
but a de-facto standard in most implementations. And not so easily).
Define new class for ranged specializers, new class for generic
functions that accept them, and - the trickier part - define method on
compute-applicable method (-using classes) so that it sorts applicable
functions in the way you like. Now all you need is some syntactic
sugar to define methods on ranges in a nice way. I dont think this is
the way to do it for you, but might be nice exercise for MOP.

Other way - possibly easier for this task - is to create a class bug-
range with one slot containing value, and wrap all your numbers that
should be bug-ranges into this class. Depeneding on your code it might
be even easy and make the code more readable and less error-prone.

And of course, the easiest way is to dispatch on integer (note that
fixnum is not required to be a class, and in clisp you would not be
able to dispatch on it) and check type inside.
From: Javier
Subject: Re: Creating a new type
Date: 
Message-ID: <5af73d1c-71a3-4f8c-8a1f-7a4d74f298ee@m74g2000hsh.googlegroups.com>
On 22 oct, 10:44, Tomas Zellerin <········@gmail.com> wrote:
> > In article <···············@blackcat.isi.edu>,
> >  ····@sevak.isi.edu (Thomas A. Russ) wrote:
>
> > > Javier <·······@gmail.com> writes:
>
> > > > So, how can I define a compatible class for bug-range?
>
> > > You can't.
>
> Actually, I think you can do it in using MOP (not part of Common Lisp,
> but a de-facto standard in most implementations. And not so easily).
> Define new class for ranged specializers, new class for generic
> functions that accept them, and - the trickier part - define method on
> compute-applicable method (-using classes) so that it sorts applicable
> functions in the way you like. Now all you need is some syntactic
> sugar to define methods on ranges in a nice way. I dont think this is
> the way to do it for you, but might be nice exercise for MOP.


Nice, if I define a new class derived from INTEGER, for example:

(defclass example (integer)
  ())

I get this error:

The class #<BUILT-IN-CLASS INTEGER> was specified as a
super-class of the class #<STANDARD-CLASS EXAMPLE>, but the
meta-classes #<STANDARD-CLASS BUILT-IN-CLASS> and
#<STANDARD-CLASS STANDARD-CLASS> are incompatible.  Define a
method for SB-MOP:VALIDATE-SUPERCLASS to avoid this error.
   [Condition of type SIMPLE-ERROR]


So this indicates that it might be still possible, as you say.
How do I define a method for SB-MOP:VALIDATE-SUPERCLASS? May this be
compatible with any compiler supporting MOP?
From: Matthias Benkard
Subject: Re: Creating a new type
Date: 
Message-ID: <1865f8ed-8bd7-4c2a-a69a-b7288079cec6@79g2000hsk.googlegroups.com>
On 22 Okt., 13:09, Javier <·······@gmail.com> wrote:
> Nice, if I define a new class derived from INTEGER, for example:
>
> (defclass example (integer)
>   ())
>
> ...
>
> So this indicates that it might be still possible, as you say.
> How do I define a method for SB-MOP:VALIDATE-SUPERCLASS? May this be
> compatible with any compiler supporting MOP?

Don't do that.  CLOS is a class-based (!) object system with multiple
dispatch, not a pattern matcher.  If you want pattern matching (or
other, more weird kinds of dispatch), there are a couple of options
available.  Non-MOPped CLOS isn't one of them.

(That said, you might be able to make a pattern matcher (or something
more general) out of CLOS via the MOP.  Would it be fruitful?  I don't
know.)

Matthias
From: Pascal Costanza
Subject: Re: Creating a new type
Date: 
Message-ID: <6mbkoqFg0e8hU1@mid.individual.net>
Tomas Zellerin wrote:
>> In article <···············@blackcat.isi.edu>,
>>  ····@sevak.isi.edu (Thomas A. Russ) wrote:
>>
>>> Javier <·······@gmail.com> writes:
>>>> So, how can I define a compatible class for bug-range?
>>> You can't.
> Actually, I think you can do it in using MOP (not part of Common Lisp,
> but a de-facto standard in most implementations. And not so easily).

See http://lisp-ecoop07.bknr.net/submission/13504.html and 
http://lisp-ecoop07.bknr.net/submission/13487.html and 
http://p-cos.net/documents/filtered-dispatch.pdf for some ideas.


Pascal

-- 
Lisp50: http://www.lisp50.org

My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Javier
Subject: Re: Creating a new type
Date: 
Message-ID: <59c0448d-0db4-416f-a537-a57861df90cc@s50g2000hsb.googlegroups.com>
On 22 oct, 05:48, Barry Margolin <······@alum.mit.edu> wrote:
> In article <···············@blackcat.isi.edu>,
>  ····@sevak.isi.edu (Thomas A. Russ) wrote:
>
> > Javier <·······@gmail.com> writes:
>
> > > So, how can I define a compatible class for bug-range?
>
> > You can't.
>
> And there's a decent reason for it.
>
> Suppose you had classes for (integer 0 10) and (integer 5 15), and
> methods of a generic function specialized on each of them.  Then you
> called the GF with the argument 8 -- which one should it run?  There's
> no obvious way to specify the class precedence list for such general
> types.
>
> When you define classes with DEFCLASS you're forced to specify the
> hierarchical relationships.

Well, there is a way: the last defining one may take precedence, for
example.
This is a similar conflict as it happens with multiple inheritance,
there must be some rules. Just define the rules, and it should be
possible.

Anyway, I'm disappointed. I thought that CLOS was conceived to
consider everything as manageable objects. Now I see that there are
exceptions.
From: Kenny
Subject: Re: Creating a new type
Date: 
Message-ID: <48ff385e$0$5647$607ed4bc@cv.net>
Javier wrote:
> On 22 oct, 05:48, Barry Margolin <······@alum.mit.edu> wrote:
> 
>>In article <···············@blackcat.isi.edu>,
>> ····@sevak.isi.edu (Thomas A. Russ) wrote:
>>
>>
>>>Javier <·······@gmail.com> writes:
>>
>>>>So, how can I define a compatible class for bug-range?
>>
>>>You can't.
>>
>>And there's a decent reason for it.
>>
>>Suppose you had classes for (integer 0 10) and (integer 5 15), and
>>methods of a generic function specialized on each of them.  Then you
>>called the GF with the argument 8 -- which one should it run?  There's
>>no obvious way to specify the class precedence list for such general
>>types.
>>
>>When you define classes with DEFCLASS you're forced to specify the
>>hierarchical relationships.
> 
> 
> Well, there is a way: the last defining one may take precedence, for
> example.

That would be fun. Every time I recompile the precedence will change, 
exp. when I am debugging the precedence and going back and forth between 
two source files modifying debug print statements.

ie, define "last".

> This is a similar conflict as it happens with multiple inheritance,
> there must be some rules. Just define the rules, and it should be
> possible.
> 
> Anyway, I'm disappointed. I thought that CLOS was conceived to
> consider everything as manageable objects. Now I see that there are
> exceptions.

Yeah, forget CLOS. Too un-Lispy. I use RDF now.

hth, kenny
From: Javier
Subject: Re: Creating a new type
Date: 
Message-ID: <gdnjf7$t5l$1@aioe.org>
Kenny wrote:

> Yeah, forget CLOS. Too un-Lispy. I use RDF now.

What is RDF?
From: Kenny
Subject: Re: Creating a new type
Date: 
Message-ID: <48ff5ede$0$5661$607ed4bc@cv.net>
Javier wrote:
> Kenny wrote:
> 
> 
>>Yeah, forget CLOS. Too un-Lispy. I use RDF now.
> 
> 
> What is RDF?

http://en.wikipedia.org/wiki/Triple_Store

The Lispy data store. They talk about persistent stores, but my dream is 
  a dynamic RDF. CLOS is too tailwagdoggy.

hth,kzo
From: Javier
Subject: Re: Creating a new type
Date: 
Message-ID: <gdnnbb$bvd$1@aioe.org>
Kenny wrote:

>> What is RDF?
> 
> http://en.wikipedia.org/wiki/Triple_Store
> 
> The Lispy data store. They talk about persistent stores, but my dream is
>   a dynamic RDF. CLOS is too tailwagdoggy.

- And how do you use that?
- Is there any implementation?
From: Kenny
Subject: Re: Creating a new type
Date: 
Message-ID: <48ff658e$0$4895$607ed4bc@cv.net>
Javier wrote:
> Kenny wrote:
> 
> 
>>>What is RDF?
>>
>>http://en.wikipedia.org/wiki/Triple_Store
>>
>>The Lispy data store. They talk about persistent stores, but my dream is
>>  a dynamic RDF. CLOS is too tailwagdoggy.
> 
> 
> - And how do you use that?
> - Is there any implementation?
> 

No, it is just a gleam in my eye. With a good btree hack something could 
be rolled in a week, I should think.

If you meant persistent, I hear Redmond works good and you can always 
get the ACL trial and use AG, you just gotta keep your datasets under a 
kabillion or something.

Right now I have to concentrate on promoting the Algebra thing, not 
tools, tho if I do decide to go Web2 with that I'll need to do Xello, 
aka AJAX with Cells Inside(tm).

kt
From: Javier
Subject: Re: Creating a new type
Date: 
Message-ID: <gdnp2o$iuc$1@aioe.org>
Kenny wrote:

> Javier wrote:
>> Kenny wrote:
>> 
>> 
>>>>What is RDF?
>>>
>>>http://en.wikipedia.org/wiki/Triple_Store
>>>
>>>The Lispy data store. They talk about persistent stores, but my dream is
>>>  a dynamic RDF. CLOS is too tailwagdoggy.
>> 
>> 
>> - And how do you use that?
>> - Is there any implementation?
>> 
> 
> No, it is just a gleam in my eye. With a good btree hack something could
> be rolled in a week, I should think.
> 
> If you meant persistent, I hear Redmond works good and you can always
> get the ACL trial and use AG, you just gotta keep your datasets under a
> kabillion or something.
> 
> Right now I have to concentrate on promoting the Algebra thing, not
> tools, tho if I do decide to go Web2 with that I'll need to do Xello,
> aka AJAX with Cells Inside(tm).
> 
> kt


I'm a free-software-man, but thank you anyway.
From: Kenny
Subject: Re: Creating a new type
Date: 
Message-ID: <48ff6a14$0$4986$607ed4bc@cv.net>
Javier wrote:
> Kenny wrote:
> 
> 
>>Javier wrote:
>>
>>>Kenny wrote:
>>>
>>>
>>>
>>>>>What is RDF?
>>>>
>>>>http://en.wikipedia.org/wiki/Triple_Store
>>>>
>>>>The Lispy data store. They talk about persistent stores, but my dream is
>>>> a dynamic RDF. CLOS is too tailwagdoggy.
>>>
>>>
>>>- And how do you use that?
>>>- Is there any implementation?
>>>
>>
>>No, it is just a gleam in my eye. With a good btree hack something could
>>be rolled in a week, I should think.
>>
>>If you meant persistent, I hear Redmond works good and you can always
>>get the ACL trial and use AG, you just gotta keep your datasets under a
>>kabillion or something.
>>
>>Right now I have to concentrate on promoting the Algebra thing, not
>>tools, tho if I do decide to go Web2 with that I'll need to do Xello,
>>aka AJAX with Cells Inside(tm).
>>
>>kt
> 
> 
> 
> I'm a free-software-man, but thank you anyway.
> 

You missed the open option, perhaps because I blew the name: /Redland/ 
is the open RDF I have heard works well. Of course you'll have to do 
your own bindings and it won't be as slick as AG but the important thing 
is that you'll go to FSF heaven, IIUC.

hth,kzo
From: Javier
Subject: Re: Creating a new type
Date: 
Message-ID: <gdnqms$p7b$1@aioe.org>
Kenny wrote:

>> I'm a free-software-man, but thank you anyway.
>> 
> 
> You missed the open option, perhaps because I blew the name: /Redland/
> is the open RDF I have heard works well. Of course you'll have to do
> your own bindings and it won't be as slick as AG but the important thing
> is that you'll go to FSF heaven, IIUC.

The problem I see is that it is a database, not really an object system.
From: Kenny
Subject: Re: Creating a new type
Date: 
Message-ID: <4900186c$0$4902$607ed4bc@cv.net>
Javier wrote:
> Kenny wrote:
> 
> 
>>>I'm a free-software-man, but thank you anyway.
>>>
>>
>>You missed the open option, perhaps because I blew the name: /Redland/
>>is the open RDF I have heard works well. Of course you'll have to do
>>your own bindings and it won't be as slick as AG but the important thing
>>is that you'll go to FSF heaven, IIUC.
> 
> 
> The problem I see is that it is a database, not really an object system.

Oh, I missed which option you missed because you said free was an issue 
and the option I missed you missed was to write the damn thing yourself 
in which case there would not be a licensing issue so it cannot be that 
unless the problem is that you will write it yourself but not license it 
to yourself with an acceptable license in which case believe me, I 
understand, I wouldn't either.

hth, kzo

ps. it's cool because rdf is a superset of relational as well as oo so 
one cannot go wrong. h,k
From: Barry Margolin
Subject: Re: Creating a new type
Date: 
Message-ID: <barmar-1C7AE8.23561622102008@mara100-84.onlink.net>
In article 
<····································@s50g2000hsb.googlegroups.com>,
 Javier <·······@gmail.com> wrote:

> On 22 oct, 05:48, Barry Margolin <······@alum.mit.edu> wrote:
> > In article <···············@blackcat.isi.edu>,
> > ·····@sevak.isi.edu (Thomas A. Russ) wrote:
> >
> > > Javier <·······@gmail.com> writes:
> >
> > > > So, how can I define a compatible class for bug-range?
> >
> > > You can't.
> >
> > And there's a decent reason for it.
> >
> > Suppose you had classes for (integer 0 10) and (integer 5 15), and
> > methods of a generic function specialized on each of them. �Then you
> > called the GF with the argument 8 -- which one should it run? �There's
> > no obvious way to specify the class precedence list for such general
> > types.
> >
> > When you define classes with DEFCLASS you're forced to specify the
> > hierarchical relationships.
> 
> Well, there is a way: the last defining one may take precedence, for
> example.
> This is a similar conflict as it happens with multiple inheritance,
> there must be some rules. Just define the rules, and it should be
> possible.

With multiple inheritence, the programmer states the precedence 
explicitly, by ordering the parent classes in the superclass list.

(defclass sub (super1 super2) ...)

says that super1 takes precedence, while

(defclass sub (super2 super1) ...)

says that super2 takes precedence.

Sure, we could come up with arbitrary rules for the 
automatically-generated classes, but would they make sense or be useful?

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Alex Mizrahi
Subject: Re: Creating a new type
Date: 
Message-ID: <49005b75$0$90265$14726298@news.sunsite.dk>
 J> Anyway, I'm disappointed. I thought that CLOS was conceived to
 J> consider everything as manageable objects. Now I see that there are
 J> exceptions.

CLOS is more like add-on to Lisp -- it can be implemented almost entirely
on "user level" without interferencing with other stuff. so it only treats 
it's own
objects with first class, support for primitive types is sub-prime. and 
actually
that's just fine from practical point of view -- this was it is more honest 
and
there is less room for over-engineering. 
From: Marco Antoniotti
Subject: Re: Creating a new type
Date: 
Message-ID: <082e1087-658d-4ea1-9416-a9d6398ebe08@v28g2000hsv.googlegroups.com>
On Oct 22, 5:48 am, Barry Margolin <······@alum.mit.edu> wrote:
> In article <···············@blackcat.isi.edu>,
>  ····@sevak.isi.edu (Thomas A. Russ) wrote:
>
> > Javier <·······@gmail.com> writes:
>
> > > So, how can I define a compatible class for bug-range?
>
> > You can't.
>
> And there's a decent reason for it.
>
> Suppose you had classes for (integer 0 10) and (integer 5 15), and
> methods of a generic function specialized on each of them.  Then you
> called the GF with the argument 8 -- which one should it run?  There's
> no obvious way to specify the class precedence list for such general
> types.

But then again, suppose you have classes for (INTEGER 0 42) and for
(INTEGER 1024 *).  In this case it is clear which should run.

Not that I am saying that it is easy to set it up, but for the case of
disjoint sets, it should be possible.  There was some discussion on
the CLOSER mailing list some time ago, and Christophe had a paper
along this lines at the ELS08 in Bordeaux.

Cheers
--
Marco
From: Barry Margolin
Subject: Re: Creating a new type
Date: 
Message-ID: <barmar-8A9860.23531922102008@mara100-84.onlink.net>
In article 
<····································@v28g2000hsv.googlegroups.com>,
 Marco Antoniotti <·······@gmail.com> wrote:

> On Oct 22, 5:48�am, Barry Margolin <······@alum.mit.edu> wrote:
> > In article <···············@blackcat.isi.edu>,
> > ·····@sevak.isi.edu (Thomas A. Russ) wrote:
> >
> > > Javier <·······@gmail.com> writes:
> >
> > > > So, how can I define a compatible class for bug-range?
> >
> > > You can't.
> >
> > And there's a decent reason for it.
> >
> > Suppose you had classes for (integer 0 10) and (integer 5 15), and
> > methods of a generic function specialized on each of them. �Then you
> > called the GF with the argument 8 -- which one should it run? �There's
> > no obvious way to specify the class precedence list for such general
> > types.
> 
> But then again, suppose you have classes for (INTEGER 0 42) and for
> (INTEGER 1024 *).  In this case it is clear which should run.
> 
> Not that I am saying that it is easy to set it up, but for the case of
> disjoint sets, it should be possible.  There was some discussion on
> the CLOSER mailing list some time ago, and Christophe had a paper
> along this lines at the ELS08 in Bordeaux.

You don't really need an OO system to deal with disjoint types.  Most of 
the fancy stuff that CLOS (and other OO systems) does is to deal with a 
hierarchical class system.

Furthermore, there are many overlaps that ARE feasible, e.g. (integer 0 
10) and (integer 5 7).  And things get more complicated when you start 
dealing with compound types like arrays and lists.

Maybe it's possible to define an OO system that works with all these 
types of classes, but the rules would get extremely complex.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Marco Antoniotti
Subject: Re: Creating a new type
Date: 
Message-ID: <eaf6deb1-c8a2-4362-9e01-88397926fdb1@s50g2000hsb.googlegroups.com>
On Oct 23, 5:53 am, Barry Margolin <······@alum.mit.edu> wrote:
> In article
> <····································@v28g2000hsv.googlegroups.com>,
>  Marco Antoniotti <·······@gmail.com> wrote:
>
>
>
> > On Oct 22, 5:48 am, Barry Margolin <······@alum.mit.edu> wrote:
> > > In article <···············@blackcat.isi.edu>,
> > >  ····@sevak.isi.edu (Thomas A. Russ) wrote:
>
> > > > Javier <·······@gmail.com> writes:
>
> > > > > So, how can I define a compatible class for bug-range?
>
> > > > You can't.
>
> > > And there's a decent reason for it.
>
> > > Suppose you had classes for (integer 0 10) and (integer 5 15), and
> > > methods of a generic function specialized on each of them.  Then you
> > > called the GF with the argument 8 -- which one should it run?  There's
> > > no obvious way to specify the class precedence list for such general
> > > types.
>
> > But then again, suppose you have classes for (INTEGER 0 42) and for
> > (INTEGER 1024 *).  In this case it is clear which should run.
>
> > Not that I am saying that it is easy to set it up, but for the case of
> > disjoint sets, it should be possible.  There was some discussion on
> > the CLOSER mailing list some time ago, and Christophe had a paper
> > along this lines at the ELS08 in Bordeaux.
>
> You don't really need an OO system to deal with disjoint types.  Most of
> the fancy stuff that CLOS (and other OO systems) does is to deal with a
> hierarchical class system.
>
> Furthermore, there are many overlaps that ARE feasible, e.g. (integer 0
> 10) and (integer 5 7).  And things get more complicated when you start
> dealing with compound types like arrays and lists.
>
> Maybe it's possible to define an OO system that works with all these
> types of classes, but the rules would get extremely complex.

I am not saying that it would be easy, but it would definitively be an
interesting thing to look at.  A class can be seen as a representative
of a set (give or take), so, in principle, talking about methods
specialized on *disjoint* subsets should be feasible.

Cheers
--
Marco
From: Thomas A. Russ
Subject: Re: Creating a new type
Date: 
Message-ID: <ymi1vy7dynd.fsf@blackcat.isi.edu>
Marco Antoniotti <·······@gmail.com> writes:

> On Oct 22, 5:48�am, Barry Margolin <······@alum.mit.edu> wrote:
> > In article <···············@blackcat.isi.edu>,
> >
> > Suppose you had classes for (integer 0 10) and (integer 5 15), and
> > methods of a generic function specialized on each of them. �Then you
> > called the GF with the argument 8 -- which one should it run? �There's
> > no obvious way to specify the class precedence list for such general
> > types.
> 
> But then again, suppose you have classes for (INTEGER 0 42) and for
> (INTEGER 1024 *).  In this case it is clear which should run.
> 
> Not that I am saying that it is easy to set it up, but for the case of
> disjoint sets, it should be possible.  There was some discussion on
> the CLOSER mailing list some time ago, and Christophe had a paper
> along this lines at the ELS08 in Bordeaux.

Well, our Loom knowledge representation language had the ability to
define methods that dispatched on description logic class definitions.
This allowed a flexibility that was sufficient for defining such
ranges.  Choosing the methods to execute was controlled by the lattice
of class definitions as well as a set of filtering techniques to apply
to the set of candidate  methods.

As Barry notes above when you allow this, you don't necessarily have an
unambiguous most specific method.  This is unlike CLOS, which has the
most specific method clearly defined.  Loom addressed this by computing
two sets.  One of all applicable methods and a second one which had just
the most specific methods.  And then there was the choice of which
methods to actually execute.  The actual method to invoke was determined
by the combination of various filters.  More than one filter could be
applied:

 :overrides filter eliminates methods which have been explicitly
            declared less preferable than some other candidate method.
 :most-specific filter eliminates any method whose situation pattern is
            specialized by some other candidate method's pattern.
 :last-one filter selects the most-recently defined of the surviving
            candidate methods.  [Just for Kenny!]
 :select-one performs a pseudo-random selection of one of the candidate
            methods.
 :select-all filter passes all of the surviving methods.
 :warning filter passes a single surviving candidate method, or lists
            the surviving methods and warns that it cannot choose among
            them. 
 :error filter passes a single surviving candidate method, or lists the
            surviving methods and breaks. 

If a list of methods was returned, then they would all be invoked, in
some arbitrary order.

http://www.isi.edu/isd/LOOM

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Thomas A. Russ
Subject: Re: Creating a new type
Date: 
Message-ID: <ymi63nle8av.fsf@blackcat.isi.edu>
Javier <·······@gmail.com> writes:

> So, how can I define a compatible class for bug-range?

OK.  You can't in Common Lisp.
You could in Loom, though:  http://www.isi.edu/isd/LOOM/

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Kenny
Subject: Re: Creating a new type
Date: 
Message-ID: <48fe6646$0$5662$607ed4bc@cv.net>
Javier wrote:
> On 21 oct, 16:36, ·······@corporate-world.lisp.de" <······@corporate-
> world.lisp.de> wrote:
> 
>>On Oct 21, 4:19 pm, Javier <·······@gmail.com> wrote:
>>
>>
>>>Ok, I want to create a new numerical type (like a set) for example:
>>
>>>type BUG_RANGE is range -13..34;
>>
>>>Ok, in Lisp, defining the type is a little dificult but possible:
>>
>>It is easy and possible:
>>
>>(deftype bug-range () '(integer -13 34))
> 
> 
> Oh my god... :)

You rang?

(defun gettysburgh? (x)
   (not (null
         (search x "Four score and seven years ago our parents brought 
forth on this continent"
           :test 'string-equal))))

(deftype gettysburgh ()
   `(satisfies gettysburgh?))

(typep "seven" 'gettysburgh) -> t
(typep "eight" 'gettysburgh) -> nil

Left as an exercise:

    (typep "rs ago" 'gettysburgh) -> t

> So, how can I define a compatible class for bug-range?
> 

Where is Costanza when we need him?!

hth,kzo
From: Alberto Riva
Subject: Re: Creating a new type
Date: 
Message-ID: <gdm1cv$dc0a$1@usenet.osg.ufl.edu>
Kenny wrote:
> 
> Where is Costanza when we need him?!

Probably still at OOPSLA. By the way, you didn't show up in the end, we 
missed you... ;)

Alberto
From: Kenny
Subject: Re: Creating a new type
Date: 
Message-ID: <48fe8e93$0$4892$607ed4bc@cv.net>
Alberto Riva wrote:
> Kenny wrote:
> 
>>
>> Where is Costanza when we need him?!
> 
> 
> Probably still at OOPSLA. By the way, you didn't show up in the end, we 
> missed you... ;)

How is/was/will it? I woulda loved to go but just pegged these days.


kt
From: Alberto Riva
Subject: Re: Creating a new type
Date: 
Message-ID: <gdm3so$8o4u$1@usenet.osg.ufl.edu>
Kenny wrote:
> Alberto Riva wrote:
>> Kenny wrote:
>>
>>>
>>> Where is Costanza when we need him?!
>>
>>
>> Probably still at OOPSLA. By the way, you didn't show up in the end, 
>> we missed you... ;)
> 
> How is/was/will it? I woulda loved to go but just pegged these days.

Well, I had to leave early so I missed the final part of the day, but 
I'm still glad I managed to go. I think most of the people who were 
there are still traveling, I haven't seen any report here or in blogs so 
far. But if you start a new thread with your question, we'll all 
contribute...

I hope they put the videos on the talks on the website soon, anyway.

Alberto
From: ·············@gmail.com
Subject: Re: Creating a new type
Date: 
Message-ID: <9b9ab06f-276e-44bc-bff9-a6b0cfb0a559@2g2000hsn.googlegroups.com>
On Oct 21, 10:19 am, Javier <·······@gmail.com> wrote:
> Ok, I want to create a new numerical type (like a set) for example:
>
> type BUG_RANGE is range -13..34;

stuff deleted ...

> CL-USER> (type-of 8)
> (INTEGER 0 536870911)
>
> I want the response from type-of to be BUG-RANGE. That is, when the
> number is in the range of -13 and 34, I want the system to say that
> the number is BUG-RANGE by default. Is it possible?
>
I am wondering if your syntax is a problem.  Simple integers are
already reserved by lisp (I am sure I will get corrected on this) for
counting items, and incrementing and decrementing the counts.  They
are not meant to be bug identifiers : you would not want to do
(let ((bug 8))
    (+1 bug))

Hm, Actually you may, if you would want to print out a list of all the
bugs.

So, after just shooting myself in the foot, let me limp a bit more.

Maybe you can define a syntax like #G8 for bug 8 (#B8 would not work,
because #B is for binary numbers)?  I have no clue, but maybe lisp has
a machinery for those kinds of definitions, upone which you can define
tests, and simple operations (like (next-bug #G8)

Cheers,

Mirko
From: Pascal Bourguignon
Subject: Re: Creating a new type
Date: 
Message-ID: <49008ce7$0$15460$426a74cc@news.free.fr>
·············@gmail.com wrote:
> On Oct 21, 10:19 am, Javier <·······@gmail.com> wrote:
>> Ok, I want to create a new numerical type (like a set) for example:
>>
>> type BUG_RANGE is range -13..34;
> 
> stuff deleted ...
> 
>> CL-USER> (type-of 8)
>> (INTEGER 0 536870911)
>>
>> I want the response from type-of to be BUG-RANGE. That is, when the
>> number is in the range of -13 and 34, I want the system to say that
>> the number is BUG-RANGE by default. Is it possible?
>>
> I am wondering if your syntax is a problem.  Simple integers are
> already reserved by lisp (I am sure I will get corrected on this) for
> counting items, and incrementing and decrementing the counts.  They
> are not meant to be bug identifiers : you would not want to do
> (let ((bug 8))
>     (+1 bug))
> 
> Hm, Actually you may, if you would want to print out a list of all the
> bugs.
> 
> So, after just shooting myself in the foot, let me limp a bit more.
> 
> Maybe you can define a syntax like #G8 for bug 8 (#B8 would not work,
> because #B is for binary numbers)?  I have no clue, but maybe lisp has
> a machinery for those kinds of definitions, upone which you can define
> tests, and simple operations (like (next-bug #G8)

Well if you start in this dirrection, why not just write bug-8, bug-9, 
..., or better: bug-program-crashed, bug-misplaced-window, etc...

Then you can (deftype bug () (member bug-program-crashed 
bug-misplaced-window ...))

and if you need to implement methods on these bugs:

(defmethod correct ((self (eql bug-program-crashed)))
   (restart-program)

(defmethod correct ((self (eql bug-misplaced-window)))
   (nudge-window))


But of course, you still cannot define a method on a set of bugs.



-- 
__Pascal Bourguignon__
http://www.informatimago.com
From: ·············@gmail.com
Subject: Re: Creating a new type
Date: 
Message-ID: <6961ae82-7e70-4bcf-b0db-d291847e2202@l77g2000hse.googlegroups.com>
On Oct 23, 10:40 am, Pascal Bourguignon <····@informatimago.com>
wrote:
> ·············@gmail.com wrote:
> > On Oct 21, 10:19 am, Javier <·······@gmail.com> wrote:
> >> Ok, I want to create a new numerical type (like a set) for example:
>
> >> type BUG_RANGE is range -13..34;
>
> > stuff deleted ...
>
> >> CL-USER> (type-of 8)
> >> (INTEGER 0 536870911)
>
> >> I want the response from type-of to be BUG-RANGE. That is, when the
> >> number is in the range of -13 and 34, I want the system to say that
> >> the number is BUG-RANGE by default. Is it possible?
>
> > I am wondering if your syntax is a problem.  Simple integers are
> > already reserved by lisp (I am sure I will get corrected on this) for
> > counting items, and incrementing and decrementing the counts.  They
> > are not meant to be bug identifiers : you would not want to do
> > (let ((bug 8))
> >     (+1 bug))
>
> > Hm, Actually you may, if you would want to print out a list of all the
> > bugs.
>
> > So, after just shooting myself in the foot, let me limp a bit more.
>
> > Maybe you can define a syntax like #G8 for bug 8 (#B8 would not work,
> > because #B is for binary numbers)?  I have no clue, but maybe lisp has
> > a machinery for those kinds of definitions, upone which you can define
> > tests, and simple operations (like (next-bug #G8)
>
> Well if you start in this dirrection, why not just write bug-8, bug-9,
> ..., or better: bug-program-crashed, bug-misplaced-window, etc...
>
> Then you can (deftype bug () (member bug-program-crashed
> bug-misplaced-window ...))
>
> and if you need to implement methods on these bugs:
>
> (defmethod correct ((self (eql bug-program-crashed)))
>    (restart-program)
>
> (defmethod correct ((self (eql bug-misplaced-window)))
>    (nudge-window))
>
> But of course, you still cannot define a method on a set of bugs.
>
> --
> __Pascal Bourguignon__http://www.informatimago.com

I really know next to nothing on type-deriving yet, so I could be
shooting myself into the other foot, but, could one play with the
reader to catch #bug12 and interpret it and etc etc?  (& I know even
less on that topic).

I am not advocating any of these approaches, just thinking aloud.

Mirko
From: Pascal Bourguignon
Subject: Re: Creating a new type
Date: 
Message-ID: <4902fe7c$0$18785$426a34cc@news.free.fr>
·············@gmail.com wrote:
> On Oct 23, 10:40 am, Pascal Bourguignon <····@informatimago.com>
> wrote:
>> ·············@gmail.com wrote:
>>> On Oct 21, 10:19 am, Javier <·······@gmail.com> wrote:
>>>> Ok, I want to create a new numerical type (like a set) for example:
>>>> type BUG_RANGE is range -13..34;
>>> stuff deleted ...
>>>> CL-USER> (type-of 8)
>>>> (INTEGER 0 536870911)
>>>> I want the response from type-of to be BUG-RANGE. That is, when the
>>>> number is in the range of -13 and 34, I want the system to say that
>>>> the number is BUG-RANGE by default. Is it possible?
>>> I am wondering if your syntax is a problem.  Simple integers are
>>> already reserved by lisp (I am sure I will get corrected on this) for
>>> counting items, and incrementing and decrementing the counts.  They
>>> are not meant to be bug identifiers : you would not want to do
>>> (let ((bug 8))
>>>     (+1 bug))
>>> Hm, Actually you may, if you would want to print out a list of all the
>>> bugs.
>>> So, after just shooting myself in the foot, let me limp a bit more.
>>> Maybe you can define a syntax like #G8 for bug 8 (#B8 would not work,
>>> because #B is for binary numbers)?  I have no clue, but maybe lisp has
>>> a machinery for those kinds of definitions, upone which you can define
>>> tests, and simple operations (like (next-bug #G8)
>> Well if you start in this dirrection, why not just write bug-8, bug-9,
>> ..., or better: bug-program-crashed, bug-misplaced-window, etc...
>>
>> Then you can (deftype bug () (member bug-program-crashed
>> bug-misplaced-window ...))
>>
>> and if you need to implement methods on these bugs:
>>
>> (defmethod correct ((self (eql 'bug-program-crashed)))
>>    (restart-program)
>>
>> (defmethod correct ((self (eql 'bug-misplaced-window)))
>>    (nudge-window))
>>
>> But of course, you still cannot define a method on a set of bugs.
>>
>> --
>> __Pascal Bourguignon__http://www.informatimago.com
> 
> I really know next to nothing on type-deriving yet, so I could be
> shooting myself into the other foot, but, could one play with the
> reader to catch #bug12 and interpret it and etc etc?  (& I know even
> less on that topic).
> 
> I am not advocating any of these approaches, just thinking aloud.

Yes, one can write a reader macro, or a dispatching reader macro, but it 
would be rather useless if it was to map these names only to numbers or 
symbols.  You can archive the same "naming" effect by directly defining 
or using symbols.

   (defconstant +bug-program-crashed+  42)
   (defconstant +bug-misplaced-window+ 34)

   Or just use the symbols, like above.

   There little point in defining a dispatching reader macro
   to read these symbols...


Only in the case where you'd define your own data type (eg. a class), a 
reader macro could be useful.  But even then, I'd rather define a bunch 
of variables.

   (defclass bug (...) (...))
   (defvar *bug-program-crashed*  (make-instance 'bug ...))
   (defvar *bug-misplaced-window* (make-instance 'bug ...))

   You can then directly use these variables to name the bugs,

   (defmethod correct ((self (eql *bug-program-crashed*)))
     (restart-program)

   (defmethod correct ((self (eql *bug-misplaced-window*)))
      (nudge-window))

   There'd be little point in defining a dispatching reader macro
   to read these objects. In the unlikely case where you'd need to
   have these values literally, you could always use #.

     '(#.*bug-program-crashed* #.*bug-misplaced-window*)

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