0

Here is sample code

(def showscp
     ( let [ cf     (seesaw.core/frame :title "cframe")]
       (do
         (seesaw.core/config! cf :content (seesaw.core/button :id :me :text "btn" ))
         (.setSize cf 300 300)
         (seesaw.core/show! cf)
         cf
       )
     )
)

For get button, I use this

(defn find-me 
   ([frame]
         (let [ btn (seesaw.core/select frame [:#me] )  ] (do btn)
         )
   )
)

It cause error, like

Syntax error reading source at (REPL:2:1). EOF while reading, starting at line 2

(I guess :#me is problem in macro.)

why error cause, and how can I avoid error.

Is there more smart way than (keyword "#me")

Alan Thompson
  • 29,276
  • 6
  • 41
  • 48
luminol
  • 11
  • 1

3 Answers3

1

# is only special at the beginning of a token, to control how that token is parsed. It's perfectly valid as part of a variable name, or a keyword. Your code breaks if I paste it into a repl, but works if I retype it by hand. This strongly suggests to me that you've accidentally included some non-printing character, or other weird variant character, into your function.

amalloy
  • 89,153
  • 8
  • 140
  • 205
0

You can't use #, because it is a dispatch character.

# is a special character that tells the Clojure reader (the component that takes Clojure source and "reads" it as Clojure data) how to interpret the next character

akond
  • 15,865
  • 4
  • 35
  • 55
0

The pound character (aka octothorpe) is a special reader control character in Clojure, so you can't use it in a literal keyword, variable name, etc.

Your suggestion of (keyword "#me") will work, although it would probably be better to modify your code to just use the string "#me", or to eliminate the need for the pound-char altogether.

Alan Thompson
  • 29,276
  • 6
  • 41
  • 48