Re: Dylan's genes

mikel evins <[email protected]>
Newsgroups gmane.comp.lang.dylan.gwydion.devel
Message-ID <[email protected]>
On Mar 17, 2013, at 3:57 AM, Bruce Hoult <[email protected]> wrote:

> On Sun, Mar 17, 2013 at 9:45 PM, mikel evins <[email protected]> wrote:
>> I was working on the s-expression reader for OpenDylan, and I noticed something that I thought was kind of interesting.
>> 
>> I'm using chapter 2.2 of the Common Lisp Hyperspace as a general spec for it--an S-expression reader for Dylan isn't going to act exactly like Common Lisp's reader, but the basic machinery is pretty much the same.  That reader distinguishes several kinds of characters, and decides what to do next based on the kind of character and the current reader state.
>> 
>> So all of a sudden I found myself wishing for a feature from Bard, and I realized that it is essentially a generalization of a Dylan feature.
>> 
>> Dylan, of course, has singletons, which enable you to, in effect, dynamically designate a specific value as a type for dispatching purposes. That's a cool feature, and I've used it often, both when I was working in Dylan from day-to-day, and also when I've worked in Dylan's ancestor, Common Lisp. Common Lisp calls this feature "EQL specializers".
>> 
>> Some programmers new to the idea have posed the argument that it's just fluff without real utility, but I disagree. EQL specializers enable you to dismantle certain kinds of conditionals and replace them with separate method definitions. Those separate methods tend to be much smaller and simpler than the big switch, and therefore easier to think about, especially when you just need to address one or two of them. Factoring things that way also makes it possible to add new cases without touching the existing code--you can even add new cases when you don't have the sources for the existing ones. That's pretty handy.
>> 
>> The Bard feature in question is a kind of type called a "category". A category is an ad hoc type defined dynamically by a predicate called a "criterion". When you apply the criterion to a value, if it returns true then the value is an instance of the associated category; otherwise it isn't. So, as with singletons, you can dynamically designate a type for dispatching purposes, but where a singleton creates a type with a single instance (the singleton value), a criterion creates a type with an arbitrary number of instances--for example, all the odd integers, or all the whitespace characters.
>> 
>> That's what made me think of it: since the Common Lisp reader wants to choose what to do with a character based on which of several character classes it belongs to, categories naturally popped into my head. Obviously, I want to define categories for each of the different kinds of characters the reader can encounter.
>> 
>> That's not a Dylan feature, of course, and I'm not asking for it or complaining or anything. I just thought it was interesting and worth noting that categories seem like a natural development of singletons. I never noticed that before.
> 
> 
> Dylan can do type-union of singletons e.g.
> 
> define constant vowel = type-union(singleton('a'), singleton('e'),
> singleton('i'), singleton('o'), singleton('u'));
> 
> There's every a standard shorthand macro for this:
> 
> define constant vowel = one-of('a', 'e', 'i', 'o', 'u');
> 
> You can then dispatch on vowel as a specialized type.

Ooo, I forgot about type unions! I don't remember them being part of the Dylan I used lo, these many years ago. Now that you mention them, I remember reading about them in the docs, but it seems they fell out of my brain.

Thanks for putting them back; I get to do what I want, after all.

--me
_______________________________________________
hackers mailing list
[email protected]
https://lists.opendylan.org/mailman/listinfo/hackers
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.