So in https://forum.nim-lang.org/t/5855 @juancarlospaco shared a website https://code-golf.io
It's a website for competitive code golfing and it supports Nim!
So if someone considers it fun and has free time, we can try making new solutions, and, only if you want to, share the solutions (CodeGolf doesn't allow you to see other people's solutions) or the tricks for making Nim code smaller here.
Some tricks:
Before:
proc a(x:int):int=
result=5
if x>5:
if x<3:
if x==0:
echo x
echo x-1
elif x==0:
echo 0
echo 5
else:return 5
After:
proc b(x:int):int=(result=5;(if x>5:(if x<3:(if x==0:(echo x;echo x-1)))elif x==0:(echo 0;echo 5) else:return 5))
15 characters less
And of course, don't follow these tips in your real projects
Some examples:
Leap years from 1801 to 2400:
import times
for x in 1801..2400:
if x.isleapyear:echo x
Without stdlib -
for x in 1801..2400:
if x%%(if x%%25>0:4 else:16)<1:echo x
Fibonacci of numbers from 0 to 30:
for i in ..30:echo (var(a,b)=(0, 1);(for x in 0..<i:(a,b)=(b,a+b));a)
Or, by SolitudeSF:
var(a,b)=(0,1)
for _ in ..30:echo a;(a,b)=(b+a,a)
You can replace indentation with ; and parentheses
Now we can just admit that Nim is a syntax skin over Lisp