Public Vars

Back

read-line (clj)

(source)

function

(read-line)
Reads the next line from stream that is the current value of *in* .

Examples

clojupyter/clojupyter
(ns clojupyter.kernel.handle-event.execute-test
  (:require [clojupyter.kernel.cljsrv :as srv]
            [clojupyter.kernel.core-test :as core-test]
            [clojupyter.kernel.handle-event.execute :as execute]
            [clojupyter.kernel.handle-event.shared-ops :as sh]
            [clojupyter.kernel.init :as init]
            [clojupyter.kernel.jup-channels :as jup]
            [clojupyter.log :as log]
            [clojupyter.messages :as msgs]
            [clojupyter.messages-specs :as msp]
            [clojupyter.test-shared :as ts]
            [clojure.core.async :as async]
            [clojure.spec.alpha :as s]
            [io.simplect.compose :refer [def- c C p P]]
            [io.simplect.compose.action :as a]
            [midje.sweet :as midje :refer [=> fact]]
            [nrepl.core :as nrepl :refer [code]]))

(fact
 "read-line works and is correctly ordered wrt other side-effects"
 (log/with-level :error
   (let [[ctrl-in ctrl-out shell-in shell-out io-in io-out stdin-in stdin-out]
         ,, (repeatedly 8 #(async/chan 25))
         jup (jup/make-jup ctrl-in ctrl-out shell-in shell-out io-in io-out stdin-in stdin-out)]
     (async/>!! stdin-in {:req-message ((ts/s*message-header msgs/INPUT-REPLY) (msgs/input-reply-content "input-1"))})
     (async/>!! stdin-in {:req-message ((ts/s*message-header msgs/INPUT-REPLY) (msgs/input-reply-content "input-2"))})
     (init/ensure-init-global-state!)
     (with-open [srv (srv/make-cljsrv)]
       (let [code (code (println (list 1 2 3))
                        (println (read-line))
                        (println 123)
                        (println (str "Read from stdin: " (read-line)))
                        14717)
             msg ((ts/s*message-header msgs/EXECUTE-REQUEST)
                  (merge (ts/default-execute-request-content) {:code code}))
             port :shell_port
             req {:req-message msg, :req-port port, :cljsrv srv, :jup jup}
             {:keys [leave-action]} (execute/eval-request req)
             specs (a/step-specs leave-action)]
         (.invoke leave-action)
         (= ["(1 2 3)\n" "input-1\n" "123\n" "Read from stdin: input-2\n"]
            (->> (core-test/on-outbound-channels jup)
                 (map (P dissoc :req-message))
                 (filter (C :rsp-msgtype (P = "stream")))
                 (filter (C :rsp-content :name (P = "stdout")))
                 (mapv (C :rsp-content :text))))))))
 => true)
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))

#?@(:cljs [] :default [
cc/pop-thread-bindings [:-> t/Any]
cc/load [t/Str :* :-> t/Any]
cc/read-string [t/Str :-> t/Any]
cc/read [(t/alt (t/cat (t/? java.io.Reader))
                (t/cat java.io.Reader t/Bool)
                (t/cat java.io.Reader t/Bool t/Any (t/? t/Bool)))
         :-> t/Any]
cc/read+string [(t/alt (t/cat (t/? java.io.Reader))
                       (t/cat java.io.Reader t/Bool)
                       (t/cat java.io.Reader t/Bool t/Any (t/? t/Bool)))
                :-> '[t/Any t/Str]]
cc/read-line [:-> (t/U nil t/Str)]
cc/add-classpath [(t/U t/Str java.net.URL) :-> nil]
])