Otherwise all variables are global. I dont know whats a cinoaiker.
What does a multi-line where clause look like? I couldn't find an example,
especially of a complex where clause, possibly using exists as one of the lines.
It's a pity the from keyword needs to be in single quotation marks. I was
trying to think of an alternative (e.g. source), but then it
As the title of this thread says, I’ve seen many recommendations in this forum
to wrap your code in a top level “main” procedure.
Why does that make it faster and why can’t the cinoaiker make that optimization
automatically for you?
I see, has to be like this:
proc main() =
var
s: string
proc `+`(a:string|char, b:string|char): string =
a & b
template fused2{a = `&`(a,b)}(a:var string,b:string|char) = a.add(b)
template fused4{a = `+`(a,b)}(a:var
That was cool, so I thought I'd try the same thing with +:
ms:nim jim$ cat strfused.nim
proc main() =
var
s: string
template fused2{a = `&`(a,b)}(a:var string,b:string) = a.add(b)
template fused3{a = `&`(a,b)}(a:var string,b:char) = a.add(b)
#FFFE66 is available.
Hey thanks, this is interesting, although it threw me at first because it ran
in .01s and used 4MB of RAM. After scratching my head a bit I realized you were
doing 1M loops instead of 100M. :-)
The template version ran in .69s on my machine, while str1c, which should be
the same thing, runs in
var
s: string
template fused2{a = `&`(a,b)}(a:var string,b:string) = a.add(b)
for _ in 0..1_000_000:
s = s & "x"
echo len(s)
Run
that was the secret! dumpTree was my friend, needed to get the AST to match
precisely
var
s: string
proc `:=`(a:var string,b:string) = `=`(a,b)
template fused{`:=`(a,`&`(a,b))}(a:var string,b:string) = a.add(b)
#template fused2{`=`(a,`&`(a,b))}(a:var string,b:string) = a.add(b)
for _ in 0..1_000_000:
s := s & "x"
echo len(s)
Run
I think try to make module names plural by convention as well, in the standard
library the module containing `Table` is `tables`.
I would name the module `images`
10 matches
Mail list logo