From 74e98f7e3b162a16a6f45153c58328316d4aa791 Mon Sep 17 00:00:00 2001 From: redxef Date: Sun, 27 Nov 2022 01:51:38 +0100 Subject: [PATCH] Small fixes for user-defined functions, update readme. --- README.md | 3 +++ i3toolwait | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e926ca..ad52537 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/i3toolwait b/i3toolwait index 0fe258b..c91c152 100755 --- a/i3toolwait +++ b/i3toolwait @@ -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,