arc-lang 0.6.2 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -130
- package/dist/ast.d.ts +30 -2
- package/dist/build.js +1 -1
- package/dist/formatter.js +15 -3
- package/dist/index.js +104 -0
- package/dist/interpreter.js +130 -17
- package/dist/lexer.d.ts +41 -37
- package/dist/lexer.js +47 -39
- package/dist/linter.js +18 -0
- package/dist/modules.js +5 -1
- package/dist/parser.d.ts +2 -0
- package/dist/parser.js +91 -11
- package/dist/repl.js +66 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -2
- package/stdlib/API_DESIGN.md +357 -0
- package/stdlib/ASYNC_DESIGN.md +815 -0
- package/stdlib/EXAMPLES.md +710 -0
- package/stdlib/MODULES.md +854 -0
- package/stdlib/README.md +64 -0
- package/stdlib/collections.arc +140 -0
- package/stdlib/crypto.arc +62 -0
- package/stdlib/csv.arc +40 -0
- package/stdlib/datetime.arc +75 -0
- package/stdlib/embed.arc +42 -0
- package/stdlib/env.arc +10 -0
- package/stdlib/error.arc +36 -0
- package/stdlib/html.arc +30 -0
- package/stdlib/http.arc +43 -0
- package/stdlib/io.arc +28 -0
- package/stdlib/json.arc +204 -0
- package/stdlib/llm.arc +193 -0
- package/stdlib/log.arc +20 -0
- package/stdlib/map.arc +72 -0
- package/stdlib/math.arc +133 -0
- package/stdlib/net.arc +17 -0
- package/stdlib/os.arc +81 -0
- package/stdlib/path.arc +11 -0
- package/stdlib/prompt.arc +49 -0
- package/stdlib/regex.arc +59 -0
- package/stdlib/result.arc +50 -0
- package/stdlib/store.arc +62 -0
- package/stdlib/strings.arc +44 -0
- package/stdlib/test.arc +61 -0
- package/stdlib/time.arc +19 -0
- package/stdlib/toml.arc +10 -0
- package/stdlib/yaml.arc +10 -0
package/README.md
CHANGED
|
@@ -1,148 +1,83 @@
|
|
|
1
|
-
# Arc ⚡
|
|
1
|
+
# Arc Compiler ⚡
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The compiler/interpreter implementation for the [Arc programming language](https://github.com/kai-builds-ai/arc-lang).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Architecture
|
|
6
6
|
|
|
7
|
-
## Quick Start
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
# Clone and install
|
|
11
|
-
git clone https://github.com/kai-builds-ai/arc-lang.git
|
|
12
|
-
cd arc-lang/compiler && npm install && cd ..
|
|
13
|
-
|
|
14
|
-
# Run an example
|
|
15
|
-
npx tsx compiler/src/index.ts run examples/hello-world.arc
|
|
16
|
-
|
|
17
|
-
# Start the REPL
|
|
18
|
-
npx tsx compiler/src/index.ts repl
|
|
19
7
|
```
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
```arc
|
|
43
|
-
# AI agent that fetches data, analyzes it, and acts
|
|
44
|
-
let [weather, news] = fetch [
|
|
45
|
-
@GET "api/weather?city=NYC",
|
|
46
|
-
@GET "api/news/top?limit=3"
|
|
47
|
-
]
|
|
48
|
-
|
|
49
|
-
let headlines = news.articles
|
|
50
|
-
|> take(3)
|
|
51
|
-
|> map(a => "• {a.title}")
|
|
52
|
-
|> join("\n")
|
|
53
|
-
|
|
54
|
-
let advice = match weather.condition {
|
|
55
|
-
"rain" | "storm" => "Bring an umbrella!",
|
|
56
|
-
"snow" => "Bundle up!",
|
|
57
|
-
_ => "Enjoy the weather!"
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
print("{advice}\n\nTop News:\n{headlines}")
|
|
8
|
+
src/
|
|
9
|
+
├── index.ts # CLI entry point
|
|
10
|
+
├── lexer.ts # Tokenizer
|
|
11
|
+
├── parser.ts # Parser → AST
|
|
12
|
+
├── ast.ts # AST node types
|
|
13
|
+
├── interpreter.ts # Tree-walking interpreter
|
|
14
|
+
├── modules.ts # Module resolver & loader
|
|
15
|
+
├── ir.ts # Intermediate representation
|
|
16
|
+
├── optimizer.ts # IR optimizer
|
|
17
|
+
├── codegen.ts # WAT code generation
|
|
18
|
+
├── codegen-js.ts # JavaScript code generation
|
|
19
|
+
├── semantic.ts # Semantic analysis
|
|
20
|
+
├── typechecker.ts # Type checker
|
|
21
|
+
├── formatter.ts # Code formatter
|
|
22
|
+
├── linter.ts # Linter
|
|
23
|
+
├── errors.ts # Error types & pretty printing
|
|
24
|
+
├── security.ts # Security sandbox
|
|
25
|
+
├── repl.ts # Interactive REPL
|
|
26
|
+
├── build.ts # Build system & project scaffolding
|
|
27
|
+
├── package-manager.ts # Package manager
|
|
28
|
+
├── lsp.ts # Language Server Protocol
|
|
29
|
+
└── version.ts # Version info
|
|
61
30
|
```
|
|
62
31
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
## Standard Library
|
|
66
|
-
|
|
67
|
-
Arc ships with a growing standard library. Currently implemented:
|
|
32
|
+
## Development
|
|
68
33
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
| [`strings`](stdlib/strings.arc) | pad_left, pad_right, capitalize, words |
|
|
73
|
-
| [`collections`](stdlib/collections.arc) | set, unique, group_by, chunk, flatten, zip_with, partition, sort_by |
|
|
74
|
-
| [`map`](stdlib/map.arc) | merge, map_values, filter_map, from_pairs, pick, omit |
|
|
75
|
-
| [`io`](stdlib/io.arc) | read_lines, write_lines, exists, append |
|
|
76
|
-
| [`http`](stdlib/http.arc) | get, post, put, delete, fetch_all, parse_url |
|
|
77
|
-
| [`json`](stdlib/json.arc) | to_json, from_json, pretty, get_path |
|
|
78
|
-
| [`csv`](stdlib/csv.arc) | parse_csv, to_csv, parse_csv_headers |
|
|
79
|
-
| [`test`](stdlib/test.arc) | describe, it, expect_eq, expect_true, run_tests |
|
|
80
|
-
| [`result`](stdlib/result.arc) | ok, err, is_ok, unwrap, map_result, try_fn |
|
|
81
|
-
| [`time`](stdlib/time.arc) | now, format_duration, sleep |
|
|
82
|
-
|
|
83
|
-
Plus many built-in functions available without imports: `map`, `filter`, `reduce`, `print`, `len`, `split`, `join`, `trim`, and more.
|
|
84
|
-
|
|
85
|
-
📖 **[Standard Library Reference](docs/stdlib-reference.md)** | **[Standard Library Tutorial](docs/stdlib-tutorial.md)**
|
|
86
|
-
|
|
87
|
-
## Documentation
|
|
88
|
-
|
|
89
|
-
- **[Getting Started](docs/getting-started.md)** — Installation, first program, REPL, basics
|
|
90
|
-
- **[Language Tour](docs/language-tour.md)** — Complete feature walkthrough
|
|
91
|
-
- **[Standard Library Reference](docs/stdlib-reference.md)** — Full stdlib API reference
|
|
92
|
-
- **[Standard Library Tutorial](docs/stdlib-tutorial.md)** — Hands-on stdlib guide
|
|
93
|
-
- **[Examples](examples/)** — Real-world programs with token comparisons
|
|
94
|
-
- **[FAQ](docs/FAQ.md)** — Common questions answered
|
|
95
|
-
- **[Grammar Spec](spec/grammar.md)** — Formal language specification
|
|
96
|
-
|
|
97
|
-
## Status
|
|
98
|
-
|
|
99
|
-
🚀 **In Active Development** — Arc has a working compiler (lexer, parser, IR, optimizer, JS/WAT codegen), interpreter, REPL, 17 stdlib modules, LSP, VS Code extension, package manager, build system, formatter, linter, security sandbox, rich error reporting, benchmarking framework, and migration tools. 508+ tests passing.
|
|
100
|
-
|
|
101
|
-
Current phase: **Phase 6 — Community & Adoption**
|
|
34
|
+
```bash
|
|
35
|
+
# Install dependencies
|
|
36
|
+
npm install
|
|
102
37
|
|
|
103
|
-
|
|
38
|
+
# Build (TypeScript → JavaScript)
|
|
39
|
+
npm run build
|
|
104
40
|
|
|
105
|
-
|
|
41
|
+
# Run directly from source
|
|
42
|
+
npx tsx src/index.ts run ../examples/hello-world.arc
|
|
106
43
|
|
|
107
|
-
|
|
108
|
-
arc
|
|
109
|
-
├── README.md # You are here
|
|
110
|
-
├── PHILOSOPHY.md # Design principles & rationale
|
|
111
|
-
├── ROADMAP.md # Development phases & milestones
|
|
112
|
-
├── LICENSE # MIT License
|
|
113
|
-
├── docs/ # Comprehensive documentation
|
|
114
|
-
├── spec/ # Formal language specification
|
|
115
|
-
├── examples/ # Code samples & tutorials
|
|
116
|
-
├── compiler/ # Compiler/interpreter implementation
|
|
117
|
-
├── stdlib/ # Standard library
|
|
118
|
-
└── CONTRIBUTING.md # Contribution guidelines
|
|
44
|
+
# Run with compiled output
|
|
45
|
+
node dist/index.js run ../examples/hello-world.arc
|
|
119
46
|
```
|
|
120
47
|
|
|
121
|
-
##
|
|
48
|
+
## CLI Commands
|
|
122
49
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
50
|
+
```bash
|
|
51
|
+
arc run <file> # Execute an Arc file
|
|
52
|
+
arc repl # Interactive REPL
|
|
53
|
+
arc parse <file> # Print AST
|
|
54
|
+
arc ir <file> # Print IR
|
|
55
|
+
arc compile <file> # Compile to JS (or --target=wat)
|
|
56
|
+
arc check <file> # Semantic analysis
|
|
57
|
+
arc fmt <file> # Format code (--write to overwrite)
|
|
58
|
+
arc lint <file> # Lint code
|
|
59
|
+
arc builtins # List all built-in functions
|
|
60
|
+
arc builtins --modules # List stdlib modules
|
|
61
|
+
arc build # Build project
|
|
62
|
+
arc test # Run project tests
|
|
63
|
+
arc new <name> # Scaffold new project
|
|
64
|
+
arc version # Print version
|
|
65
|
+
```
|
|
139
66
|
|
|
140
|
-
|
|
67
|
+
## Publishing
|
|
141
68
|
|
|
142
|
-
|
|
69
|
+
```bash
|
|
70
|
+
npm run copy-stdlib # Copy stdlib into compiler package
|
|
71
|
+
npm run build # Compile TypeScript
|
|
72
|
+
npm publish # Publish to npm
|
|
73
|
+
```
|
|
143
74
|
|
|
144
|
-
|
|
75
|
+
The `prepublishOnly` script handles `copy-stdlib` and `build` automatically.
|
|
145
76
|
|
|
146
|
-
|
|
77
|
+
## See Also
|
|
147
78
|
|
|
148
|
-
|
|
79
|
+
- [Language documentation](../docs/)
|
|
80
|
+
- [Standard library](../stdlib/)
|
|
81
|
+
- [Examples](../examples/)
|
|
82
|
+
- [Architecture details](ARCHITECTURE.md)
|
|
83
|
+
- [Design decisions](DESIGN_DECISIONS.md)
|
package/dist/ast.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export interface Loc {
|
|
|
2
2
|
line: number;
|
|
3
3
|
col: number;
|
|
4
4
|
}
|
|
5
|
-
export type Expr = IntLiteral | FloatLiteral | BoolLiteral | NilLiteral | StringLiteral | StringInterp | Identifier | BinaryExpr | UnaryExpr | CallExpr | MemberExpr | IndexExpr | PipelineExpr | IfExpr | MatchExpr | LambdaExpr | ListLiteral | MapLiteral | ListComprehension | ToolCallExpr | RangeExpr | BlockExpr | AsyncExpr | AwaitExpr | FetchExpr | SpreadExpr | OptionalMemberExpr | TryExpr;
|
|
5
|
+
export type Expr = IntLiteral | FloatLiteral | BoolLiteral | NilLiteral | StringLiteral | StringInterp | Identifier | BinaryExpr | UnaryExpr | CallExpr | MemberExpr | IndexExpr | PipelineExpr | IfExpr | MatchExpr | LambdaExpr | ListLiteral | MapLiteral | ListComprehension | ToolCallExpr | RangeExpr | BlockExpr | AsyncExpr | AwaitExpr | FetchExpr | SpreadExpr | OptionalMemberExpr | TryExpr | TryCatchExpr;
|
|
6
6
|
export interface IntLiteral {
|
|
7
7
|
kind: "IntLiteral";
|
|
8
8
|
value: number;
|
|
@@ -170,6 +170,13 @@ export interface TryExpr {
|
|
|
170
170
|
expr: Expr;
|
|
171
171
|
loc: Loc;
|
|
172
172
|
}
|
|
173
|
+
export interface TryCatchExpr {
|
|
174
|
+
kind: "TryCatchExpr";
|
|
175
|
+
body: Expr;
|
|
176
|
+
catchVar: string;
|
|
177
|
+
catchBody: Expr;
|
|
178
|
+
loc: Loc;
|
|
179
|
+
}
|
|
173
180
|
export type Pattern = WildcardPattern | LiteralPattern | BindingPattern | ArrayPattern | OrPattern | ConstructorPattern;
|
|
174
181
|
export interface WildcardPattern {
|
|
175
182
|
kind: "WildcardPattern";
|
|
@@ -201,7 +208,7 @@ export interface ConstructorPattern {
|
|
|
201
208
|
args: Pattern[];
|
|
202
209
|
loc: Loc;
|
|
203
210
|
}
|
|
204
|
-
export type Stmt = LetStmt | FnStmt | ForStmt | DoStmt | ExprStmt | UseStmt | TypeStmt | AssignStmt | MemberAssignStmt | IndexAssignStmt | RetStmt;
|
|
211
|
+
export type Stmt = LetStmt | FnStmt | ForStmt | DoStmt | WhileStmt | ExprStmt | UseStmt | TypeStmt | AssignStmt | MemberAssignStmt | IndexAssignStmt | RetStmt | BreakStmt | ContinueStmt | TryCatchStmt;
|
|
205
212
|
export interface AssignStmt {
|
|
206
213
|
kind: "AssignStmt";
|
|
207
214
|
target: string;
|
|
@@ -270,6 +277,27 @@ export interface DoStmt {
|
|
|
270
277
|
isWhile: boolean;
|
|
271
278
|
loc: Loc;
|
|
272
279
|
}
|
|
280
|
+
export interface WhileStmt {
|
|
281
|
+
kind: "WhileStmt";
|
|
282
|
+
condition: Expr;
|
|
283
|
+
body: Expr;
|
|
284
|
+
loc: Loc;
|
|
285
|
+
}
|
|
286
|
+
export interface BreakStmt {
|
|
287
|
+
kind: "BreakStmt";
|
|
288
|
+
loc: Loc;
|
|
289
|
+
}
|
|
290
|
+
export interface ContinueStmt {
|
|
291
|
+
kind: "ContinueStmt";
|
|
292
|
+
loc: Loc;
|
|
293
|
+
}
|
|
294
|
+
export interface TryCatchStmt {
|
|
295
|
+
kind: "TryCatchStmt";
|
|
296
|
+
body: Expr;
|
|
297
|
+
catchVar: string;
|
|
298
|
+
catchBody: Expr;
|
|
299
|
+
loc: Loc;
|
|
300
|
+
}
|
|
273
301
|
export interface ExprStmt {
|
|
274
302
|
kind: "ExprStmt";
|
|
275
303
|
expr: Expr;
|
package/dist/build.js
CHANGED
|
@@ -127,7 +127,7 @@ export function newProject(name, parentDir) {
|
|
|
127
127
|
"dev-dependencies": {},
|
|
128
128
|
};
|
|
129
129
|
writeFileSync(resolve(projectDir, "arc.toml"), serializeArcToml(toml));
|
|
130
|
-
writeFileSync(resolve(projectDir, "src", "main.arc"),
|
|
130
|
+
writeFileSync(resolve(projectDir, "src", "main.arc"), `# Hello from ${name}!\nlet msg = "Hello from ${name}!"\nprint(msg)\n`);
|
|
131
131
|
writeFileSync(resolve(projectDir, "tests", "main.test.arc"), `fn test_main() {\n let x = 1 + 1\n print(x)\n}\n`);
|
|
132
132
|
writeFileSync(resolve(projectDir, "README.md"), `# ${name}\n\nAn Arc project.\n\n## Getting Started\n\n\`\`\`bash\narc build\narc run\n\`\`\`\n`);
|
|
133
133
|
console.log(`Created project '${name}'`);
|
package/dist/formatter.js
CHANGED
|
@@ -150,7 +150,7 @@ export function format(source, options) {
|
|
|
150
150
|
else {
|
|
151
151
|
elInline = formatBlockExpr(expr.else_, depth);
|
|
152
152
|
}
|
|
153
|
-
const single = `if ${cond} ${thenInline}
|
|
153
|
+
const single = `if ${cond} ${thenInline} else ${elInline}`;
|
|
154
154
|
if (single.length + depth * opts.indentSize <= opts.maxLineLength) {
|
|
155
155
|
return single;
|
|
156
156
|
}
|
|
@@ -159,12 +159,12 @@ export function format(source, options) {
|
|
|
159
159
|
? formatBlockMultiline(expr.then, depth)
|
|
160
160
|
: thenInline;
|
|
161
161
|
if (expr.else_.kind === "IfExpr") {
|
|
162
|
-
return `if ${cond} ${thenMulti}
|
|
162
|
+
return `if ${cond} ${thenMulti} else ${formatExpr(expr.else_, depth)}`;
|
|
163
163
|
}
|
|
164
164
|
const elMulti = expr.else_.kind === "BlockExpr"
|
|
165
165
|
? formatBlockMultiline(expr.else_, depth)
|
|
166
166
|
: elInline;
|
|
167
|
-
return `if ${cond} ${thenMulti}
|
|
167
|
+
return `if ${cond} ${thenMulti} else ${elMulti}`;
|
|
168
168
|
}
|
|
169
169
|
const single = `if ${cond} ${thenInline}`;
|
|
170
170
|
if (single.length + depth * opts.indentSize <= opts.maxLineLength) {
|
|
@@ -240,6 +240,8 @@ export function format(source, options) {
|
|
|
240
240
|
case "SpreadExpr": return `...${formatExpr(expr.expr, depth)}`;
|
|
241
241
|
case "OptionalMemberExpr": return `${formatExpr(expr.object, depth)}?.${expr.property}`;
|
|
242
242
|
case "TryExpr": return `${formatExpr(expr.expr, depth)}?`;
|
|
243
|
+
case "TryCatchExpr":
|
|
244
|
+
return `try ${formatBlockExpr(expr.body, depth)} catch ${expr.catchVar} ${formatBlockExpr(expr.catchBody, depth)}`;
|
|
243
245
|
default: return `/* unknown */`;
|
|
244
246
|
}
|
|
245
247
|
}
|
|
@@ -347,6 +349,16 @@ export function format(source, options) {
|
|
|
347
349
|
const pub = stmt.pub ? "pub " : "";
|
|
348
350
|
return `${pub}type ${stmt.name} = ${formatTypeExpr(stmt.def)}`;
|
|
349
351
|
}
|
|
352
|
+
case "RetStmt":
|
|
353
|
+
return stmt.value ? `return ${formatExpr(stmt.value, depth)}` : "return";
|
|
354
|
+
case "WhileStmt":
|
|
355
|
+
return `while ${formatExpr(stmt.condition, depth)} ${formatBlockExpr(stmt.body, depth)}`;
|
|
356
|
+
case "BreakStmt":
|
|
357
|
+
return "break";
|
|
358
|
+
case "ContinueStmt":
|
|
359
|
+
return "continue";
|
|
360
|
+
case "TryCatchStmt":
|
|
361
|
+
return `try ${formatBlockExpr(stmt.body, depth)} catch ${stmt.catchVar} ${formatBlockExpr(stmt.catchBody, depth)}`;
|
|
350
362
|
case "AssignStmt":
|
|
351
363
|
return `${stmt.target} = ${formatExpr(stmt.value, depth)}`;
|
|
352
364
|
case "MemberAssignStmt":
|
package/dist/index.js
CHANGED
|
@@ -101,6 +101,108 @@ else if (command === "pkg") {
|
|
|
101
101
|
process.exit(1);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
+
else if (command === "builtins") {
|
|
105
|
+
console.log("Arc Built-in Functions\n");
|
|
106
|
+
console.log("I/O:");
|
|
107
|
+
console.log(" print(...values) Print values to stdout\n");
|
|
108
|
+
console.log("Type Conversion:");
|
|
109
|
+
console.log(" int(v) Convert to integer (throws on bad input)");
|
|
110
|
+
console.log(" float(v) Convert to float (throws on bad input)");
|
|
111
|
+
console.log(" str(v) Convert to string");
|
|
112
|
+
console.log(" bool(v) Convert to boolean");
|
|
113
|
+
console.log(" type_of(v) Get type: \"int\" \"float\" \"string\" \"bool\" \"list\" \"map\" \"fn\" \"nil\"\n");
|
|
114
|
+
console.log("Strings:");
|
|
115
|
+
console.log(" len(s) Length (codepoints, not bytes)");
|
|
116
|
+
console.log(" trim(s) Strip whitespace");
|
|
117
|
+
console.log(" upper(s) / lower(s) Case conversion");
|
|
118
|
+
console.log(" split(s, sep) Split into list");
|
|
119
|
+
console.log(" join(list, sep) Join list into string");
|
|
120
|
+
console.log(" replace(s, old, new) Replace all occurrences");
|
|
121
|
+
console.log(" contains(s, sub) Check substring");
|
|
122
|
+
console.log(" starts(s, prefix) Starts with");
|
|
123
|
+
console.log(" ends(s, suffix) Ends with");
|
|
124
|
+
console.log(" repeat(s, n) Repeat string n times");
|
|
125
|
+
console.log(" chars(s) Split into character list");
|
|
126
|
+
console.log(" slice(s, start, end?) Substring");
|
|
127
|
+
console.log(" index_of(s, sub) Find index (nil if not found)");
|
|
128
|
+
console.log(" ord(s) Char to code point");
|
|
129
|
+
console.log(" chr(n) Code point to char");
|
|
130
|
+
console.log(" char_at(s, i) Character at index\n");
|
|
131
|
+
console.log("Lists:");
|
|
132
|
+
console.log(" len(list) Length");
|
|
133
|
+
console.log(" map(list, fn) Transform each element");
|
|
134
|
+
console.log(" filter(list, fn) Keep elements matching predicate");
|
|
135
|
+
console.log(" reduce(list, fn, init) Fold left");
|
|
136
|
+
console.log(" fold(list, init, fn) Fold (init-first arg order)");
|
|
137
|
+
console.log(" find(list, fn) First matching element");
|
|
138
|
+
console.log(" any(list, fn) Any element matches?");
|
|
139
|
+
console.log(" all(list, fn) All elements match?");
|
|
140
|
+
console.log(" sort(list) Sort (numbers or strings)");
|
|
141
|
+
console.log(" head(list) First element");
|
|
142
|
+
console.log(" tail(list) All but first");
|
|
143
|
+
console.log(" last(list) Last element");
|
|
144
|
+
console.log(" reverse(list) Reverse");
|
|
145
|
+
console.log(" take(list, n) First n elements");
|
|
146
|
+
console.log(" drop(list, n) Skip first n");
|
|
147
|
+
console.log(" flat(list) Flatten nested lists");
|
|
148
|
+
console.log(" zip(a, b) Zip two lists");
|
|
149
|
+
console.log(" enumerate(list) Add indices: [[0,a],[1,b],...]");
|
|
150
|
+
console.log(" push(list, item) Append (returns new list)");
|
|
151
|
+
console.log(" concat(a, b) Concatenate lists");
|
|
152
|
+
console.log(" sum(list) Sum numbers");
|
|
153
|
+
console.log(" range(a, b) Generate [a, a+1, ..., b-1]\n");
|
|
154
|
+
console.log("Maps:");
|
|
155
|
+
console.log(" keys(map) Get keys as list");
|
|
156
|
+
console.log(" values(map) Get values as list");
|
|
157
|
+
console.log(" entries(map) Key-value pairs\n");
|
|
158
|
+
console.log("Math:");
|
|
159
|
+
console.log(" abs(n) Absolute value");
|
|
160
|
+
console.log(" min(...) / max(...) Min/max (args or list)");
|
|
161
|
+
console.log(" round(n) Round to integer\n");
|
|
162
|
+
console.log("Other:");
|
|
163
|
+
console.log(" assert(cond, msg?) Assert truth (throws on false)");
|
|
164
|
+
console.log(" time_ms() Unix timestamp in milliseconds\n");
|
|
165
|
+
console.log("Operators: + - * / % ** ++ == != < > <= >= and or not |> .. ?.");
|
|
166
|
+
console.log("Strings: \"text {expr}\" (interpolation) \"ha\" * 3 (repetition)");
|
|
167
|
+
console.log("Comments: # or //");
|
|
168
|
+
console.log("Errors: try { ... } catch e { ... }\n");
|
|
169
|
+
console.log("Stdlib: arc builtins --modules (list all standard library modules)");
|
|
170
|
+
if (args.includes("--modules")) {
|
|
171
|
+
console.log("\nStandard Library Modules: (import with: use <module>)\n");
|
|
172
|
+
const mods = [
|
|
173
|
+
["math", "sqrt, pow, ceil, floor, clamp, PI, E, sin, cos, log, 25 functions"],
|
|
174
|
+
["strings", "pad_left, pad_right, capitalize, words"],
|
|
175
|
+
["collections", "group_by, chunk, flatten, zip_with, partition, sort_by, unique"],
|
|
176
|
+
["map", "merge, map_values, filter_map, from_pairs, pick, omit"],
|
|
177
|
+
["io", "read_file, write_file, read_lines, exists, append"],
|
|
178
|
+
["http", "get, post, put, delete — real HTTP requests"],
|
|
179
|
+
["json", "to_json, from_json, pretty, get_path"],
|
|
180
|
+
["csv", "parse_csv, to_csv, parse_csv_headers"],
|
|
181
|
+
["regex", "match, find, test, replace, split, capture"],
|
|
182
|
+
["datetime", "now, today, parse, format, add_days, diff_days"],
|
|
183
|
+
["os", "cwd, list_dir, mkdir, exec, platform, env, remove, copy"],
|
|
184
|
+
["env", "get, set, has, all — environment variables"],
|
|
185
|
+
["crypto", "sha256, sha512, hmac_sha256, uuid, random_bytes"],
|
|
186
|
+
["error", "try_catch, try_finally, throw, retry, assert"],
|
|
187
|
+
["result", "ok, err, is_ok, unwrap, map_result, try_fn"],
|
|
188
|
+
["net", "ws_connect, tcp_connect, dns_lookup, base64_encode"],
|
|
189
|
+
["yaml", "parse, stringify"],
|
|
190
|
+
["toml", "parse, stringify"],
|
|
191
|
+
["html", "parse, create_element, to_html"],
|
|
192
|
+
["path", "join, dirname, basename, extname"],
|
|
193
|
+
["log", "info, warn, error, debug"],
|
|
194
|
+
["store", "get, set, delete — persistent key-value storage"],
|
|
195
|
+
["test", "describe, it, expect_eq, run_tests"],
|
|
196
|
+
["prompt", "template, count_tokens, window"],
|
|
197
|
+
["embed", "similarity, cosine, search"],
|
|
198
|
+
["llm", "chat, complete — multi-provider LLM API"],
|
|
199
|
+
];
|
|
200
|
+
for (const [name, desc] of mods) {
|
|
201
|
+
console.log(` ${name.padEnd(14)} ${desc}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
process.exit(0);
|
|
205
|
+
}
|
|
104
206
|
else if (command === "help" || command === "--help" || command === "-h" || !command || !file) {
|
|
105
207
|
console.log(`Arc ${ARC_VERSION} — A programming language designed by AI agents, for AI agents.\n`);
|
|
106
208
|
console.log("Usage: arc <command> [options]\n");
|
|
@@ -117,6 +219,8 @@ else if (command === "help" || command === "--help" || command === "-h" || !comm
|
|
|
117
219
|
console.log(" build Build the current project");
|
|
118
220
|
console.log(" test Run project tests");
|
|
119
221
|
console.log(" new <name> Create a new project");
|
|
222
|
+
console.log(" builtins List all built-in functions");
|
|
223
|
+
console.log(" builtins --modules List all standard library modules");
|
|
120
224
|
console.log(" pkg <sub> Package manager (init|add|remove|list|install)");
|
|
121
225
|
console.log(" version Print version info");
|
|
122
226
|
console.log("\nOptions:");
|