Validates PTC-Lisp programs against Babashka/Clojure.
Provides validation to ensure:
- PTC-Lisp programs are valid Clojure syntax
- Runtime functions behave identically to Clojure equivalents
Usage
# Check if Babashka is available
PtcRunner.Lisp.ClojureValidator.available?()
# Validate syntax only (fast)
PtcRunner.Lisp.ClojureValidator.validate_syntax("(+ 1 2)")
# Execute and get result
PtcRunner.Lisp.ClojureValidator.execute("(+ 1 2)")Installation
Install Babashka with: mix ptc.install_babashka
Summary
Functions
Check if Babashka is available.
Get the path to the Babashka binary.
Compare a PTC-Lisp result with a Clojure result.
Execute source in Babashka and return the result.
Validate that source is valid Clojure syntax.
Wrap PTC-Lisp source with Clojure stubs for PTC-specific features.
Functions
@spec available?() :: boolean()
Check if Babashka is available.
Looks for bb at _build/tools/bb first, then in system PATH.
@spec bb_path() :: String.t() | nil
Get the path to the Babashka binary.
Returns nil if not found.
Compare a PTC-Lisp result with a Clojure result.
Handles normalization of types that differ between systems:
- Elixir atoms vs Clojure keywords
- Map key type differences
Returns :match if equivalent, {:mismatch, details} otherwise.
Execute source in Babashka and return the result.
Options
:timeout- Timeout in milliseconds (default: 5000):context- Context map to inject asctxbinding:memory- Memory map to inject asmemorybinding
Examples
iex> PtcRunner.Lisp.ClojureValidator.execute("(+ 1 2 3)")
{:ok, 6}
iex> PtcRunner.Lisp.ClojureValidator.execute("(filter even? [1 2 3 4])")
{:ok, [2, 4]}
Validate that source is valid Clojure syntax.
Returns :ok if valid, {:error, reason} if invalid.
Examples
iex> PtcRunner.Lisp.ClojureValidator.validate_syntax("(+ 1 2)")
:ok
iex> PtcRunner.Lisp.ClojureValidator.validate_syntax("(+ 1 2")
{:error, "Syntax error: ..."}
Wrap PTC-Lisp source with Clojure stubs for PTC-specific features.
Adds definitions for:
ctx- Context data as a mapmemory- Memory data as a map- PTC-specific functions:
where,all-of,any-of,none-of, etc.