clj-commons / seesaw

Seesaw turns the Horror of Swing into a friendly, well-documented, Clojure library
https://groups.google.com/group/seesaw-clj
1.48k stars 149 forks source link

Strange warning using seesaw.core/invoke-later in REPL #73

Open jannschu opened 12 years ago

jannschu commented 12 years ago

I tried this one in a fresh project (Clojure/seesaw 1.3):

lein repl:

(use 'seesaw.core) ; => nil
(invoke-later nil) ; => ArityException Wrong number of args (1) passed to: invoke$invoke-later  clojure.lang.AFn.throwArity (AFn.java:437)
(seesaw.invoke/invoke-later ni) ; => nil

Then:

(def #^{:macro true} foo #'seesaw.invoke/invoke-later) ; => #'test.core/foo
(foo nil) ; => nil

No idea what's wrong, I'm very new to Clojure. But this works:

(use '[seesaw.invoke :only (invoke-later)]) ; => nil
(invoke-later nil) ; => nil

Am I making a mistake?

jannschu commented 12 years ago

Just magically vanished. I'm really puzzled.

daveray commented 12 years ago

hmmm... I don't think you're doing anything wrong. I can't reproduce it though:

[508,0] seesaw-test $ ls lib/
clojure-1.3.0.jar    j18n-1.0.0.jar       swing-worker-1.1.jar
filters-2.0.235.jar  miglayout-3.7.4.jar  swingx-1.6.1.jar
forms-1.2.1.jar      seesaw-1.3.0.jar
[509,0] seesaw-test $ lein repl
REPL started; server listening on localhost port 21326
user=> (use 'seesaw.core)
nil
user=> (invoke-later nil)
nil
user=> 

I guess I have to ask why are you passing nil to invoke-later anyway? :)

daveray commented 12 years ago

oops. I should have refreshed the page and seen your second comment before looking into it. Let me know if you have any more issues.

naylor127 commented 12 years ago

I've had a similar issue. I put it in my core.clj file like so:

(ns seesaw-playground.core (:use seesaw.core))

(defn -main [& args](invoke-later %28-> %28frame :title "Hello", :content "Hello, Seesaw", :on-close :exit) pack! show!)))

My project.clj is:

(defproject seesaw-playground "1.0.0-SNAPSHOT" :description "FIXME: write" :dependencies [[org.clojure/clojure "1.3.0"] [seesaw "1.3.0"]] :main seesaw-playground.core)

But when I call lein run on the command-line I get:

Exception in thread "main" clojure.lang.ArityException: Wrong number of args (1) passed to: invoke$invoke-later at clojure.lang.AFn.throwArity(AFn.java:437) at clojure.lang.RestFn.invoke(RestFn.java:412) at clojure.lang.Var.invoke(Var.java:401) at seesaw_playground.core$_main.doInvoke(core.clj:6) at clojure.lang.RestFn.invoke(RestFn.java:397) at clojure.lang.Var.invoke(Var.java:397) at user$eval36.invoke(NO_SOURCE_FILE:1) at clojure.lang.Compiler.eval(Compiler.java:6465) at clojure.lang.Compiler.eval(Compiler.java:6455) at clojure.lang.Compiler.eval(Compiler.java:6431) at clojure.core$eval.invoke(core.clj:2795) at clojure.main$eval_opt.invoke(main.clj:296) at clojure.main$initialize.invoke(main.clj:315) at clojure.main$null_opt.invoke(main.clj:348) at clojure.main$main.doInvoke(main.clj:426) at clojure.lang.RestFn.invoke(RestFn.java:421) at clojure.lang.Var.invoke(Var.java:405) at clojure.lang.AFn.applyToHelper(AFn.java:163) at clojure.lang.Var.applyTo(Var.java:518) at clojure.main.main(main.java:37)

Oddly enough, the program doesn't crash, and the Hello window opens up fine.

jannschu commented 12 years ago

I noticed, that deleting the compiled files (.class) solves the problem. Some before/after results:

(var-get seesaw.core/invoke-later) => <invoke/invoke-later fn obj>

(var-get seesaw.core/invoke-later) =>
    Runtime Exception: Can't take value of a macro: #'seesaw.core/invoke-now

Steps to reproduce:

Create new project (with leiningen). Add seesaw to deps, load deps. Open lein repl and run (compile 'seesaw.core). Close REPL, open a new one:

(use 'seesaw.core)
(invoke-later) ; => warning
daveray commented 12 years ago

Give this fix a try. I honestly don't know what's going on, but switching from a def alias to a defmacro wrapper seemed to fix it.

jannschu commented 12 years ago

This works. I created a simple example showing the problem (http://pastebin.com/raw.php?i=2GFGY2NW) and tested it with Clojure 1.3.0 and Clojure 1.4.0-master-SNAPSHOT. Both are broken. Seems to be a bug.

daveray commented 12 years ago

Thanks for following up on this. Assuming you're compj on IRC, I saw you asking about it there. It would be nice if a fix ended up in 1.4.

jannschu commented 12 years ago

There is a ticket & patch: http://dev.clojure.org/jira/browse/CLJ-1021