문제

I tried writing compiling and running my first nimrod program a fizzbuzz.

Nimrod is installed from git and version is.

[sayth nimrod]$  nimrod --version
Nimrod Compiler Version 0.9.4 (2014-04-28) [Linux: amd64]
Copyright (c) 2006-2014 by Andreas Rumpf

So here is a fizzbuzz

proc fizzBuzz(x, y: int) =
        for i in x .. y:
                if i mod 15 == 0:
                        echo("FizzBuzz")
                elif i mod 3 == 0:
                        echo("Fizz")
                elif i mod 5 == 0:
                        echo("Buzz")
                else:
                        echo(i)

I compiled to c (is there a better option?) and it appeared ok to me.

[sayth nimrod]$  nimrod c fizzbuzz.nim 
config/nimrod.cfg(37, 2) Hint: added path: '/home/sayth/.babel/pkgs/' [Path]
Hint: used config file '/home/sayth/Nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: fizzbuzz [Processing]
fizzbuzz.nim(1, 5) Hint: 'fizzbuzz.fizzBuzz(x: int, y: int)' is declared but not used [XDeclaredButNotUsed]
gcc -c  -w  -I/home/sayth/Nimrod/lib -o /home/sayth/Scripts/nimrod/nimcache/fizzbuzz.o /home/sayth/Scripts/nimrod/nimcache/fizzbuzz.c 
gcc -c  -w  -I/home/sayth/Nimrod/lib -o /home/sayth/Scripts/nimrod/nimcache/stdlib_system.o /home/sayth/Scripts/nimrod/nimcache/stdlib_system.c 
gcc   -o /home/sayth/Scripts/nimrod/fizzbuzz  /home/sayth/Scripts/nimrod/nimcache/stdlib_system.o /home/sayth/Scripts/nimrod/nimcache/fizzbuzz.o  -ldl
Hint: operation successful (8181 lines compiled; 1.065 sec total; 13.138MB) [SuccessX]

But running it produces no output. Is there something I am doing wrong?

[sayth nimrod]$  ./fizzbuzz
[sayth nimrod]$ 
도움이 되었습니까?

해결책

You simply forgot to call it. Note the compiler hint:

fizzbuzz.nim(1, 5) Hint: 'fizzbuzz.fizzBuzz(x: int, y: int)' is declared but not used [XDeclaredButNotUsed]

And no, your best option is compiling to C. There may be an LLVM backend in the future, but the general opinion is that it is more trouble than it is worth. Intermediate C output is more portable (gcc runs in many more plataforms than LLVM) and you can chose the compiler that can best optimize your code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top