; quoting rules

(setq glob0 123)
(setq glob1 '(2 3 4))

(assert (= (list 1 2 3) '(1 2 3) `(1 2 3) (quote (1 2 3))))
(assert (= '(1 glob0 3) `(1 glob0 3)))
(assert (= '(1 123 3) `(1 ,glob0 3)))
(assert (= '(1 glob1 5) `(1 glob1 5)))
(assert (= '(1 (2 3 4) 5) `(1 ,glob1 5)))
(assert (= '(1 2 3 4 5) `(1 ,@glob1 5)))
(assert (= '(2 3 4 5) `(,@glob1 5)))
(assert (= '(1 2 3 4) `(1 ,@glob1)))
(assert (= '(2 3 4) `(,@glob1)))
(assert (= '((2 3 4)) `(,glob1)))

; Nested
(assert (= '((123 123) (123 123)) `((,glob0 ,glob0) (,glob0 ,glob0))))
(assert (= '(2 3 4 2 3 4) `(,@glob1 ,@glob1)))
(assert (= '((((2 3 4)))) `(((,glob1)))))

; Read value of a constructed symbol
(defun read-indexed (prefix index) (get (symbol (+ (->string prefix) index))))
(assert (= 123 (read-indexed 'glob 0)))
(assert (= '(2 3 4) (read-indexed 'glob 1)))
(assert (= nil (read-indexed 'glob 2)))

; those are prelude, but defined in lysp itself:

(print "The previously printed expression is AFTER this one in the code")
(compile-debug
  (when #t
    (print "a")
    (print "b")
    )
  )
(runtime-debug
  (when #t
    (print "a")
    (print "b")
    )
  )

(when 1
  (print "a")
  (print "b")
  )
(unless nil
  (print "c")
  (print "d")
  )


; catch macro
(print "Failing in a catch block...")
(catch
  (print a)
  e (print "Caught an error:" e)
  )

(print "... doesn't fail the execution")
