planck.core

Core Planck functions for use in scripts.

Protocols

IBufferedReader
IClosable
IInputStream
IOutputStream
IReader

Vars

*command-line-args*
*err*
*in*
*planck-version*
eval
exit
file-seq
init-empty-state
intern
line-seq
ns-resolve
read-line
read-password
resolve
slurp
spit
with-open

Protocols

IBufferedReader

Protocol

Protocol for reading line-based content.

-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.

IReader

Protocol

Protocol for reading.

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

Vars

*command-line-args*

A sequence of the supplied command line arguments, or nil if none were supplied

*err*

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

*in*

An IReader representing standard input for read operations.

*planck-version*

A string containing the version of the Planck executable.

eval

([form])

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

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

exit

([exit-value])

Causes Planck to terminate with the supplied exit-value.

Spec
args: (cat :exit-value integer?)

file-seq

([dir])

A tree seq on files

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

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 Planck 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?

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-line

([])

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

Spec
args: (cat )
ret: string?

read-password

([] [prompt])

Reads the next line from console with echoing disabled. It will print out a prompt if supplied

Spec
args: (cat :prompt (? string?))
ret: string?

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?)

slurp

([f & opts])

Opens a reader on f and reads all its contents, returning a string. See planck.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 planck.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.