Using a map of keywords is a good solution, but I think it is somewhat
just boilerplate code to satisfy the compiler, not to satisfy
developers (yes, human). In view we have to write (:my-var map)
everywhere. Is there a better way, something like lazy variable
binding or lazy function binding?
To repair the Ruby code, instance variable or method can be used:
def my_view
"hello #{@name}"
end
@name = "bilbo"
puts my_view
Or
def my_view
"hello #{name}"
end
def name "bilbo" end
puts my_view
Ruby does not force @name or name in my_view to exist before hand,
this is really dynamic.
Well, the idea is I want to create a web framework based on Compojure
with as less code as possible in view (may be designers would like it,
it's not normal HTML anyway). Place-holders in view should be lazy,
then when an action wants to use a view, it just has to declare a
bunch of concrete values and include the desired view, something like:
(defn my-action []
(with-variables [foo "hello", bar "world"] my-view))
The Clojure code may be incorrect, but I think you have captured the
idea.