Re: How to expand a single template
I think I understand now, the template args in getAst have to be NimNodes. One more question, can you dynamically evaluate template expansions based on existing AST or is it conceptually unviable? Example: import macros template texture(a, b): untyped = var a: TexturePtr init: state.a = loadTexture(b) finish: state.a.free() macro mcr(body) = result = newEmptyNode() let node = getAst(`body[0]`) # do what here? echo body.treeRepr mcr: texture background, "res/menu.png" Run
Re: Why does the this code work?
I'm sure there a couple of open bugs thanks to these rules and in retrospect `f(unpackVarargs(s))` might have been the better design. Maybe for Nim version 2. :-)
Re: Why does the this code work?
I have tried to declare a `varargs[string | seq[string]]` but the compiler rejects it. It seems that for `varargs`, more strict rules apply to avoid some nasty problems. But there may exist other problematic cases as Araq said. Adding – in a future version – an explicit unpacking as he suggests would simplify things (and Python people would say that explicit is better than implicit). Personally, I would not care as I have never used this feature, but `unpackVarargs` is really an ugly name :-).
Re: Raylib Forever (4Nim)
Sorry for rather long delay: added 5 new examples from text and models categories. Project != dead. I guess, it't time to decide if heavier samples is needed - I hate adding aux files to this repository, yet demand is demand.
Re: soy nuevo en nim
Welcome!. Hay un grupo de [Chat Spanish](https://t.me/NimArgentina) , we also understand English.
Re: Why whitespace?
I'm really tired of these tabs vs. spaces discussions. There are good reasons for either approach, and I don't see why one approach would be _objectively_ better than the other. People who prefer the pro/con combination of tabs over the pro/con combination of spaces, prefer tabs. People who prefer the pro/con combination of spaces over the pro/con combination of tabs, prefer spaces. It's subjective. My recommendation is to follow a project's existing approach or, if you start a new project, the "community standard" approach (two spaces per indent for Nim). I think there are really more important things to discuss than tabs vs. spaces. (Yes, it's ironic that I still took the time to write this reply. ;-) )
Re: Why whitespace?
I dont like at all when I get this answer myself but ... Nim is open source with MIT license. If you cant live without tabs, fork it.
Re: Why whitespace?
Sure. I follow @sschwarzer's approach personally. The reasons for @Tutbadut or (someone else passionate about just one issue) **not** to fork something go back to network effects and the value of communities. Sometimes reiteration of pros & cons, etc. has value for new people.
Re: Why whitespace?
>From several decades of experience, tabs eventually always cause the >(potential) problems, but only rarely deliver the (potential) benefits. For the people who can't live without them, Nim provides [https://nim-lang.org/docs/filters.html](https://nim-lang.org/docs/filters.html) ; an `#? expandTabs(tabwidth:int)` filter can easily be written. Personally, I think it's a bad idea and would recommend against including such a filter in the standard library.
Re: Nim Community Survey 2019
The results of Nim Community Survey 2019 are now available at: [https://nim-lang.org/blog/2020/02/18/community-survey-results-2019.html](https://nim-lang.org/blog/2020/02/18/community-survey-results-2019.html)
RayCasting Problem
Hello! I just found about Nim some days ago and really like it, so to learn and do something cool with the language I decided to follow this incredible RayCasting tutorial [https://lodev.org/cgtutor/raycasting.html](https://lodev.org/cgtutor/raycasting.html) The code there is in C++ so I thought translating the code to Nim would be a good learning process. But I'm a having a problem and a I think it's related to type differences between C++ and Nim, the problem is: When I rotate (press A or D) the camera plane is not perpendicular anymore to the direction vector, I think the cause of this problem is the way sin() and cos() function works in Nim but I could be wrong. Example of what is happening: You can take a look at the code I wrote and the original C++ code here: [https://github.com/JustAntoRS/RayCasting-nim](https://github.com/JustAntoRS/RayCasting-nim) I know this is not a normal question but I'm getting desperate :S Thank you for taking the time to read this :)
Re: RayCasting Problem
Have you done the transfer with c2nim tool? Seems that you did at least manual modifications: time : uint32 = 0 oldTime : uint32 = 0 time = getTicks() var diff : uint32 = time - oldTime var frameTime : float = float(diff) / 1000.0 Run Time and oldTime is double in cpp code, such changes can make differences...
Re: RayCasting Problem
Nope, didn't use c2nim tool I did it by hand. Yes, there are some modification like that, because getTicks() return a uint32 value :) Thanks for the tip on using c2nim, I'm going to use it and see the result
Re: RayCasting Problem
c2nim can translate most basic C and even Cpp code, problems can be C macros and cpp classes, and somtimes it generates a div instead desired / for floating point division. But it save some work and avoids errors. When you change datatypes, you have to be careful, as float and integer arithmetic is different. Also note that in C int is often 4 byte, but in Nim int is 8 byte on 64 bit systems. For compatibility we have type cint which is the C int type.
Re: RayCasting Problem
I am pretty sure Nim's sin() and cos() work exact same way as the C++ ones. I never had an issue with them working differently. I think error is some place else. Some thing I noticed: * you use uint32 for time while C++ uses double. * you hard code w to 640 while C++ does not. * your right and left key is flipped from the C++ code. * C++ article warns about the problem you hare having. * you are doing one extra line should be 0 ..< 640 not 0..640 running your code i get: (61, 29) Error: type mismatch: got but expected 'array[0..3, int32]' I switched to using .byte for color values. I switched to using w and h like C++ code. I can't find the issue in you code, ... but I did my own C++ to nim conversion and it works without issues: import sdl2 import math var worldMap =[ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,2,2,2,2,2,0,0,0,0,3,0,3,0,3,0,0,0,1], [1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,3,0,0,0,3,0,0,0,1], [1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,2,2,0,2,2,0,0,0,0,3,0,3,0,3,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,4,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,4,0,0,0,0,5,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,4,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,4,0,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] ] proc main() = var posX: float = 22 # x and y start position posY: float = 12 dirX: float = -1 # initial direction vector dirY: float = 0 planeX: float = 0 # the 2d raycaster version of camera plane planeY: float = 0.66 time: float = 0 # time of current frame oldTime: float = 0 # time of previous frame w = 680 h = 420 window = createWindow("NIM RayCasting", 100,100,cint w,cint h, SDL_WINDOW_SHOWN or SDL_WINDOW_OPENGL) render = createRenderer(window, -1, Renderer_Accelerated or Renderer_PresentVsync) evt = sdl2.defaultEvent runGame = true while(runGame): render.setDrawColor(0,0,0,255) render.clear() for x in 0 ..< w: # calculate ray position and direction var cameraX = 2 * float(x) / float(w) - 1 # x-coordinate in camera space rayDirX = dirX + planeX * cameraX rayDirY = dirY + planeY * cameraX # which box of the map we're in mapX: int = int(floor(posX)) mapY: int = int(floor(posY)) # length of ray from current position to next x or y-side sideDistX: float sideDistY: float # length of ray from one x or y-side to next x or y-side deltaDistX = abs(1 / rayDirX) deltaDistY = abs(1 / rayDirY) perpWallDist: float # what direction to step in x or y-direction (either +1 or -1) stepX: int stepY: int hit = 0 # was there a wall hit? side: int # was a NS or a EW wall hit? # calculate step and initial sideDist if rayDirX < 0: stepX = -1 sideDistX = (posX - float(mapX)) * deltaDistX else: stepX = 1 sideDistX = (float(mapX) + 1.0 - posX) * deltaDistX if rayDirY < 0: stepY = -1 sideDistY = (posY - float(mapY)) * deltaDistY else: stepY = 1 sideDistY = (float(mapY) + 1.0 - posY) * deltaDistY # perform DDA while hit == 0: # jump to next map square, OR in x-direction, OR in y-direction if sideDistX < sideDistY: sideDistX += deltaDistX mapX += stepX side = 0 else: sideDistY += deltaDistY mapY += stepY side = 1 # Check if ray has hit a wall if worldMap[mapX][mapY] > 0: hit = 1 # Calculate distan
Re: RayCasting Problem
Here is your exact code fixed: [https://gist.github.com/treeform/bb3f4618d24535590043e264825f350d](https://gist.github.com/treeform/bb3f4618d24535590043e264825f350d) I recommend using getKeyboardState() like I did, other wise it moves only on key repeats.
Re: RayCasting Problem
Oh I diffed the two files and found the error: [https://dl3.pushbulletusercontent.com/XulFI2T1reCunTVRZEXwGlORRV28pdXi/image.png](https://dl3.pushbulletusercontent.com/XulFI2T1reCunTVRZEXwGlORRV28pdXi/image.png) You have one important "(" in the wrong place.
Re: Nim Community Survey 2019
Nice, thank you for the write up!
Re: RayCasting Problem
Thank you so much for taking the time to do this, you helped me learn a lot (and solved the problem) Thanks again :)
Re: Paranim and Pararules - my new gamedev libraries
Looks cool!
Re: Zig as C compiler for Nim. How to feed him the code
@SebastianM I tried it once, for experimental cross-compilation to ARM, seemed to work that one time for me. I don't think I have this exact configuration stored anywhere, but IIRC there's basically 2 steps to it: 1. use [nim.cfg to point Nim to a specific compiler](https://github.com/akavel/hellomello/blob/948e3ba205ca637eaca6438c86be25ed65dd10b4/nim.cfg) 2. provide appropriate [flags to Zig](https://lists.sr.ht/~andrewrk/ziglang/%20%3CCACZYt3T8jACL+3Z_NMW8yYvcJ+5oyP%3Dh1s2HHdDL_VxYQH5rzQ%40mail.gmail.com%3E) I hope to try and come back at some point in future, but don't suspect this to be soon. As to compiler's complaints, try your luck at asking on Zig's IRC and/or reporting on their github, Andrew Kelley seems to listen and be very open to discussion and helping, though he also has a lot to do, so I'd say your chances are maybe kinda 50/50?
reader macro
Is there any equivalent to a reader macro in nim? I wrote an expression parser and evaluator in nim which was very easy to do. To get better performance I thought that since nim has macro's I can leverage that without too much trouble. However, walking the AST of my expression parser to create nim AST (in macros) requires compile time proc's for recursion and so I have a chicken and egg problem that I can't seem to resolve.
Re: Nim Community Survey 2019
Thanks for the writeup! One thing I wanted to mention, is that the pair of "no" answers in "Have you made contributions" was a very weird choice in my opinion: I could either answer "No, but plan to", or "No and never will"; that's weird to me, as I'd like to answer "No, and currently don't plan to"; I definitely don't have strong negative opinion about contributing, I see it as possible I may one day, but I also currently just don't have plans to do that. I was super confused and didn't know which answer to chose, both seemed an equal lie. I don't remember which one I chose in the end, would be confused the same if I were to chose again.
Re: Nim Community Survey 2019
Kind of an off topic question but doesn’t Option[T] obviate the need of non-nillable types?
Re: reader macro
Do you mean something like [NPeg](https://github.com/zevv/npeg)?
I have a super doubt
Hello again, nim as the first programming language that I am learning which books or manuals I recommend reading to improve. I have basic knowledge of syntax. I have noticed that in this language you have to learn an example about pragma, pointer, tuple and much more.
Re: I have a super doubt
> nim as the first programming language that I am learning which books or > manuals I recommend reading ? to improve. See the Nim learning resources here: [https://nim-lang.org/learn.html](https://nim-lang.org/learn.html) Shameless plug for: [https://narimiran.github.io/nim-basics](https://narimiran.github.io/nim-basics)/ which is described on our learning page as: "For programming beginners. Covers all the basic topics, enough to make your first programming steps."
Can't pass varargs to echo
I can't tell if this is a bug or if there is a way to change this so it works. echo @["a", "b", "c"] # expected, prints @["a", "b", "c"] echo(varargs[string](@["a", "b", "c"])) # prints ["a", "b", "c"] Run This also doesn't cut it: proc a(x: varargs[string, `$`]) = echo x a "a", "b", "c" # prints ["a", "b", "c"] Run Is this a limitation of the `varargs[string, `$`]` type? I saw there was a PR that fixed overloading for these types but I don't think I saw anything mentioned about passing varargs between each other. Is there an issue open for this on the Nim github?
How to package a nim program in an APK file
Good morning I am trying to create my first .apk (android app). I have managed to write a simple console based app using the Nim scripting language. (Managed to compile and test it on a Docker ubuntu image - to create a Windows 10 executable, also a working MacOS binary that executes correctly.) However, now I want to see if I can compile and package my nim program to an APK that i can copy to an android device and run. I read this: [https://nim-lang.github.io/Nim/nimc.html#cross-compilation-for-android](https://nim-lang.github.io/Nim/nimc.html#cross-compilation-for-android) I managed to successfully run this : nim c -c --cpu:arm --os:android -d:androidNDK --noMain:on hello.nim But now I need guidance (exact steps to follow) to do the follow: (extract from the guide)? P.S I want to do this on the same Docker Ubuntu image (I connect to the container using VS Code) Add the generated C files to CMake build script in your Android project. Then do the final compile with Android Studio which uses Gradle to call CMake to compile the project.
Re: Zig as C compiler for Nim. How to feed him the code
Yeah, sure, but you need to build one yourself on Windows for example, Zig does it out of the box. There is no GCC built and ready to cross compile from Windows to Linux or Mac. There is musl.cc, but it is buggy as hell.