Re: Nim Compiler Documentation
i have not, i will take a look at that now, thank you
Nim Compiler Documentation
This is just a simple question. I have started looking at the nim compiler source and trying to implement my own backend for nim. Is there not documentation for the nim compiler or is it reserved for developers? I might just not have found where it is though.
Re: Error: unhandled exception: paramCount is not implemented on Nintendo Switch [OSError]
thanks i will do that
Re: Error: unhandled exception: paramCount is not implemented on Nintendo Switch [OSError]
If there is no quick fix, i guess i can patch the file. but i just thought id show this because it is weird
Error: unhandled exception: paramCount is not implemented on Nintendo Switch [OSError]
I got this error msg from this code #The file is get_saves.nims import parseopt import "check_installed.nims" echo check_installed.exists var ops = initOptParser() while true: ops.next case ops.kind of cmdEnd: break of cmdLongOption, cmdShortOption: echo "got and option" of cmdArgument: echo "got and argument" Run Here is the other file "check_installed.nims" from os import `/` mode = ScriptMode.Verbose var user_profile = getEnv("userprofile") let minecraftDir = user_profile / "AppData/Roaming/.minecraft" var exists* = false if dirExists(minecraftDir): exists = true echo "The Java Edition of minecraft has been installed on this system" echo "We will now be creating a directory: .resourceManager in your UserProfile directory( " & user_profile & " )" else: echo "The Java Edition of minecraft has not been installed on this system" echo "Exiting..." quit(0) Run This might be a little spammy, but I am just trying to make a simple script that checks if minecraft is installed, grabs my save folder and allows me to manage resource packs and datapacks from another area using a CLI. This is the output I get from running "nim get_saves.nims" {{USERNAME}}@{{COMPUTER_NAME}} ~/Documents/GitHub/CodeDump/minecraft (master) $ nim get_saves.nims Hint: used config file 'C:\Users\{{USERNAME}}\.choosenim\toolchains\nim-1.2.0\config\nim.cfg' [Conf] The Java Edition of minecraft has been installed on this system We will now be creating a directory: .resourceManager in your UserProfile directory( C:\Users\{{USERNAME}} ) true stack trace: (most recent call last) C:\Users\{{USERNAME}}\Documents\GitHub\CodeDump\minecraft\get_saves.nims(4, 24) C:\Users\{{USERNAME}}\.choosenim\toolchains\nim-1.2.0\lib\pure\parseopt.nim(229, 49) initOptParser C:\Users\{{USERNAME}}\.choosenim\toolchains\nim-1.2.0\lib\pure\os.nim(2693, 5) paramCount C:\Users\{{USERNAME}}\.choosenim\toolchains\nim-1.2.0\lib\pure\os.nim(2693, 5) Error: unhandled exception: paramCount is not implemented on Nintendo Switch [OSError] Run I am on a Windows 10 OS and i wonder if this is some kind of bug
examples or documentation of Source Code filters
Hi, sorry I am looking into the source code filters for nim and it is actually kind of hard to figure out what a good use case for them is, or if they have any uses besides just generating xml. I was just wondering if anyone had any examples of how they have used them in their projects or anywhere to find more information on them in action so I can see what I can do with them. it would be greatly appreciated. **Thanks**
Re: unable to deference pointer and assign? Nim 1.0.6
ah thank you so much
unable to deference pointer and assign? Nim 1.0.6
So I'm just messing around and from what I understand this code should be fine, but for some reason I'm getting an error. I am wondering if there is something I don't understand about pointers in Nim and how to use them proc newLead[T](oldData:T):Lead = #copy the data if the old data is not mutable result.desc = T.name result.data = alloc0(sizeof(T)) result.data[] = 10 #THIS is where im getting the error at the `=`, also here we are assuming T == int echo result.data.repr dealloc(result.data) ##this is just to clean up because im testing Run
Re: Is allowing non-matching types for assignment overloading in the development timeline?
Wow thanks, I didn't know about this use of converters. I can simplify a lot it code with this!
Re: Auto import file with config.nims
Oh I figured it out the --import argument in the computer
Re: Auto import file with config.nims
Sorry, I want to do something like. Include a module automatically to my project without having to call import in every file. Like the standard library. I'm wondering if I can do that using nimscript or something else
Auto import file with config.nims
Might be a noobish question but I've googled for a while and I can't find anything on being able to automatically import files in a project, like the system module
Re: FOSDEM "Metaprogramming in Nim" talk now online
Nice, for the amount of time you had it was a good taste of what nim can do. Not really how to do it but it should get people interested in that
Re: Deleting a certain value from a sequence
I like @Araq s suggestion as well lol
Re: ability to undefine a symbol?
Fair enough thanks for the time
ability to undefine a symbol?
Is there anyway to undefine a symbol in nim using macros? like in C you can do #define SYMBOL_NAME #undefine SYMBOL_NAME Run
Re: Associating data to types
you can also hold data on types by using static though then it needs to be known at compileTime type typeWithData[data:static[auto]] = distinct object var a:typeWithData[10] echo a.data #outputs 10 Run
Re: recommendation for simple graphics lib?
thanks for the suggestions, as for my question not being smart. I didn't say because I don't know exactly what I plan to do. I am researching options at the moment.
Re: Should we get rid of style insensitivity?
I think a vote is good, will be voting no for the change though
Re: Compiler plugins?
What can they do??? Is there documentation?
Compiler plugins?
Digging up a dead thread, is there anybody who knows exactly what you need to do to make a compiler plugin?
Re: Nim source equivalent to C #define
i just want to say, i love how many good options nim has for such a simple thing. Nim -- a buffet for the programmers taste
Re: Nim source equivalent to C #define
const Thing = 0 when declared(Thing): const otherThing = 0 when declared(otherThing): echo "we are here" Run this works
a small change to macros.getCustomPragmaVal
real quick here is the code for the change macro getCustomPragmaVal*(n: typed, cp: typed{nkSym}): untyped = let pragmaNode = customPragmaNode(n) result = newTree(nnkPar) for p in pragmaNode: if p.kind in nnkPragmaCallKinds and p.len > 0 and p[0].kind == nnkSym and p[0] == cp: if p.len > 1: for arg in 1..(p.len-1): result.add p[arg] return else: return p[1] error(n.repr & " doesn't have a pragma named " & cp.repr()) # returning an empty node results in most cases in a cryptic error, Run and the original for reference macro getCustomPragmaVal*(n: typed, cp: typed{nkSym}): untyped = let pragmaNode = customPragmaNode(n) for p in pragmaNode: if p.kind in nnkPragmaCallKinds and p.len > 0 and p[0].kind == nnkSym and p[0] == cp: return p[1] error(n.repr & " doesn't have a pragma named " & cp.repr()) # returning an empty node results in most cases in a cryptic error, Run now running the original version with this code template test_prag(d:int,b:int) {.pragma.} type test_type {.tprag(10,20).} = int var a:test_type = 0 echo a.getCustomPragmaVal(tprag) # this outputs 10, there is no way to get the second value that I know of Run but with the change it would output (Field0: 10, Field1: 20) Run ill be using this myself, but I wanted to get others opinions
Re: How to check an auto type parameter in a proce
the module typetraits might be able to help you
Re: Is there any untyped list data type in Nim ?, like in python.
I might be able to help > 1.Node is a ref object. Yes, it is. Acting like a pointer (guessing at the inner workings of this) with the statement case kind: NodeKind # the ``kind`` field is the discriminator of nkInt: intVal: int of nkFloat: floatVal: float of nkString: strVal: string Run kind is declared in the type like a variable and the compiler will create separate "Node types" depending on whether or not it is nkInt, nkFloat, or nkString, I assume. so > 2.kind is not declared in this type. Or this case statement is declaring kind > as a varibale, i don't know. kind is declared as a variable > 3\. If the latter is true then, case statement is checking the data type and > allow us to use this type for required data type. > > 4.And in the last portion, you have declared a varibale "n" which contains a > seq of nodes. yes **If I am wrong please let me know, I 'm just really starting to learn Nim myself**
Re: How to check an auto type parameter in a proce
Do you need to know the type at runtime?
Re: a funny compiler crash
looks like there was some other problem. you are right that example now works I assume i was using a 32 bit version of gcc or nim or i wasnt as up to date as i thought I will close the issue
Re: a funny compiler crash
ah, yeah fixed the indentation and case mistakes, same problem though made an issue ticket on github [https://github.com/nim-lang/Nim/issues/9054](https://github.com/nim-lang/Nim/issues/9054)
Re: a funny compiler crash
Might be because I'm using 0.18.0, I will see
Re: a funny compiler crash
Os and compiler?
Re: shorthand if statement
Sometimes, I just like astetics ok guys
Re: shorthand if statement
You realize this evaluates both statements regardless of the condition Run Evaluated yes with a bit different syntax? Run Yes
shorthand if statement
**_IF_** you have been looking for a shorthand if statement here is some code type pair*[T] = (T,T) template `|`*[A](a:A,b:A):pair[A] = (a,b) template `?`*[T](cond:bool,res:pair[T]):untyped = if cond: res[0] else: res[1] Run
Re: shorthand if statement
oh how to use it var a = 0==1 ? 1|2 # == 2 var b = 0==0? 1|2 # == 1 #must give the same types for the result Run
Re: shorthand if statement
oh how to use it var a = 0==1 ? 1|2 # == 2 var b = 0==0? 1|2 # == 1 #must give the same types for the result Run
Re: a funny compiler crash
will do
Re: a funny compiler crash
I'm not sure if its just my computer, but that crashes something. my program won't output anything now
Exploring namespaces support in Nim
going to dig up an old thread, I would still love to see from module import type foo Run
Re: a funny compiler crash
came up with a fix, so you cannot supply different types type same[T] = T Gen[A:auto,val:static[same[A]]] = same[A] Run
a funny compiler crash
So today i was messing around with Generic types and I found something that I think would be considered "Undefined behavior". I thought I would just share it here in case anyone else gets the same idea. type Gen[val:static[auto]] = auto true_t = Gen[true] var a:true_t = "hello" var b:true_t = 10 proc c(a:true_t):void = echo a c(a) c(b) Run **the output here is understandable** Hint: system [Processing] Hint: test [Processing] Error: internal error: (filename: "semtypes.nim", line: 908) No stack traceback available To create a stacktrace, rerun compilation with ./koch temp c Run I would like to explain why I think this happens. I think that the error occurs because when declaring Gen[ **whatever this may be** ] I actually turn **true_t** into two distinct types, and when executing the _proc_ **c** it would probably expect the type **string** because that would be what the first actual definition of the _proc_ does, or maybe because it is an ambiguous proc, though it doesn't really seem to catch onto that and just crashes. It made me laugh a little so I thought I would share. **Thanks for reading**
Re: Returning from Concepts
alright, thank you very much. Just another question do you know if its planned for V1 or working in devl?
Returning from Concepts
I have just started playing around with concepts, but I'm very confused about what this return statement is used for with the generics converters I have tried to do the exact same example and nothing seems to work. though I don't understand what should be happening anyway. Any help would be greatly appreciated. [https://nim-lang.org/docs/manual.html#generics-converter-type-classes](https://nim-lang.org/docs/manual.html#generics-converter-type-classes)
Re: --stdout question
that seems useless
--stdout question
Just a quick question, the compiler flag --stdout says it outputs to stdout, am I assuming that it gives the resulting binary to stdout incorrectly?
Re: quick question about macros
thank you very much
Nim as a run time interpreter?
I am looking for a way to evaluate Nim at run time, is there anything to recommend?
Re: Why is my destructor not called?
> I am on Windows 10, Nim Compiler Version 0.18.0 [Windows: i386], MinGW GCC. I don't know if that is just for windows 10, I am on ubuntu with 0.18.0 and I am getting the same thing though my code is a little different {.experimental.} type thing = object x:int p:pointer proc `=destroy`(o:thing):void = if o.p != nil: dealloc o.p echo "destroyed" proc op():thing = result = thing(x:10,p:alloc(1)) proc work(o:thing):void= echo o proc main() = let t= op() work(t) main() Hint: used config file '/etc/nim.cfg' [Conf] Hint: system [Processing] Hint: destruct [Processing] CC: destruct Hint: [Link] Hint: operation successful (11723 lines compiled; 0.185 sec total; 22.32MiB peakmem; Debug Build) [SuccessX] Hint: /home/User/Desktop/nim/tests/destruct [Exec] (x: 10, p: ...)
Re: Delaying macro expansion
well this isn't exactly delaying macro expansion I found a work around that works for what I want I changed getRNG into a static proc static: proc getRNGS():uint32 = mz = (36969u32 * mz and high(uint32) + (mz shr 32)) #echo tobin(mz.int,64) mw = (18000u32 * mw and high(uint32) + (mw shr 32)) if mw == 0: mw = 18000 if mz == 0: mz = 36969 return ((mz shl 16) + mw) and use that in both my regular macros macro getRNG*() = getRNGS() macro getRNGF*():float = let fh = high(uint32) var fr = getRNGS() return fr.float / fh.float I don't think this actually creates any functions in your C code, just values and that is what I am aiming for with this
Delaying macro expansion
So I am making just a small compile time RNG and having a few problems macro getRNGF*():float = let fh = high(uint32) let fr = getRNG() return fr.float / fh.float the getRNG proc is another macro that affects some static variables declared earlier, but the problem is that nim expands the macro and gives me a static value that doesn't change with each call. I will include the getRNG proc and the variables it affects static: var mz:uint32 = 36969 var mw:uint32 = 18000 macro getRNG*():uint32= mz = (36969u32 * mz and high(uint32) + (mz shr 32)) mw = (18000u32 * mw and high(uint32) + (mw shr 32)) if mw == 0: mw = 18000 if mz == 0: mz = 36969 return (mz shl 16) + mw so my question is if there is anyway to delay macro expansion or some work around to make getRNG's return value not static
Re: Community name?
nimeks, like planet namek in dragonball z
Re: static macro
you are right, thank you
Re: static macro
alright thank you, that narrows my search
static macro
Just a quick question, I have been looking for where the static macro is defined so I can look at how it is implemented does anyone have an idea of where that would be?
Re: two questions about static
yeah I have noticed that too, might be a bug... I wouldn't know how to go about stating that though
Re: two questions about static
Awesome Thank you, that worked great
Re: Wow. It all 'just works'
I have started using nim just recently as well, and I can agree with you this language is great! My brother is the one who let me know about this language because he has been watching me do experiments with compiler abuse in C++ (which if I wanted to do anything fun I had to abuse the compiler), but Nim lets me do very cool and fun things without having to find hacky work arounds. I am in love lol
Re: two questions about static
Here I have made an example of what is happening #module A static: var test=0 proc test_proc(): void {.discardable,compileTime.} = var a = test echo a #module B import A static: test_proc() this will give me an "Error: cannot evaluate at compile time: test" for line 6 of module A
Re: two questions about static
thanks, I think i learned I have a completely different problem then what I thought was going on, I will try to figure it out before I bother more people about it, but what is happening is that a proc I have made is using static variables defined in one module, but when I export that proc and use it in another module I am getting an error saying it cannot evaluate my static variable at compile time. that is why I thought the issue was that they didn't export out of modules
two questions about static
So just to start, I am very new to nim I started reading about it and programming in it 4 days ago. I understand that using static like this static: var some_variable = 10 evaluates the statement at compile time and uses the Nim VM to do that my questions are, is there a way to use these static variables outside of the module they are defined in, and does anyone know where static is defined so i can look at how it is coded so that if my first question results in no I can possibly recreate a version of static that could