arc-lang 0.6.12 → 0.6.14
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/dist/interpreter.js +15 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/stdlib/MODULES.md +7 -11
- package/stdlib/README.md +1 -1
package/dist/interpreter.js
CHANGED
|
@@ -27,6 +27,13 @@ class Env {
|
|
|
27
27
|
suggestion: "Did you mean 'let mut' to declare a mutable variable?",
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
+
if (name === "import") {
|
|
31
|
+
throw new ArcRuntimeError(`Undefined variable: ${name}`, {
|
|
32
|
+
code: ErrorCode.UNDEFINED_VARIABLE,
|
|
33
|
+
category: "RuntimeError",
|
|
34
|
+
suggestion: "Arc uses 'use' instead of 'import'. Try: use modulename",
|
|
35
|
+
});
|
|
36
|
+
}
|
|
30
37
|
const candidates = this.allNames();
|
|
31
38
|
const closest = findClosestMatch(name, candidates);
|
|
32
39
|
throw new ArcRuntimeError(`Undefined variable: ${name}`, {
|
|
@@ -229,13 +236,15 @@ function makePrelude(env) {
|
|
|
229
236
|
return null;
|
|
230
237
|
},
|
|
231
238
|
len: (v) => {
|
|
239
|
+
if (v === undefined || v === null)
|
|
240
|
+
throw new Error("len() requires an argument — pass a string, list, or map");
|
|
232
241
|
if (typeof v === "string")
|
|
233
242
|
return [...v].length; // codepoint count, not UTF-16
|
|
234
243
|
if (Array.isArray(v))
|
|
235
244
|
return v.length;
|
|
236
245
|
if (v && typeof v === "object" && "__map" in v)
|
|
237
246
|
return v.entries.size;
|
|
238
|
-
|
|
247
|
+
throw new Error("len() expects a string, list, or map — got " + typeof v);
|
|
239
248
|
},
|
|
240
249
|
map: (list, fn) => {
|
|
241
250
|
if (!Array.isArray(list))
|
|
@@ -2785,10 +2794,14 @@ function evalExpr(expr, env) {
|
|
|
2785
2794
|
if (idx !== Math.floor(idx))
|
|
2786
2795
|
throw new ArcRuntimeError("String index must be an integer");
|
|
2787
2796
|
let i = idx < 0 ? obj.length + idx : idx;
|
|
2788
|
-
|
|
2797
|
+
if (i < 0 || i >= obj.length)
|
|
2798
|
+
throw new ArcRuntimeError(`String index out of bounds: index ${idx} but length is ${obj.length}`);
|
|
2799
|
+
return obj.charAt(i);
|
|
2789
2800
|
}
|
|
2790
2801
|
if (Array.isArray(obj) && typeof idx === "number") {
|
|
2791
2802
|
let i = idx < 0 ? obj.length + idx : idx;
|
|
2803
|
+
if (i < 0 || i >= obj.length)
|
|
2804
|
+
throw new ArcRuntimeError(`Index out of bounds: index ${idx} but length is ${obj.length}`);
|
|
2792
2805
|
return obj[i] ?? null;
|
|
2793
2806
|
}
|
|
2794
2807
|
if (obj && typeof obj === "object" && "__map" in obj) {
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
package/stdlib/MODULES.md
CHANGED
|
@@ -781,21 +781,17 @@ stdlib/
|
|
|
781
781
|
└── cmd/ # Command execution
|
|
782
782
|
```
|
|
783
783
|
|
|
784
|
-
###
|
|
784
|
+
### Use Syntax
|
|
785
785
|
|
|
786
786
|
```arc
|
|
787
|
-
//
|
|
788
|
-
|
|
787
|
+
// Use entire module
|
|
788
|
+
use collections
|
|
789
789
|
|
|
790
|
-
//
|
|
791
|
-
|
|
790
|
+
// Use specific exports
|
|
791
|
+
use collections { List, Map, Set }
|
|
792
792
|
|
|
793
|
-
//
|
|
794
|
-
|
|
795
|
-
import {List as L} from collections
|
|
796
|
-
|
|
797
|
-
// Import everything (discouraged)
|
|
798
|
-
import * from collections
|
|
793
|
+
// Use everything (discouraged)
|
|
794
|
+
use collections { * }
|
|
799
795
|
```
|
|
800
796
|
|
|
801
797
|
---
|
package/stdlib/README.md
CHANGED
|
@@ -40,7 +40,7 @@ strings.capitalize("hello") # => "Hello"
|
|
|
40
40
|
strings.words("one two three") # => ["one", "two", "three"]
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
## Built-in Functions (No
|
|
43
|
+
## Built-in Functions (No `use` Required)
|
|
44
44
|
|
|
45
45
|
Many common operations are built into Arc and need no `use` statement:
|
|
46
46
|
|