Small fixes for user-defined functions, update readme.

This commit is contained in:
redxef 2022-11-27 01:51:38 +01:00
parent ddabe282a4
commit 74e98f7e3b
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921
2 changed files with 4 additions and 1 deletions

View file

@ -60,6 +60,9 @@ Available Operators:
- lt: `<`: less than
- load: `load`: load a key from the provided input `(load ".container.app_id")`
- has-key: `has-key`: check if a key is in the input: `(has-key ".container.app_id")`
- let: `let`: assign a local variable: `(let x 10)`
- setq: `setq`: assign a global variable: `(setq x 11)`
- defun: `defun`: user-defined functions: `((defun greet (a) (write (+ "Hello " a "!"))) (greet "Alice"))`
For example: `(> (load ".container.geometry.width") 300)` would match the first window where the width is greater than 300.

View file

@ -80,7 +80,7 @@ class Environment:
'<': lambda _, _l, a, b: a < b,
'>=': lambda _, _l, a, b: a >= b,
'<=': lambda _, _l, a, b: a <= b,
'+': lambda _, _l, *a: sum(a),
'+': lambda _, _l, *a: functools.reduce(lambda a, b: a + b, a),
'-': lambda _, _l, a, b: a - b,
'*': lambda _, _l, *a: functools.reduce(lambda a, b: a * b, a),
'/': lambda _, _l, a, b: a // b,