简体   繁体   中英

How to execute clojure function with no arguments

I have a clojure function defined which takes no arguments.

example

(defn m
[]
...)

How do I execute this function in light table..

(m) or (m nil) or anyway.

using (m) and (m nil) I didn't get any output

to run a function with no arguments the call looks like this:

(m)

if you added a nil it would be calling a function with one argument, and that argument would have the value nil . If you are not seeing output, then it's because your function does not produce any output. Since you are using light table make sure the call is at the top level and not inside another function definition (recount the () s)

There are two modes for getting LightTable to perform Clojure:

  1. In an instarepl, everything you type is instantly evaluated.
  2. In a .clj file, Ctrl + Enter evaluates the current context, and Ctrl + Shift + Enter evaluates the whole file.

In either case, you see what the expression evaluates to: all clojure expressions evaluate to something (if they don't throw an exception, also shown).

So I think you're using mode (2), without evaluating the expression .

Having said that, if you type enough nonsense, LightTable may give up on it.

If I'm right, you'll soon find out how to call a function without arguments.

To run that function you first need to evaluate the function definition – hit Ctrl + Enter with the cursor on any of the lines of the function definition. Then you should be able to evaluate a line with code that calls your function, ie (m) .

When you evaluate Clojure code Light Table needs to connect to your code's Leiningen project (if you have one), it may connect to "LightTable-REPL" if there isn't one, or you can tell it to connect to the "Light Table UI" instead (if you want to play with Light Tables's code inside of LT itself).

It's also possible that your function doesn't have a return value, like if it only calls other functions (eg print ) that are intended to have side effects but not a useful return value. But even in that case you should see nil printed in your Clojure file when you evaluate the line containing your function call.

If you're still having trouble, feel free to ask for help in the Light Table Gitter room , the Google Groups group , or, if you think you've found a bug, open an issue on GitHub .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM