:script — The Gateway
:script — The Gateway
Section titled “:script — The Gateway”“Explore fast. Ship when ready.”
:script is :core with the training wheels on. It’s designed for the moments when you just want to get something done — explore an idea, prototype a solution, or crunch some data. When you’re ready to ship, one command promotes your script to production-ready :core code.
What :script Gives You
Section titled “What :script Gives You”Convenience Features
Section titled “Convenience Features”- Implicit types — The compiler figures it out
- Top-level code — No
main()wrapper required - REPL — Run
janus repland type directly - Auto-imports — Common stdlib modules available by default
- Script arena allocator — No explicit memory management
The $-Family (The Killer Feature)
Section titled “The $-Family (The Killer Feature)”The $-family is what makes :script the replacement for awk, bash, Ruby, and Python. It’s inspired by awk’s $1, $NF — but with static type safety.
| Form | Meaning |
|---|---|
$_ | Current pipeline element, whole |
$1, $2, … | Positional component of the current element |
$# | Index of the current element in the stream |
$N | Number of positional components |
$_1, $_2, … | Closure arguments by position (multi-arg) |
$@ | Full closure argument tuple |
All resolved at compile time. If $5 doesn’t exist on your element type, you get a compile error — not a runtime crash.
AOT Cached Execution
Section titled “AOT Cached Execution”janus path/to/script.jans # First run: ~150ms compile + cachejanus path/to/script.jans # Second run: ~5ms (cached!)Scripts compile to native binaries on first run, then cache for instant subsequent execution. No interpreter overhead. No JIT. Just fast.
What :script Excludes
Section titled “What :script Excludes”| Excluded | Available In |
|---|---|
| Not publishable via Hinge | :core (after promotion) |
| No explicit allocator control | :core, :service |
Promotion is one command:
janus desugar script.jans > script.janWhen to Use :script
Section titled “When to Use :script”Perfect for:
- Learning Janus interactively
- Prototyping an idea in 10 minutes
- Data exploration and analysis
- One-off automation scripts
- AI agent tasks (short-lived, disposable code)
- Homework and algorithm competitions
The rule: Use :script to explore. Use :code (:core) to ship.
Code Examples
Section titled “Code Examples”Hello, World (No Boilerplate)
Section titled “Hello, World (No Boilerplate)”# Just run this - no main() neededprint("Hello from :script!")The Killer Example
Section titled “The Killer Example”This is the syntax that makes Nexus operators delete their ~/.zshrc:
<<p"access.log">> |> map($_.fields()) |> filter($5.to_int()? >= 500) |> group_by($7) |> map(($_1, $_2.len())) |> sort_by($2, desc) |> take(10) |> for_each(println)What this does:
- Stream lines from
access.log - Split each line into fields (whitespace-separated)
- Filter to status codes >= 500 (errors)
- Group by the 7th field (URL path)
- Count items per group
- Sort by count descending
- Take top 10
- Print each
Compare to the shell equivalent:
cat access.log | awk '{print $5, $7}' | grep -v '^[0-4]' | sort | uniq -c | sort -rn | head -10The Janus version is:
- Type-checked —
$5.to_int()?fails at compile time if not a number - Provenance tracked — every line knows its source file and line number
- Fused — compiles to a single loop, zero intermediate arrays
Pipeline with Regex
Section titled “Pipeline with Regex”<<p"server.log">> |> grep(r/ERROR.*connection reset/) |> map($_.split(":").1) |> unique() |> for_each(println)Working with Data
Section titled “Working with Data”# Read JSON, filter, transform, output CSVlet data := read_json("users.json") |> filter($_.age >= 18) |> map($.name) |> sort()
for name in data do println(name)endWhy This Beats the Competition
Section titled “Why This Beats the Competition”| Concern | awk | Bash | Ruby | Python | Janus :script |
|---|---|---|---|---|---|
Positional $N | ✅ | ❌ | ❌ | ❌ | ✅ |
| Pipeline operator | ❌ | ✅ | ✅ | ✅ | ✅ |
| Type-checked positions | ❌ | ❌ | ❌ | ❌ | ✅ |
| Zero-alloc fusion | ✅ | ❌ | ❌ | ❌ | ✅ |
| Sub-10ms cold start | ✅ | ✅ | ❌ | ❌ | ✅ |
| Static binary output | ❌ | ❌ | ❌ | ❌ | ✅ |
| Promotion to production | ❌ | ❌ | ❌ | ❌ | ✅ |
Next Steps
Section titled “Next Steps”- Move to :core — When you’re ready to ship
- Profile Overview — See all six profiles
- Generics & Traits — Level up your code
Explore fast. Ship with confidence.