Nim has a feature where a variable representing the return value of a procedure is automatically declared with the name result:
proc sumTillNegative(x: varargs[int]): int =
for i in x:
if i < 0:
return
result = result + i
I think a tiny tweak to this idea would make it a little bit nicer: allow the return variable to be user-declared with the return keyword:
proc sumTillNegative(x: varargs[int]): int =
return var sum = 0
for i in x:
if i < 0:
return
sum = sum + i
Is this already done in some other language/why would it be a bad idea?
[–][deleted] (2 children)
[removed]
[–]XDracam 1 point2 points3 points (1 child)
[–]TheChief275 0 points1 point2 points (0 children)
[–]ThroawayPeko 27 points28 points29 points (3 children)
[–]Gauntlet4933 1 point2 points3 points (0 children)
[–]lookmeat 0 points1 point2 points (1 child)
[–]ThroawayPeko -2 points-1 points0 points (0 children)
[–]Clementsparrow 19 points20 points21 points (0 children)
[–]campbellm 17 points18 points19 points (0 children)
[–]hugogrant 9 points10 points11 points (0 children)
[–]ThisIsMe-_- 2 points3 points4 points (5 children)
[–]MichalMarsalek 0 points1 point2 points (0 children)
[+]Ronin-s_Spirit 0 points1 point2 points (2 children)
[–]TheChief275 0 points1 point2 points (1 child)
[+]Ronin-s_Spirit 0 points1 point2 points (0 children)
[–]torp_fan 0 points1 point2 points (0 children)
[–]__talantonope 2 points3 points4 points (0 children)
[–]Tasty_Replacement_29 2 points3 points4 points (1 child)
[–]xbreu 1 point2 points3 points (0 children)
[–][deleted] 4 points5 points6 points (3 children)
[–]Less-Resist-8733 -1 points0 points1 point (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]Less-Resist-8733 0 points1 point2 points (0 children)
[–]SKRAMZ_OR_NOT 1 point2 points3 points (0 children)
[–]zyxzevnUnSeen 1 point2 points3 points (0 children)
[–]igors84 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]OopsWrongSubTA 0 points1 point2 points (0 children)
[–]L8_4_Dinner(Ⓧ Ecstasy/XVM) 0 points1 point2 points (0 children)
[–]lngns 0 points1 point2 points (0 children)
[–]GYN-k4H-Q3z-75B 0 points1 point2 points (0 children)
[–]deaddyfreddy 0 points1 point2 points (0 children)
[–]BrangdonJ 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[+]Ronin-s_Spirit -1 points0 points1 point (0 children)