From 0091e54e979d4753d30558827b9ae7119c7d08f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yanis=20Zafir=C3=B3pulos?= <1265028+drkameleon@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:38:26 +0100 Subject: [PATCH 1/3] minor fix --- src/library/Core.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/library/Core.nim b/src/library/Core.nim index 3925b5b1fe..2e725d5083 100644 --- a/src/library/Core.nim +++ b/src/library/Core.nim @@ -1496,8 +1496,8 @@ proc defineLibrary*() = ; the main block is always evaluated! when [ prime? 4 -> print "yes, 4 is prime - wait, what?!" - prime? 5 -> print "yes, 5 is prime - prime? 7 -> print "yes, 6 is prime + prime? 5 -> print "yes, 5 is prime" + prime? 7 -> print "yes, 6 is prime" true -> print "none of the above was true" ] ; yes, 5 is prime From 50b9544fe2d3459f94136915eaa65ed2d82058f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yanis=20Zafir=C3=B3pulos?= <1265028+drkameleon@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:46:05 +0100 Subject: [PATCH 2/3] added example highlight short-circuit use of `when` --- src/library/Core.nim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/library/Core.nim b/src/library/Core.nim index 2e725d5083..25ea525178 100644 --- a/src/library/Core.nim +++ b/src/library/Core.nim @@ -1518,6 +1518,22 @@ proc defineLibrary*() = true -> print "x is >= 4" ] ; x is less than 4 + .... + f: function [x][ + print ["called F with:" x] + return odd? x + ] + ; short-circuiting: + ; conditions are not evaluated unless needed + when [ + [f 10]-> print "F 10" + [f 11]-> print "F 11" + [f 12]-> print "F 12" + ] + ; called F with: 10 + ; called F with: 11 + ; F 11 + """: #======================================================= let withAny = (hadAttr("any")) From 5bac4c4b3d07977c4bd95b66cb7f1208c8a4957b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yanis=20Zafir=C3=B3pulos?= <1265028+drkameleon@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:48:40 +0100 Subject: [PATCH 3/3] another minor edit --- src/library/Core.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/Core.nim b/src/library/Core.nim index 25ea525178..5c79e30156 100644 --- a/src/library/Core.nim +++ b/src/library/Core.nim @@ -1518,7 +1518,7 @@ proc defineLibrary*() = true -> print "x is >= 4" ] ; x is less than 4 - .... + .......... f: function [x][ print ["called F with:" x] return odd? x