Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure - Evaluating returned function from higher order function

If I run a higher order function in the repl, or something that returns a function, like below, is there any way to later retrieve the returned function (the value that is returned by the repl) and evaluate it?

user> #(% 5 5)
#function[user/eval13160/fn--13161]

To explain the reason for the question, I'm playing around with http-kit, and ran the function run-server. It was only after execution that I realized that the function returns a function that is required to stop the server, and so I've been trying to figure how to use the function that was returned.

like image 908
maxorcist Avatar asked Jun 25 '26 03:06

maxorcist


1 Answers

Yep, you can access previous REPL values with *1:

user=> #(% 5 5)
#object[user$eval3$fn__4 0x487db668 "user$eval3$fn__4@487db668"]
user=> (*1 +)
10

There's also *2 and *3 for trailing values from previous evaluations, and *e for prior exceptions.

You could also def the result:

(def my-fn #(% 5 5))
(def my-fn *1) ;; or do it later
like image 179
Taylor Wood Avatar answered Jun 27 '26 03:06

Taylor Wood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!