replete.core

Core Replete functions.

Protocols

IBufferedReader
IClosable
IInputStream
IOutputStream
IPushbackReader
IReader

Vars

*err*
*in*
eval
file-seq
find-var
init-empty-state
intern
line-seq
load-reader
load-string
ns-resolve
read
read-line
read-string
requiring-resolve
resolve
sleep
slurp
spit
with-open

Protocols

IBufferedReader

Protocol

Protocol for reading line-based content. Instances of IBufferedReader must also satisfy IReader.

-read-line
([this])
Reads the next line.

IClosable

Protocol

Protocol for closing entities.

-close
([this])
Closes this entity.

IInputStream

Protocol

Protocol for reading binary data.

-read-bytes
([this])
Returns available bytes as an array of unsigned numbers or nil if EOF.

IOutputStream

Protocol

Protocol for writing binary data.

-write-bytes
([this byte-array])
Writes byte array.

-flush-bytes
([this])
Flushes output.

IPushbackReader

Protocol

Protocol for readers that support undo. Instances of IPushbackReader must also satisfy IBufferedReader.

-unread
([this s])
Pushes a string of characters back on to the stream.

IReader

Protocol

Protocol for reading.

-read
([this])
Returns available characters as a string or nil if EOF.

Vars

*err*

A cljs.core/IWriter representing standard error for print operations.

*in*

An IReader representing standard input for read operations.

eval

([form])

Evaluates the form data structure (not text!) and returns the result.

Spec
args: (cat :form any?)
ret: any?

file-seq

([dir])

A tree seq on files

Spec
args: (cat :dir (or :string string? :file file?))

find-var

([sym])

Returns the global var named by the namespace-qualified symbol, or nil if no var with that name.

Spec
args: (cat :sym qualified-symbol?)
ret: (nilable var?)

init-empty-state

([state])

An init function for use with cljs.js/empty-state which initializes the empty state with cljs.core analysis metadata.

This is useful because Replete is built with :dump-core set to false.

Usage: (cljs.js/empty-state init-empty-state)

Spec
args: (cat :state map?)
ret: map?

intern

([ns name] [ns name val])

Finds or creates a var named by the symbol name in the namespace ns (which can be a symbol or a namespace), setting its root binding to val if supplied. The namespace must exist. The var will adopt any metadata from the name symbol. Returns the var.

Spec
args: (cat :ns (or :sym symbol? :ns #(instance? Namespace %)) :name symbol? :val (? any?))

line-seq

([rdr])

Returns the lines of text from rdr as a lazy sequence of strings. rdr must implement IBufferedReader.

Spec
args: (cat :rdr (instance? IBufferedReader %))
ret: seq?

load-reader

([rdr])

Sequentially read and evaluate the set of forms contained in the stream/file

Spec
args: (cat :reader (satisfies? IPushbackReader %))
ret: any?

load-string

([rdr])

Sequentially read and evaluate the set of forms contained in the string

Spec
args: (cat :s string?)
ret: any?

ns-resolve

([ns sym])

Returns the var to which a symbol will be resolved in the namespace, else nil.

Spec
args: (cat :ns symbol? :sym symbol?)
ret: (nilable var?)

read

([] [reader] [opts reader] [reader eof-error? eof-value])

Reads the first object from a IPushbackReader. Returns the object read. If EOF, throws if eof-error? is true. Otherwise returns sentinel. If no reader is provided, *in* will be used. Opts is a persistent map with valid keys:

:read-cond - :allow to process reader conditionals, or :preserve to keep all branches
:features - persistent set of feature keywords for reader conditionals
:eof - on eof, return value unless :eofthrow, then throw. if not specified, will throw

Spec
args: (alt :nullary (cat ) :unary (cat :reader #(satisfies? IPushbackReader %)) :binary (cat :opts map? :reader #(satisfies? IPushbackReader %)) :ternary (cat :reader #(satisfies? IPushbackReader %) :eof-error? boolean? :eof-value any?))

read-line

([])

Reads the next line from the current value of *in*

Spec
args: (cat )
ret: string?

read-string

([s] [opts s])

Reads one object from the string s. Optionally include reader options, as specified in read.

Spec
args: (alt :unary (cat :s string?) :binary (cat :opts map? :s string?))

requiring-resolve

([sym])

Resolves namespace-qualified sym per resolve. If initial resolve fails, attempts to require sym's namespace and retries.

Spec
args: (cat :sym qualified-symbol?)
ret: (nilable var?)

resolve

([sym])

Returns the var to which a symbol will be resolved in the current namespace, else nil.

Spec
args: (cat :sym symbol?)
ret: (nilable var?)

sleep

([f & opts])

Causes execution to block for the specified number of milliseconds plus the optionally specified number of nanoseconds.

millis should not be negative and nanos should be in the range 0–999999

Spec
args: (alt :unary (cat :millis #(and (integer? %) (not (neg? %)))) :binary (cat :millis #(and (integer? %) (not (neg? %))) :nanos #(and (integer? %) (<= 0 % 999999))))

slurp

([f & opts])

Opens a reader on f and reads all its contents, returning a string. See replete.io/reader for a complete list of supported arguments.

Spec
args: (cat :f (or :string string? :file file?) :opts (* any?))
ret: string?

spit

([f content & opts])

Opposite of slurp. Opens f with writer, writes content, then closes f. Options passed to replete.io/writer.

Spec
args: (cat :f (or :string string? :file file?) :content any? :opts (* any?))

with-open

([bindings & body])

Macro

bindings => [name IClosable ...]

Evaluates body in a try expression with names bound to the values of the inits, and a finally clause that calls (-close name) on each name in reverse order.