> template filter(expr: untyped) =
>
>
> when compiles(expr):
> when expr is seq[bool]: echo "bool" elif expr is seq[int]: echo "int"
> else: echo "something else"
> else:
> echo "can't compile"
>
> filter(a + b)
It seems code-highliting is broken.
I eventually settled for plain aliases:
alias nim-gen='nim c -r -d:release --passC:-mcpu=cortex-a5
--passC:-mfpu=neon --passC:- ftree-vectorize --passC:-fprofile-generate
--passL:-lgcov'
alias nim-use='nim c -d:release --passC:-mcpu=cortex-a5 --passC:-mfpu=neon
@cdunn2001, it looks like it's running for me with the latest on Ubuntu 14.04
and 16.04; I haven't tried on OS X yet.
Your code does not work because you are using `func` as identifier, which is a
reserved keyword. I demangled it a bit and renamed `func` to `fun`:
type
MyProc1 = proc()
MyProc2 = proc(p: MyProc1)
MyProc3 = proc(p: MyProc1): MyProc1
proc applyAllSync(funcs:
I need something that not going to cause compilation error for the case when
expr does not have a type
template filter(expr: untyped) =
when expr is seq[bool]: echo "bool"
elif expr is seq[int]: echo "int"
else: discard
filter(a + b) #
Well, initially it is not JS. I'm working on our internal compiler's Nim
backend.
Original function source (ML-like language):
applyAllSync(funcs: [(() -> void) -> void], onAllDone: () -> void) -> void {
fold(funcs, \onDoneNothing -> onDoneNothing,
type(expr) -> expr:
template filter(expr: untyped) =
when expr is seq[bool]: echo "bool"
elif expr is seq[int]: echo "int"
else: discard
filter newSeq[int]()
I don't know if this is useful for your usecase tho.
Your JS is horrible to read as it lacks type information (what is funcs, what
is onAllDone, what is doBefore etc). I tried to interpret it but gave up. You
should rather explain what you want to do than giving us this piece of code.
Hi Hackers,
I need to apply different logic in template if the argument has a particular
type or is untyped expression. Calling getType() in macro triggers compilation
failure for untyped expression.
Ideally, something like this. Any ideas are appreciated.
template filter(expr :
I can only support the workflow Araq suggested, I do the same. You can then add
`~/projects/Nim/bin` to your path, or symlink the binaries from there to a
folder that is already in your path. I have `~/bin` in my path and put the
symlinks there. `make install` should not be done with any
I have another question.
There is a procedure
proc fold*[T, S](arr: seq[T], init: S, op: proc(acc: S, v: T): S): S =
for x in arr:
init = op(init, x)
return init
How to implement in Nim this function (Javascript):
function applyAllSync(funcs,
> The ./install.sh script puts things under standard subdirs for /usr/bin and
> /usr/local/bin, but then does something different for other dirs.
"Does something different" \-- Like what? But you shouldn't use `install.sh`
anyway, manual messing with /usr/bin is bad, Linux got package managers
A better installation and version management system similar to rustup is in
development by @dom96 called choosenim.
It seems like your on Linux? If so, perhaps your distro has a version of Nim in
the repo? Perhaps some work could be done by creating a Flatpack or AppImage
for easier
Ok so I've been wanting to try nim for a while and finally did.
Right away I hit something I really dislike, and that is that nim has
apparently decided to do it's own thing about installation, rather than working
like ./configure --prefix=whatever. The ./install.sh script puts things under
With that fix on `devel`, it no longer hangs on OSX, but it still seg-faults on
Ubuntu.
15 matches
Mail list logo