Unable to resolve symbol while attempting to use fn args

45 views
Skip to first unread message

Szymon Kuryło

unread,
Jun 1, 2015, 10:12:50 AM6/1/15
to clojure...@googlegroups.com
Hi,

I'm learning clojure-android using Emacs CIDER 0.8.1, neko 3.2.0.
The usual way for updating UI is evaluating the (set-content-view! (*a) (my-ui-def (*a)) using Ctrl+E, e.g.

(defactivity com.szymonkurylo.MainActivity
  :key :main
  :on-create
  (fn [this bundle]
    (keep-screen-on (*a))
    (on-ui
      (set-content-view! (*a)
                         (ui/make-ui (*a) (my-ui-def (*a)))))
    ))

Every time I use `this` instead of `(*a)` I get the following error:
Unable to resolve symbol: this in this context ...

The same error happens for example while defining :on-click callbacks, e.g.

(defn my-ui-def
  [activity]
  (concat [:linear-layout {:orientation :vertical}]
          (map (fn [i]
                 [:button {:text (str i)
                           :on-click (fn [_] (toast activity (str "clicked " i)))}])
               (range 10))))

 Unable to resolve symbol: activity in this context

Both of these snippets are slightly modified examples taken from https://github.com/clojure-android/neko/wiki/User-interface
Is this my code error, or is it some CIDER issue with evaluating macros?

Alexander Yakushev

unread,
Jun 1, 2015, 10:57:30 AM6/1/15
to clojure...@googlegroups.com, szymon...@gmail.com
This is not an error. `this` is a Activity instance for the activity you generate with `defactivity`. It comes as a first argument into all Activity methods, but you can't draw it out of thin air (by default). `*a` is a debugging macro I created exactly for this reason, it keeps references to the Activity objects, and allows to grab them in the REPL. The general workflow is you use (*a) in the REPL, and then for release you replace (*a) with `this`.

Hope this helps.

Szymon Kuryło

unread,
Jun 1, 2015, 12:59:43 PM6/1/15
to clojure...@googlegroups.com, szymon...@gmail.com
Ok, what about the second example?
This is a normal `defn` function definition, and `activity` is the function's argument. Why cannot I refer it inside its body?

Alexander Yakushev

unread,
Jun 1, 2015, 1:13:45 PM6/1/15
to clojure...@googlegroups.com, szymon...@gmail.com
Second example works for me. I thought you were trying to evaluate only the highlighted part. Are you sure you are evaluating the whole top-level expresion?

Szymon Kuryło

unread,
Jun 1, 2015, 2:08:00 PM6/1/15
to clojure...@googlegroups.com, szymon...@gmail.com
Yep, sorry, my mistake. Indeed, I was trying to evaluate the (map ...) part.
Reply all
Reply to author
Forward
0 new messages