Monday 15 July 2013

Clojure functions - returning value computed before the last statement -


I have written some tests in the closure. It is a simple example:

  ( Defn test1 [] (start-server) (run-private and hopefully "PVT-0") (stop-server))   

I have "run-private-and-recorded" I want to return the result, but after that I need to execute other functions. How can I do this in a functional way in the closure (without "construct" such as the console Using Rkshn)? Thank you.

Note: I read the question and its answers but it could not be applied in my case. Also, a comment asked for examples which were never given, so please consider it as an example ...

You can do this by using the last block.

  (try (+ 2 3) (finally (+ 6 7))   

generates a result

Exprs at any end will be evaluated for their side effects.

Another option would be to write along with typing a macro to start and stop your server when returning the right results, although this only solves the problem how you write a macro Because it either requires it to be used or finally tried to create the above.

No comments:

Post a Comment