Я хочу сделать приложение доступным в виде Clojure REPL. Т.е. что-то, что пользователь запускает с терминала и имеет полный Clojure REPL с множеством дополнительных функций, включенных в качестве функций Clojure.
Я хочу, чтобы все это находилось в автономном JAR-файле и не зависело от того, что пользователь уже установил Clojure или знает, как установить Clojure или импортировать дополнительные библиотеки. Все это должно просто быть на месте при запуске.
Есть ли простой способ сделать это? Т.е. повторно использовать существующий код REPL Clojure?
Все, что вам нужно сделать, это запустить clojure.main/repl
в своем собственном файле main.
В документации описаны имеющиеся у вас точки входа:
"Generic, reusable, read-eval-print loop. By default, reads from *in*, writes to *out*, and prints exception summaries to *err*. If you use the default :read hook, *in* must either be an instance of LineNumberingPushbackReader or duplicate its behavior of both supporting .unread and collapsing CR, LF, and CRLF into a single \\newline. Options are sequential keyword-value pairs. Available options and their defaults: - :init, function of no arguments, initialization hook called with bindings for set!-able vars in place. default: #() - :need-prompt, function of no arguments, called before each read-eval-print except the first, the user will be prompted if it returns true. default: (if (instance? LineNumberingPushbackReader *in*) #(.atLineStart *in*) #(identity true)) - :prompt, function of no arguments, prompts for more input. default: repl-prompt - :flush, function of no arguments, flushes output default: flush - :read, function of two arguments, reads from *in*: - returns its first argument to request a fresh prompt - depending on need-prompt, this may cause the repl to prompt before reading again - returns its second argument to request an exit from the repl - else returns the next object read from the input stream default: repl-read - :eval, function of one argument, returns the evaluation of its argument default: eval - :print, function of one argument, prints its argument to the output default: prn - :caught, function of one argument, a throwable, called when read, eval, or print throws an exception or error default: repl-caught"
Общие вещи здесь:
:init
: добавьте свою настройку для использования REPL. Например. use
некоторые библиотеки:prompt
: отображать "состояние", отличное от нс:print
: используйте какой-нибудь симпатичный принтерСтоит отметить, что каждая программа, которую вы создаете (например, uberjaring), которая содержит clojure.main
(например, clojure-$VERSION.jar
), может запускать REPL из этого uberjar, поэтому вы можете запускать оттуда разные main
: s.
Самореклама: Если вам нужно дополнительное вдохновение, это "модифицированные" REPL, которые я делал в прошлом: