1.2.0 permalink Arrow_down_16x16
  • (repl & options)
A repl that supports line numbers. For definitions and evaluations made
at the repl, the repl-name and line number will be reported as the
origin. Use set-repl-name and set-repl-prompt to customize the repl name
and prompt. This repl supports all of the keyword arguments documented
for clojure.main/repl with the following change and additions:

- :prompt has a new default
default: #(clojure.core/print (repl-prompt))

- :name-fmt, Name format string
default: the name-fmt of the parent repl, or "repl-%S"

- :prompt-fmt, Prompt format string
default: the prompt-fmt of the parent repl, or "%S:%L %N=> "

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/repl_ln.clj:217 top

(defn repl
  "A repl that supports line numbers. For definitions and evaluations made
  at the repl, the repl-name and line number will be reported as the
  origin. Use set-repl-name and set-repl-prompt to customize the repl name
  and prompt. This repl supports all of the keyword arguments documented
  for clojure.main/repl with the following change and additions:

       - :prompt has a new default
         default: #(clojure.core/print (repl-prompt))

       - :name-fmt, Name format string
         default: the name-fmt of the parent repl, or \"repl-%S\"

       - :prompt-fmt, Prompt format string
         default: the prompt-fmt of the parent repl, or \"%S:%L %N=> \""
  [& options]
  (let [{:keys [init need-prompt prompt flush read eval print caught
                name-fmt prompt-fmt]
         :or {init        #()
              need-prompt (if (instance? LineNumberingPushbackReader *in*)
                            #(.atLineStart *in*)
                            #(identity true))
              prompt      #(clojure.core/print (repl-prompt))
              flush       flush
              read        clojure.main/repl-read
              eval        eval
              print       prn
              caught      clojure.main/repl-caught
              name-fmt    (*info* :name-fmt)
              prompt-fmt  (*info* :prompt-fmt)}}
              (apply hash-map options)]
    (try
     (Var/pushThreadBindings
      {Compiler/SOURCE (var-get Compiler/SOURCE)
       Compiler/LINE (var-get Compiler/LINE)
       (var *info*) *info*
       (var *private*) {}})
     (update *info*
             :started (Date.)
             :serial (swap! *serial-number* inc)
             :thread (.getId (Thread/currentThread))
             :depth (inc (*info* :depth)))
     (update *private*
             :prompt prompt)
     (set-repl-name name-fmt)
     (set-repl-prompt prompt-fmt)
     (clojure.main/repl
      :init init
      :need-prompt need-prompt
      :prompt prompt-hook
      :flush flush
      :read read
      :eval eval
      :print print
      :caught caught)
     (finally
      (Var/popThreadBindings)
      (prn)))))
Vars in clojure.contrib.repl-ln/repl: defn eval flush inc let print prn read swap! repl
Used in 0 other vars

Comments top

No comments for repl. Log in to add a comment.