2 ms·
Indeed. But Nim is much more expressive than Python. A very nice feature of Nim is clean macros. They support regular string matching in native Perl syntax. For
by progman 11y ago
Indeed. But Nim is much more expressive than Python. A very nice feature of Nim is clean macros. They support regular string matching in native Perl syntax. For instance.
if line =~ rx"http[s]://(.+)":
var url = matches[0]
...
where rx is defined as:
# partial regular expressions as in Perl
template rx * (arg: expr): expr =
re(r".*?" & arg & ".*")
Another macro instance:
template repeat * (body: stmt): stmt {.immediate.} =
block:
while (true):
body
template until * (cond: expr): stmt {.immediate.} =
block:
if cond:
break
# Sample:
#
# var i=0
# repeat:
# echo i
# i += 1
# until i==7
Nice, isn't it?