~pepe/marble

29bb62b91e0f48d9cb4113379409066aaa4af1b0 — Josef Pospíšil a month ago 7bf0c9e
Add do-var and get-only-el
2 files changed, 21 insertions(+), 0 deletions(-)

M marble/init.janet
M test/suite0.janet
M marble/init.janet => marble/init.janet +17 -0
@@ 164,3 164,20 @@
(def <-: named-capture)

(def . string)

(defmacro get-only-el
  ```
  Convenience macro for geting first element
  from first row.
  ```
  [m]
  ~(in (in ,m 0) 0))

(defmacro do-var
  ```
  Convenience macro for defining varible
  named `v` with value `d` before `body`
  and returning it afterwards.
  ```
  [v d & body]
  ~(do (var ,v ,d) ,;body ,v))

M test/suite0.janet => test/suite0.janet +4 -0
@@ 141,4 141,8 @@
(assert (= (. ;(range 10)) (string ;(range 10)))
        "dot")

(assert (one? (get-only-el @[@[1]])))

(assert (one? (do-var res 0 (++ res))))

(end-suite)