Re: macros
On May 15, 11:10 pm, Seamus MacRae <smacrae...@live.ca.nospam> wrote:
Pillsy wrote:
On May 15, 7:22 pm, Seamus MacRae <smacrae...@live.ca.nospam> wrote:
[...]
On the much more frequent occasion I wanted to
add a new noun, I'd often be forced to change verbs that lived in
pre-existing namespaces, and maybe even in more than one namespace; th=
e
code for my new noun would be scattered all over the codebase AND the
namespaces within the system, rather than in exactly one place in each=
..
This, at least, is a potential problem, but in practice it's never
caused me any difficulty.
*deep sigh*
What? A mix of commonly used idioms, coding practices and tool support
allow you to avoid a potential problem when writing programs. That's a
pretty common state of affairs in software development.
Lisp development environments are quite
helpful when it comes to locating method definitions wherever they
might be.
What development environments? That curses-based museumstrosity you were
evangelizing half an hour ago? Surely ye jest?
No, Emacs + SLIME has convenient features for locating method
definitions in their source files. Just because the interface looks a
like something out of 1983 doesn't mean it doesn't work well.
There's also going to be big differences in polymorphism. With an obje=
ct
oriented system, nouns can be subtypes of other nouns, and verb behavi=
or
can be inherited, with or without modification.
Same in Common Lisp. Classes can inherit from other classes, and
generic functions dispatch on the run-time class, respecting
inheritance relationships.
Inheritance relationships recorded where?
In the class definition...? If I want to say that FOO is a subclass of
BAR, I just write
(defclass foo (bar)
;; This space for rent!.
)
[...]
With Lisp, I'd need to change the system namespace's plus verb's
dispatch table manually so that it knew about my Complex class, on the
other hand.
Not at all. The necessary modification of the generic function is
handled automatically (really, CLOS would be remarkably useless if it
weren't) when you define the new method.
You mean, the source code for a dispatch table you posted is
machine-generated, like yacc output?
No, I mean, you never see any of it. All you do is write the message
definition and compile it and you're done, since methods can be added
or changed at run-time.
[...]
I hate machine-generated code.
So do I. It's a very good thing that you don't have to use it to use
CLOS.
[...]
Your Lisp
dispatch thingies (generic functions, did you say?) must get built from
snippets scattered all over the damn place. Finding all the code that
generates those must be nigh-impossible.
You select the name of the generic function, hit Alt-., and a list
pops up listing all the methods for the generic function and their
classes. Then you click on the one you want, and you're taken to the
definition. It's really, really similar to looking up definitions in
Eclipse.
And there's no problem defining methods from one namespace on classes
from another namespace.
What about using the darn things?
You just... use them?
Let me guess, "there's no problem", by
which is meant "it is physically possible, though you'll need a few
tablets of Excedrin afterward and might want to save up a few sick days
first".
No, I mean, "there's no problem", by which is meant that I can't even
figure out what problem you might be referring to.
You need to be able to do this to add methods
for user-defined classes to built-in generic functions (like PRINT-
OBJECT or INITIALIZE-INSTANCE).
Such a pain, when Java lets you just go
public class MyWhatsit {
@Override
public String toString () {
return "I'm a MyWhatsit!";
}
}
sticking this in your own namespace and not monkeying with any other
code anywhere (either manually, or by running some sort of
code-generator), yet if a MyWhatsit is subsequently passed to e.g.
String.valueOf(Object), out pops "I'm a MyWhatsit!".
I'm really not seeing much difference between that and
(defclass my-whatsit () ())
(defmethod print-object ((object my-whatsit) stream)
(print-unreadable-object (obj stream)
(format stream "I'm a whatsit!")))
That's all you have to do. No monkeying with any other code anywhere
else. No code generation.
Neither fuss nor muss.
[...]
With Java I'd just have to define the implementations, naming them
correctly, and stick "implements Number" somewhere and away I'd go.
In Common Lisp, you'd just write the four method definitions; you
wouldn't even have to mention the "implements Number" part.
Duck-typing? Well, it beats no typing at all I suppose.
Eh, wait a minute, you'd write the four method definitions and then run
that code-generator thingy to generate the new versions of the dispatch
tables.
No, you write the four method definitions and then compile them. All
the machinery for doing the dispatch is handled by the Lisp
implementation transparently.
Cheers,
Pillsy
[...]