This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
nim example #40
Closed
Closed
nim example #40
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
Rust/*/target/ | ||
Nim/*/* | ||
!Nim/*/*.* | ||
!Nim/*/*/ | ||
Zig/*/zig-cache/ | ||
Zig/*/zig-out/ | ||
.idea/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Nim Examples | ||
|
||
|
||
|
||
todo | ||
|
||
|
||
|
||
|
||
|
||
For setting up your environment and installing the necessary tools, see [the Enarx documentation on using WebAssembly with Nim](https://enarx.dev/docs/WebAssembly/Nim). | ||
|
||
nim c -r -d:release fibonacci.nim | ||
|
||
or | ||
|
||
nimble run | ||
nimble run -- 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Package | ||
|
||
version = "0.1.0" | ||
author = "Profian" | ||
description = "Fibonacci example." | ||
license = "Apache-2.0" | ||
srcDir = "src" | ||
bin = @["fibonacci"] | ||
|
||
|
||
# Dependencies | ||
|
||
requires "nim >= 1.6.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import std/os, std/parseutils, std/rdstdin, std/strformat | ||
|
||
proc fib(n: int): int = | ||
case n: | ||
of 0, 1: | ||
n | ||
else: | ||
fib(n - 1) + fib(n - 2) | ||
|
||
proc main = | ||
var args = commandLineParams() | ||
|
||
if args.len == 0: | ||
var line: string | ||
|
||
if not readLineFromStdin("Enter a non-negative number: ", line): | ||
echo ("Failed to read line") | ||
quit QuitFailure | ||
|
||
args.add(line) | ||
|
||
var index: int | ||
|
||
for arg in args: | ||
if arg.parseInt(index) == 0: | ||
echo fmt("Failed to parse number: {arg}") | ||
quit QuitFailure | ||
|
||
echo (fmt"Fibonacci sequence number at index {index} is {fib(index)}") | ||
|
||
when isMainModule: | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a way to simplify this?
What paths are we trying to ignore here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I can get around this so we can have an
out
dir. I will have to investigate a bit haven't used nim in forever.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default behavior will make a Nim/fibonacci/fibonacci bin or something else if you compile to js etc