Add src/jolt/config.janet exposing a build-time `mutable?` constant read from JOLT_MUTABLE at compile time (jpm build). Default is immutable. Fix correctness bug: conj on a list (Janet array) mutated the original in place. In immutable mode conj now copies first; in mutable mode it mutates. Round 1 of persistent-collections work.
15 lines
636 B
Text
15 lines
636 B
Text
# Build-time collection mode.
|
|
#
|
|
# Jolt can be built with either immutable (persistent) collections — proper
|
|
# Clojure value semantics — or fast Janet-native mutable collections.
|
|
#
|
|
# jpm build # immutable (default)
|
|
# JOLT_MUTABLE=1 jpm build # mutable
|
|
#
|
|
# This reads the environment at module-load time, so for a jpm-compiled
|
|
# executable the value is fixed when the binary is built (a true compile flag).
|
|
# `mutable?` is a constant, so the type-mode branches throughout core fold away.
|
|
(def mutable? (= "1" (os/getenv "JOLT_MUTABLE")))
|
|
|
|
# Convenience: immutable? is the default.
|
|
(def immutable? (not mutable?))
|