mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	Fix or with zero arguments.
The value is nil to be consistent for and/or and all/some. Also add some tests for and/or.
This commit is contained in:
		| @@ -277,7 +277,8 @@ | ||||
|   [& forms] | ||||
|   (def len (length forms)) | ||||
|   (var i (- len 1)) | ||||
|   (var ret (in forms i)) | ||||
|   (var ret (if (= 0 len) nil | ||||
|              (in forms i))) | ||||
|   (while (> i 0) | ||||
|     (-- i) | ||||
|     (def fi (in forms i)) | ||||
|   | ||||
| @@ -294,4 +294,25 @@ | ||||
|           (sort (mapcat (fn [[x y z]] [z y x]) (partition 3 (range 99))))) "sort 5") | ||||
| (assert (<= ;(sort (map (fn [x] (math/random)) (range 1000)))) "sort 6") | ||||
|  | ||||
| # And and or | ||||
|  | ||||
| (assert (= (and true true) true) "and true true") | ||||
| (assert (= (and true false) false) "and true false") | ||||
| (assert (= (and false true) false) "and false true") | ||||
| (assert (= (and true true true) true) "and true true true") | ||||
| (assert (= (and 0 1 2) 2) "and 0 1 2") | ||||
| (assert (= (and 0 1 nil) nil) "and 0 1 nil") | ||||
| (assert (= (and 1) 1) "and 1") | ||||
| (assert (= (and) true) "and with no arguments") | ||||
|  | ||||
| (assert (= (or true true) true) "or true true") | ||||
| (assert (= (or true false) true) "or true false") | ||||
| (assert (= (or false true) true) "or false true") | ||||
| (assert (= (or false false) false) "or false true") | ||||
| (assert (= (or true true false) true) "or true true false") | ||||
| (assert (= (or 0 1 2) 0) "or 0 1 2") | ||||
| (assert (= (or nil 1 2) 1) "or nil 1 2") | ||||
| (assert (= (or 1) 1) "or 1") | ||||
| (assert (= (or) nil) "or with no arguments") | ||||
|  | ||||
| (end-suite) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Leah Neukirchen
					Leah Neukirchen