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
You are absolutely right - I must be doing something weird in a different part
to cause the 'uninitialized' warnings.
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
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
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(
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
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
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
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?
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
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
[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?
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
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.
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.
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
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
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
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?
Thanks @mratsim. In reality it is dispatching on an enum. The missing piece I
think is your Smth. /me goes and reads about static
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]
Awesome - thanks - I will give that a try.
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
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
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"
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
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
And I'm afraid your opinion is based on what's talked about, not on what
eventually gets done.
> 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
29 matches
Mail list logo