Re: On exceptions (again)

2018-07-20 Thread rayman22201
Dom, It seems you really don't want Nim to compete with Rust; why? I actually came to Nim looking for a better Rust, or more generally a better systems language that isn't C++. My intuition tells me I'm not the only one. I think there is a reasonable subset of the community that wants this. Then

Re: NEWBIE - generics issue

2018-07-20 Thread yatesco
You are absolutely right - I must be doing something weird in a different part to cause the 'uninitialized' warnings.

Re: Macro - whileSome: none:

2018-07-20 Thread LeuGim
If you want the second keyword be "none" and not "do", you can use 2 templates/macros and a variable to pass state between them, like: var whileSomeNone: bool template whileSome*(condition: typed, body: untyped) = whileSomeNone = condition if whileSomeNone: wh

Re: NEWBIE - generics issue

2018-07-20 Thread LeuGim
I get no compiler error for your example (maybe there is some problem in your full code), just a run-time error from dispatcher, because you didn't allocate the object for `a` (via `new`, as the variable is of reference (pointer) type, not object itself). The full code: type

Re: NEWBIE - generics issue

2018-07-20 Thread yatesco
Actually, using dynamic dispatch forces a chicken and egg situation, as I want the dynamic dispatch method to construct (from JSON) the thing it is switching on! The following represents my conundrum: method foo(s: SpecialisedTA, node: JsonNode) = s.abc = node["abc"].getStr(

Re: On exceptions (again)

2018-07-20 Thread bpr
Which space? Systems programming? C++ does that and more. C++ is also used in scientific computing, and while Rust will probably attract a few users there, I think most will find it less useful there. Nim has overloading and good macros. C++ templates are very powerful, and Rust generics are not

Re: Exceptions don't work in function

2018-07-20 Thread Serasar
Thanks. Error I get is: D:\autorun.exe.cypher Traceback (most recent call last) crypto.nim(15) encryptFile streams.nim(154) write streams.nim(130) writeData SIGSEGV: Illegal storage access. (Attempt to read from nil?) Basically when I

Re: Exceptions don't work in function

2018-07-20 Thread mratsim
You should release resources acquired on exceptions, here you leave a file handle hanging. I'm pretty sure the error you get is related to that. Reworked code which should properly cleanup after itself proc encryptFile(key, key_hash, input_file, output_file: string) = #var buf

Re: On exceptions (again)

2018-07-20 Thread dom96
I think it would be very difficult for us right now to follow what Rust does and attract users away from it. Is there a reason that you think Rust isn't a serious competitor in this space?

Re: Macro - whileSome: none:

2018-07-20 Thread mratsim
You can do anything with macros, but in your case, you need the do notation like Hlaaftana showed and templates are enough: proc yes(): bool = true proc no(): bool = false template myPattern(proc1, proc2, proc3: untyped): untyped = var wasProc2Called = false

Re: Macro - whileSome: none:

2018-07-20 Thread Hlaaftana
You can add multiple statement lists to templates with `do`: template test(a, b, c): untyped = c a b test: echo "2" do: echo "3" do: echo "1" Run

Exceptions don't work in function

2018-07-20 Thread Serasar
[https://bpaste.net/show/f955409523a7](https://bpaste.net/show/f955409523a7) This function still crashes the whole program on error despite being wrapped in except try block. What to do?

Re: On exceptions (again)

2018-07-20 Thread bpr
I applaud this new direction. I want to be able to use Nim as a systems programming language, to compete with C++. I like Rust, but the real competition is C++, which is used in many areas. Bjarne Stroustrup said, amongst other things, "I'm convinced that you could design a language about a ten

Non-blocking keyboard input

2018-07-20 Thread markprocess
Thanks all. For the short term on just raspbian spawn(getch()) works well. Eventually I'll want key up and key down. Thanks for the repo refs. Mark.

Re: Macro - whileSome: none:

2018-07-20 Thread mashingan
All of procs are untyped, so those don't get resolved during transformation. You can put boolean expression in place of proc1, but afaik, you can only have statement sequences in proc3 in template.

Re: Macro - whileSome: none:

2018-07-20 Thread markprocess
Thanks, but I think your solution always calls proc3. It should only be called if proc2 is never called. That's ok. I'm trying to determine if macros can implement procedural control flow structures that have extra colon-clauses. I actually want to replace proc1() with a bool expression and pro

Re: NEWBIE - generics issue

2018-07-20 Thread yatesco
After experimenting, I learnt the following: * the static keyword informs the compiler that the value is known at compile time * object invariants can't have the same property in each case of match * runtime dispatch uses dispatch trees which are more performant than the more common i

Re: Macro - whileSome: none:

2018-07-20 Thread mratsim
You don't need a macro. while true: if proc1(): proc2() else: proc3() break Run If the pattern is recurrent you can use template: template myPattern(proc1, proc2, proc3: untyped): untyped = while true: if p

Macro - whileSome: none:

2018-07-20 Thread markprocess
Can a macro implement whileSome proc1(): proc2() none: proc3() where proc2 is called while proc1() is true but proc3 is called if proc1() evaluates false on the first attempted iteration?

Re: NEWBIE - generics issue

2018-07-20 Thread yatesco
Thanks @mratsim. In reality it is dispatching on an enum. The missing piece I think is your Smth. /me goes and reads about static

Re: NEWBIE - generics issue

2018-07-20 Thread mratsim
Are the types known at compile-time or do they depend on runtime data. Otherwise you can do compile-time dispatch: type Something[T] = object a: int special: T SpecialisedTA = object c: int SpecialisedA = Something[SpecialisedTA]

Re: NEWBIE - generics issue

2018-07-20 Thread yatesco
Awesome - thanks - I will give that a try.

Re: NEWBIE - generics issue

2018-07-20 Thread yglukhov
The proc needs to return a concrete type, while you're trying to return Something, which is a type class. You'll be better here with either runtime dispatch (`ref object` hierarchy + `methods`) or variant objects. # runtime dispatch type Something = object a: int

NEWBIE - generics issue

2018-07-20 Thread yatesco
Hi all, I have a Something which takes a specialised thing. I then have a bunch of types that are specialised Something`s. I then want a proc which will return any of the `SpecialisedSomethings. Code will make it really clear (please forgive syntax errors): type Something[T

Re: string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-20 Thread lscrd
The copy doesn’t worry me if the behavior is consistent. But, there is something I don’t understand. In this program proc p() = let x = "abc" Run there is a string copy (and an allocation) for "x". But in this one proc p() = var a = "abc"

Re: Compiler hangs on linking

2018-07-20 Thread jyapayne
Ah, I found this comment in osprocs.nim: proc waitForExit*(p: Process, timeout: int = -1): int {.rtl, extern: "nosp$1", tags: [].} ## waits for the process to finish and returns `p`'s error code. ## ## **Warning**: Be careful when using waitForExit for processe

Re: Compiler hangs on linking

2018-07-20 Thread jyapayne
Or perhaps maybe one of these lines would be a better location? (in extccomp.nim, line 746): else: tryExceptOSErrorMessage(conf, "invocation of external compiler program failed."): if optListCmd in conf.globalOptions or conf.verbosity > 1: res = execPro

Re: On exceptions (again)

2018-07-20 Thread Araq
And I'm afraid your opinion is based on what's talked about, not on what eventually gets done.

Re: string literals should not allocate; should allocate in ROM an extra `\0`

2018-07-20 Thread Araq
> eg: so the following will allocate 10 times (in D: 0 times): Put it in a `main` proc. Allocates 0 times then. ;-) > in my idea of an ideal string type, null termination would only occur for > string literals (not on slices). I'll write more on this later, it requires a > full design writeup t