fez-lisp 1.6.35 → 1.6.37
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 +146 -12
- package/lib/baked/macros.js +10 -0
- package/lib/baked/std.js +1 -1
- package/package.json +1 -1
- package/src/debugger.js +21 -11
- package/src/macros.js +21 -1
package/README.md
CHANGED
@@ -17,15 +17,6 @@
|
|
17
17
|
|
18
18
|
## [Try it in online editor](https://at-290690.github.io/fez/)
|
19
19
|
|
20
|
-
```lisp
|
21
|
-
; Build-in keywords
|
22
|
-
(/ ...) (+ ...) (* ...) (- ...) (= ...) (< ...) (> ...) (>= ...) (<= ...) (& ...) (~ ...) (| ...) (^ ...) (<< ...) (>> ...)
|
23
|
-
(mod ...) (let ...) (if ...) (not ...) (and ...) (or ...) (atom? ...) (lambda? ...)
|
24
|
-
(length ...) (do ...) (array ...) (set! ...) (pop! ...) (get ...) (lambda ...) (apply ...)
|
25
|
-
```
|
26
|
-
|
27
|
-
## ⚠️ Important: Do not use this programming language in production!
|
28
|
-
|
29
20
|
```lisp
|
30
21
|
; Lisp programming language. It's not exactly like other Lisps.
|
31
22
|
; This is a CUSTOM lisp language that does not fully follow the general Lisp conventions
|
@@ -53,6 +44,12 @@
|
|
53
44
|
;
|
54
45
|
; See below for more examples and details.
|
55
46
|
|
47
|
+
|
48
|
+
; Build-in keywords
|
49
|
+
(/ ...) (+ ...) (* ...) (- ...) (= ...) (< ...) (> ...) (>= ...) (<= ...) (& ...) (~ ...) (| ...) (^ ...) (<< ...) (>> ...)
|
50
|
+
(mod ...) (let ...) (if ...) (not ...) (and ...) (or ...) (atom? ...) (lambda? ...)
|
51
|
+
(length ...) (do ...) (array ...) (set! ...) (pop! ...) (get ...) (lambda ...) (apply ...)
|
52
|
+
|
56
53
|
; Important Note:
|
57
54
|
; In this programming language, parentheses are used to group expressions and define the structure of code.
|
58
55
|
; It is essential to keep the number of opening and closing parentheses balanced.
|
@@ -215,6 +212,22 @@
|
|
215
212
|
(boole:true? var) ; - Check if boolean variable is true
|
216
213
|
(boole:false? var) ; - Check if boolean variable is false
|
217
214
|
;
|
215
|
+
|
216
|
+
; =============================
|
217
|
+
; Boolean Values: true and false
|
218
|
+
; =============================
|
219
|
+
; In this language, 'true' and 'false' are the canonical boolean values.
|
220
|
+
; - 'true' is equivalent to 1 (logical true)
|
221
|
+
; - 'false' is equivalent to 0 (logical false)
|
222
|
+
; You can use 'true' and 'false' directly in conditions, logical operations, and as variable names for boolean logic.
|
223
|
+
; All conditions and logical operations should use these (or 1/0) for clarity and correctness.
|
224
|
+
;
|
225
|
+
; Examples:
|
226
|
+
(and true false) ; returns false (0)
|
227
|
+
(or true false) ; returns true (1)
|
228
|
+
(not false) ; returns true (1)
|
229
|
+
|
230
|
+
|
218
231
|
; Examples:
|
219
232
|
(let counter (math:var-def 0)) ; numeric variable
|
220
233
|
(math:var-increment! counter) ; increment by 1
|
@@ -275,11 +288,42 @@
|
|
275
288
|
; . means skip that element and last one is aways the rest unelss skipped
|
276
289
|
[a . b c]
|
277
290
|
[a b .]
|
278
|
-
|
279
|
-
|
280
|
-
;
|
291
|
+
|
292
|
+
; =============================
|
293
|
+
; Array and List Syntactic Sugar
|
294
|
+
; =============================
|
295
|
+
; You can use square brackets [ ... ] as syntactic sugar for arrays.
|
296
|
+
; [1 2 3] is equivalent to (array 1 2 3)
|
297
|
+
; You can use curly braces { ... } as syntactic sugar for linked lists.
|
298
|
+
; {1 2 3} is equivalent to (list 1 2 3)
|
299
|
+
; You can use these forms anywhere an array or list is expected.
|
300
|
+
; Destructuring is also supported:
|
301
|
+
; [a b . c] ; destructures the first two elements into a, b, and the rest into c
|
302
|
+
; {a b . c} ; same for lists
|
303
|
+
|
304
|
+
; =============================
|
305
|
+
; Pipe Operator
|
306
|
+
; =============================
|
307
|
+
; The pipe operator (|>) allows you to chain expressions, passing the result of one as the input to the next.
|
308
|
+
; Syntax:
|
309
|
+
(|> value f1 f2 f3 ...)
|
310
|
+
; This is equivalent to:
|
311
|
+
(f3 (f2 (f1 value)))
|
312
|
+
; Example:
|
313
|
+
(|> 1 (+ 1) (* 2)) ; equivalent to (* 2 (+ 1 1)) ; returns 4
|
314
|
+
; You can use the pipe operator to make code more readable when applying multiple transformations.
|
281
315
|
|
282
316
|
"Hello World!" ; syntactic suggar for string but it's array of character codes
|
317
|
+
; =============================
|
318
|
+
; Strings and Character Codes
|
319
|
+
; =============================
|
320
|
+
; String literals like "hello" are automatically transformed into arrays of character codes.
|
321
|
+
; For example:
|
322
|
+
"abc"
|
323
|
+
; is equivalent to
|
324
|
+
(array 97 98 99)
|
325
|
+
; You can use string literals anywhere an array of character codes is expected.
|
326
|
+
; All string operations work on these arrays.
|
283
327
|
|
284
328
|
; syntactic suggar for variables
|
285
329
|
|
@@ -300,4 +344,94 @@
|
|
300
344
|
(+= n 10) ; increment number variable by 10
|
301
345
|
(get n) ; get number variable
|
302
346
|
|
347
|
+
; =============================
|
348
|
+
; Syntactic Sugar for Variables
|
349
|
+
; =============================
|
350
|
+
; This language provides convenient syntactic sugar for defining and working with mutable variables of different types.
|
351
|
+
;
|
352
|
+
; 1. Number Variables
|
353
|
+
; - Use (variable name initial-value) to define a mutable number variable.
|
354
|
+
; - Use (++ name) to increment by 1, (+= name x) to add x, and (set name x) to set a new value.
|
355
|
+
; - Use (get name) to retrieve the current value.
|
356
|
+
; Example:
|
357
|
+
(variable n 10) ; define number variable n with value 10
|
358
|
+
(++ n) ; increment n by 1 (n = 11)
|
359
|
+
(+= n 5) ; increment n by 5 (n = 16)
|
360
|
+
(set n 42) ; set n to 42
|
361
|
+
(get n) ; returns 42
|
362
|
+
;
|
363
|
+
; 2. Boolean Variables
|
364
|
+
; - Use (boolean name initial-value) to define a mutable boolean variable.
|
365
|
+
; - Use (boole-set name true/false) to set the value.
|
366
|
+
; - Use (boole:true? name) or (boole:false? name) to check the value.
|
367
|
+
; - Use (boole name) to get the boolean value (true or false) directly.
|
368
|
+
; - Use (get name) is NOT valid for booleans; always use the boolean helpers.
|
369
|
+
; Example:
|
370
|
+
(boolean x false) ; define boolean variable x as false
|
371
|
+
(boole-set x true) ; set x to true
|
372
|
+
(boole:true? x) ; returns true if x is true
|
373
|
+
(boole:false? x) ; returns true if x is false
|
374
|
+
(boole x) ; returns true or false (the value of x)
|
375
|
+
;
|
376
|
+
; 3. Array Variables
|
377
|
+
; - Use (let arr [1 2 3]) to define an array variable.
|
378
|
+
; - Use (array:set! arr idx value) to set an element.
|
379
|
+
; - Use (array:get arr idx) to get an element.
|
380
|
+
;
|
381
|
+
; 4. General Variables
|
382
|
+
; - Use (let v (var:def value)) to define a general variable.
|
383
|
+
; - Use (var:set! v value) to set a new value.
|
384
|
+
; - Use (var:get v) to retrieve the value.
|
385
|
+
;
|
386
|
+
; Note:
|
387
|
+
; - Use the correct set/get helpers for each variable type.
|
388
|
+
; - Do NOT use set! for number or boolean variables; use set or boole-set as appropriate.
|
389
|
+
; - Do NOT use get for boolean variables; use boole:true? or boole:false? instead.
|
390
|
+
;
|
391
|
+
|
392
|
+
; =============================
|
393
|
+
; Common Mistakes and Gotchas
|
394
|
+
; =============================
|
395
|
+
; 1. Using set! on number or boolean variables:
|
396
|
+
; WRONG: (set! n 42) ; n is a number variable, use (set n 42) instead
|
397
|
+
; WRONG: (set! x true) ; x is a boolean variable, use (boole-set x true) instead
|
398
|
+
; IMPORTANT: n (or x) must be defined using the variable helpers (e.g., (variable n 41) or (boolean x false)) in order to use (set n ...) or (boole-set x ...). If you define n as (let n 41), (set n ...) will fail.
|
399
|
+
;
|
400
|
+
; 2. Using get on boolean variables:
|
401
|
+
; WRONG: (get x) ; x is a boolean variable, use (boole:true? x), (boole:false? x), or (boole x) instead
|
402
|
+
;
|
403
|
+
; 3. Forgetting to wrap multiple expressions in a lambda body with (do ...):
|
404
|
+
; WRONG: (lambda x y (let z (+ x y)) (* z 2))
|
405
|
+
; RIGHT: (lambda x y (do (let z (+ x y)) (* z 2)))
|
406
|
+
;
|
407
|
+
; 4. Using infix or postfix notation:
|
408
|
+
; WRONG: (1 + 2) or (1 2 +)
|
409
|
+
; RIGHT: (+ 1 2)
|
410
|
+
;
|
411
|
+
; 5. Using set! for arrays only:
|
412
|
+
; set! is ONLY for arrays. For all other variable types, use the appropriate set or helper function.
|
413
|
+
;
|
414
|
+
; 6. Using get for general or number variables is fine, but for booleans always use the boolean helpers.
|
415
|
+
;
|
416
|
+
; 7. Not using the correct prefix for tail-call or memoized functions:
|
417
|
+
; Only use tail-call: for linear recursion, and memoized: when you want automatic memoization.
|
418
|
+
;
|
419
|
+
; 8. Not balancing parentheses:
|
420
|
+
; Always check that every opening parenthesis has a matching closing parenthesis.
|
421
|
+
;
|
422
|
+
; 9. Using forbidden names for variables:
|
423
|
+
; Do NOT use built-in names like 'loop', 'if', 'do' as variable names.
|
424
|
+
;
|
425
|
+
; 10. Not using prefix notation for all operators and function calls.
|
426
|
+
;
|
427
|
+
; 11. For arrays, always prefer using array:set!, array:pop!, and array:get instead of the plain set!, pop!, and get forms. This avoids ambiguity and makes your code clearer.
|
428
|
+
;
|
429
|
+
; - Integer division: (// a b) is syntactic sugar for (math:floor (/ a b)), and performs integer division.
|
430
|
+
; - No while: The language does not have a 'while' loop; use (loop ...) or (loop:for-n ...) constructs for iteration.
|
431
|
+
; - String and char codes: String literals like "." are syntactic sugar for arrays of character codes. For example, "." is [46], so (array:get str 0) on a string returns the char code (e.g., 46 for ".").
|
432
|
+
; - No return: There is no 'return' statement. Use booleans or control flow (like breaking loops or propagating values) for early exit or to indicate success/failure in recursive/backtracking algorithms.
|
433
|
+
; - Variable redeclaration: Do not redeclare (let) a variable that already exists in the same scope. Redeclaring variables can cause bugs or unexpected behavior. Always use unique variable names within a given scope, or update the variable using the appropriate set! or var:set! helper.
|
434
|
+
; - (get) vs (array:get): (get) and (array:get) are the same under the hood. (get xs) with one argument is equivalent to (get xs 0), returning the first element. However, you should only use (get) for variables declared with (variable) syntactic sugar (numbers only). For arrays, always use (array:get). For booleans, use (boole:true?) or related helpers. This avoids ambiguity and makes your code clearer and less error-prone.
|
435
|
+
|
436
|
+
|
303
437
|
```
|
package/lib/baked/macros.js
CHANGED
@@ -128,6 +128,16 @@ export const NOT_EQUAL = [
|
|
128
128
|
]
|
129
129
|
]
|
130
130
|
]
|
131
|
+
export const EQUAL = [
|
132
|
+
[0, 'lambda'],
|
133
|
+
[1, 'a'],
|
134
|
+
[1, 'b'],
|
135
|
+
[
|
136
|
+
[0, '='],
|
137
|
+
[1, 'a'],
|
138
|
+
[1, 'b']
|
139
|
+
]
|
140
|
+
]
|
131
141
|
export const SLICE_RAW = [
|
132
142
|
[0, 'lambda'],
|
133
143
|
[1, 'arr'],
|