Possible feature: consider aliases when reading namespace-qualified keywords.

5 views
Skip to first unread message

Jason Wolfe

unread,
Jan 19, 2009, 7:29:46 PM1/19/09
to Clojure
I've been doing some OO-type Clojure programming, and have run into
the following (quite minor) annoyance:

I've defined a struct with a :class of ::Foo in namespace
my.long.namespace.foo.

In another namespace my.long.namespace.bar, I want to define a
subclass of this struct.
In this namespace, I require [...foo :as foo], so that I can refer to
multimethods like foo/method1.

However, it seems I'm still required to write
(derive ::Bar :my.long.namespace.foo/Foo)
when I'd like to write
(derive ::Bar :foo/Foo)

I'm not sure if this is even feasible, since given my limited
experience it seems that aliases for symbols are handled at resolution-
time and not read-time, and that wouldn't work for keywords. On the
other hand, this state of affairs seems to be possibly-confusing and a
perhaps-needless difference between symbols and keywords. What do
others think about this?

Thanks,
Jason

David Nolen

unread,
Jan 19, 2009, 10:49:19 PM1/19/09
to clo...@googlegroups.com
My OO example from earlier deals with this case by completely removing any need to manually derive tags.  This is done by having CLJOS keep it's own internal hierarchy (via make-hierarchy) rather than using the default one.  By modifying metadata on the vars holding structs created by defclass (using alter-meta!) and tagging instances as described in existing Clojure literature you can provide functions to shuffle away the annoyance of dealing with keywords and their namespaces entirely.

Jason Wolfe

unread,
Jan 20, 2009, 3:25:14 PM1/20/09
to Clojure
Hi David,

Thanks ... I just looked at CLJOS, and was actually just earlier
thinking about writing something similar myself. It looks very nice,
and I very well might end up using it (especially if it gets up-to-
speed with "struct"). Still, I stand by my feature request :).

I guess in the mean-time I could use symbols instead of keywords for
my class types. However, I assume that would slow things down
substantially (unless method caching would take care of this; I'll
have to check on that.)

-Jason

On Jan 19, 7:49 pm, David Nolen <dnolen.li...@gmail.com> wrote:
> My OO example from earlier deals with this case by completely removing any
> need to manually derive tags.  This is done by having CLJOS keep it's own
> internal hierarchy (via make-hierarchy) rather than using the default one.
>  By modifying metadata on the vars holding structs created by defclass
> (using alter-meta!) and tagging instances as described in existing Clojure
> literature you can provide functions to shuffle away the annoyance of
> dealing with keywords and their namespaces entirely.
>

Jason Wolfe

unread,
Jan 23, 2009, 2:10:19 PM1/23/09
to Clojure
On Jan 19, 4:29 pm, Jason Wolfe <jawo...@berkeley.edu> wrote:
> I've been doing some OO-type Clojure programming, and have run into
> the following (quite minor) annoyance:
>
> I've defined a struct with a :class of ::Foo in namespace
> my.long.namespace.foo.
>
> In another namespace my.long.namespace.bar, I want to define a
> subclass of this struct.
> In this namespace, I require [...foo :as foo], so that I can refer to
> multimethods like foo/method1.
>
> However, it seems I'm still required to write
> (derive ::Bar :my.long.namespace.foo/Foo)
> when I'd like to write
> (derive ::Bar :foo/Foo)

On IRC, "duck1123" just showed me that this is already implemented;
you just have to use the "::" form.

(derive ::Bar ::foo/Foo)

You learn something new every day...

-Jason

David Nolen

unread,
Jan 23, 2009, 4:25:54 PM1/23/09
to clo...@googlegroups.com
Nice :)
Reply all
Reply to author
Forward
0 new messages