1
0
mirror of https://github.com/janet-lang/janet synced 2025-12-06 16:48:08 +00:00

Add when-with and if-with

This is useful for reading from files.
This commit is contained in:
Calvin Rose
2020-01-15 22:49:41 -06:00
parent 65be9ae095
commit 962cd7e5f5
3 changed files with 31 additions and 0 deletions

View File

@@ -286,4 +286,17 @@
(file/seek f :set 0)
(assert (= (string (file/read f :all)) "foo\n") "temp files work"))
(var counter 0)
(when-with [x nil |$]
(++ counter))
(when-with [x 10 |$]
(+= counter 10))
(assert (= 10 counter) "when-with 1")
(if-with [x nil |$] (++ counter) (+= counter 10))
(if-with [x true |$] (+= counter 20) (+= counter 30))
(assert (= 40 counter) "if-with 1")
(end-suite)