surprising immigrate behavior (?)

31 views
Skip to first unread message

Stuart Halloway

unread,
Oct 5, 2009, 11:11:27 AM10/5/09
to comp...@googlegroups.com
A consequence of using immigrate is that vars intended for rebinding
show up in multiple namespaces, and you have to be careful to get the
right one:

(use 'compojure)

; surprise: *errors* appear unbound!
(binding [*errors* {:foo "bar"}] ((error-class text-field) :foo))
= > [:input {:type "text", :name "foo", :id "foo"}]

; correct binding (different var!)
(binding [compojure.validation/*errors* {:foo "bar"}] ((error-class
text-field) :foo))
=> [:div.error [:input {:type "text", :name "foo", :id "foo"}]]

This is logical, given how immigrate works, but it still feels weird--
and it forces you to poke around in the "real" namespaces sometimes.

Is this a feature or a bug?

Stu

Daniel Renfer

unread,
Oct 5, 2009, 11:58:07 AM10/5/09
to comp...@googlegroups.com
This is one of the very reason that I refuse to use any immigrated
namespaces in my own application. I got sick of seeing multiple copies
of vars because I used different levels of immigration all over the
place.

Don't get me wrong. The immigration is great for the simple case where
you can just require compojure and go, but IMO, it's better to use the
real namespaces when possible.

Brian Carper

unread,
Oct 5, 2009, 5:01:15 PM10/5/09
to Compojure
On Oct 5, 8:58 am, Daniel Renfer <d...@kronkltd.net> wrote:
> Don't get me wrong. The immigration is great for the simple case where
> you can just require compojure and go, but IMO, it's better to use the
> real namespaces when possible.

I must agree... I gave up on (use 'compojure) and friends and I refer
to the namespaces explicitly everywhere. The behavior was too
unpredictable.

James Reeves

unread,
Oct 5, 2009, 7:32:21 PM10/5/09
to Compojure
On Oct 5, 11:11 am, Stuart Halloway <stuart.hallo...@gmail.com> wrote:
> This is logical, given how immigrate works, but it still feels weird--
> and it forces you to poke around in the "real" namespaces sometimes.
>
> Is this a feature or a bug?

I'm tempted to remove the immigrated namespaces altogether. They're
nice for "hello world" examples, but they can lead to unintuitive
behaviour.

- James

Vagif Verdi

unread,
Oct 8, 2009, 4:23:06 PM10/8/09
to Compojure


On Oct 5, 4:32 pm, James Reeves <weavejes...@googlemail.com> wrote:
> I'm tempted to remove the immigrated namespaces altogether. They're
> nice for "hello world" examples, but they can lead to unintuitive
> behaviour.
>

How about a macro (use-group compojure) That will add a bunch of
defined uses ?
Reply all
Reply to author
Forward
0 new messages