On Sep 3, 3:42 pm, ngocdaothanh <ngocdaoth...@gmail.com> wrote:
> Hi,
>
> In Rails you can create a view like this:
>
> my_view.erb:
> <%= "hello" + @name %>
>
> I'm new to Clojure. I want to create something like the above like
> this:
>
> (defn my-view []
>   (str "hello" name))
>
> The point is:
> * name is not known when my-view is defined
> * I don't want to pass name as a argument of my-view, this is kind of
> ugly boilerplate
>
If you don't pass the name as an argument, whence does my-view get it,
then?

I suppose you could use a global binding, and do (binding [*name*
"whatever"] (my-view)), but I'm not sure that's any better than just
passing in the parameter. eg.

(def *name*)

(defn my-view []
  (str "hello " *name*))

(binding [*name* "world"]



Another option would be to pass the view functions a map of keywords
to replacements so that you can have a single data structure that's
easily applied to multiple views.

--
Jarkko
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to