doesn't compile. i tried fixing the errors, but each time a new pops up. you
probably pushed old version or missed some file.
Anyone has a short how to how would one go about it ?
The issue for me is that posts about `--gc:arc` still reference concepts like
`sink` and `lent` parameters. These are described in [the post about
destructors](https://github.com/nim-lang/Nim/blob/devel/doc/destructors.rst#nim-destructors-and-move-semantics),
but, well, that document is not
> Yet I am new to Nim (coming from C, C++, Python) and wonder, what this.x then
> will mean in my Euler class. Is it the pointer to the method x or is it the
> attribute x?
I tried Skaruts's code in the [Nim
playground](https://play.nim-lang.org/#ix=27xV) and it seems accessing
`Euler(x:
According to the upcoming Official 21st Century Universal Code Style Guide, the
correct way to write this is:
type
Euler* = object
x, y, z, a, b. c: float64
method x( this: Euler): float64 =
return this.x
Run
Leading and
[https://irclogs.nim-lang.org/23-12-2019.html#16:10:45](https://irclogs.nim-lang.org/23-12-2019.html#16:10:45)
16:10:45 FromDiscord the best simd wrapper is here:
[https://github.com/numforge/laser/blob/master/laser/simd.nim](https://github.com/numforge/laser/blob/master/laser/simd.nim)
But
> How underscores improve readability?
The idea is that you could use `_name` for a private field and `name` for an
accessor proc. It's a nice convention. So I agree, it doesn't improve
readability directly, or maybe just in the sense that you avoid less readable
names like my `privateX`
That's odd. Can you revert any changes you made and show me the compiler
errors? Also, what version of the Nim compiler are you using?
I tried compiling it in a Linux VM that initially didn't have Nim 1.0.4 in it
and it was successful, so the error message will be very helpful in figuring
out
Hi,
Is it possible to evaluate function body, or some other code block, in a
different context, e.g. consider this simple repro:
import macros
# this macro evaluates function body in a different context
# and prints result at compile time
macro eval1(fun: untyped):
A few days ago I reported about not understanding the destructors document on
the #nim @ freenode.net IRC channel. Unfortunately, as a weekend developer
(just for fun), I will have to close my eyes to such changes until they are
applied (something that scares).
> there is no reason to despair and stop developing Nim libraries.
Thank you, I ensure you that I do not despair, but I feel a little lost with
all the recent changes :-)
@sschwarzer: You hit the point, thank you!
But Nim wont use underscore for private vs public. How underscores improve
readability?.
`let __variable = 42` Vs `let variable = 42`.
@Skaruts: Alas, Nim doesn't accept this code:
### Define the class
#
type
Euler* = object
x, y, z, a, b, c: float64
method dump( self: Euler): string =
return "x"
method print( self: Euler): void =
echo( self.x, ", ",
This is awesome and I look forward to seeing where it goes. Projects like these
that can exponentially expand the ecosystem are very cool.
@sshw
> I tried Skaruts's code in the Nim playground and it seems accessing Euler(x:
> 3.0).x doesn't call the method, but returns the field value.
That's because you're accessing it from within the same module. I didn't think
of mentioning this before, but the trick will only work if you
For me to understand it, I considered Nim's copy semantics. Find an variable
inside a procedure that gets copied and apply sink to the proc's parameter. If
the argument is not used after the call, then it will be moved to the proc (or
better the memory location it points to), else a copy is
Seems to be conflicting with property `x`. But you're also calling `x` as a
method with a parameter, when the method that takes a parameter is `x=`. What
you want there is something more like:
euler.`x=`(42)# I suppose using back-ticks is advisable, as sometimes
this doesn't
How I would go about it:
* Figure out which version/instruction set of SIMD you want. If you are
making it for games steam survey can help:
Searching `tkEnd` in the compiler code gives only enum definitions, and the
word `end` is shown as a keyword in the manual, where it says unused keywords
are reserved for future features of the language. I remember `atomic` and
`shared` also being unused keywords that got removed eventually, so
> Why does this proc yield `Error: 'crossover' can have side effects`?
You are using `rand` which makes this proc non-deterministic, i.e. you will not
always get the same result for the same input.
Sorry if this is a dumb question; I just started my first real Nim project a
few days ago. Why does this proc yield Error: 'crossover' can have side effects?
import random
func crossover*[T](parent_1: seq[T], parent_2: seq[T]): (seq[T], seq[T]) =
## The default
If what you say is true, your 64bit build of Nim is broken... :-/ Please report
it on github.
Having _ as initial variable name only acts as visual cue, it's not related to
readability or anything.
Having clear/distinct/helpful/noisy visual cues doesn't change the fact whether
the code is well written or not.
What actually helpful is good structure and sane APIs. Whatever the variable
rand proc has side effect.
@Libman
I think an MC Hammer emoji would be more appropriate than your smiling poop
emoji... If only one existed... 樂
Surprisingly `begin` is not reserved or I would think it's a hidden plot for
Pascal/Ada to takeover Nim.
**end** is used (and required for `if`) in the [Nim Source Code
Filters](https://nim-lang.github.io/Nim/filters).
Ah, right. The version of nimgame2 you currently have is either not from the
devel branch, or it was from the devel branch but is now too old.
Just run `nimble install nimgame2@#devel` to fix that. You'll also need to
update sdl2_nim or else you'll run into [this
I am fairly new using karax. Playing with it, I tried to make elements spawn by
clicking a button. The following approach works fine but it throws an exception
ruining other karax components.
type
Selector = ref object
selected: kstring
...
last-gardener/src/pattern.nim(73, 16) Error: type mismatch: got
this one can be fixed by importing random, but then this error pops up.
last-gardener/src/scenes.nim(104, 9) Error: attempting to call undeclared
routine: 'initScene'
At first I used it because it seemed like an easy way to run the compiler on
save. But I switched to a method like @treeform described and I prefer that now.
> People don't complain about Python not allowing unicode characters as
> identifiers (something possible in Julia for example).
For the record, Python 3 _does_ allow unicode characters in identifiers. :-)
$ python3
Python 3.7.5 (default, Oct 17 2019, 12:09:47)
[GCC 9.2.1
Also, in case you're gonna end up doing any OOP in Nim, [this blog
post](https://matthiashager.com/nim-object-oriented-programming) helped me
quite a bit.
And before Python 3.0, there were probably people who did complain about their
absence. Rationalizations tend to be disingenuous, and there's a lot of that
here. Not that it matters, because Nim's handling--and lack of handling--of
underscores is not something that's going to change.
The following code is compiling without error on Linux 64 bits but generates an
`unknown symbol 'initE'` on Linux 32 bits.
module `a.nim`
proc algo*[T] =
proc a: T =
result = initE[T]()
result += 3
echo "algo", a()
Run
Don't use the same name for the field and the proc. Also don't use `methods`
when you don't need inheritance/dynamic dispatch it's a pessimization. Use
`proc` instead.
Lastly, naming conventions allow consistency within a language and depends on
many factors. People don't complain about Python
It's probably way too late for this but I always had the idea of allowing (but
not requiring) explicit `end if` etc markers:
proc dasDing(arg: int): string =
if arg == 0:
result = "0"
else:
result = "not 0"
end if
end proc
Run
I'm not exactly sure what you mean but I assumed that:
* by context you mean scope, if so you can use a block statement
* for compile-tie printing you can use `static`
* You wanted to see 84 printed and not 48
import macros
# this macro evaluates function body in a
Genuinely curious, why would VS Code tasks be preferable than a nimble file?
You can't run VS Code tasks in CI for example which ultimately your local
testing should be a mirror of.
> In short: I am lost. I don't know which mechanism will be used in place of a
> GC. I don't know if that requires me, as a library author, to introduce sink
> or lent parameters, which I still do not understand. (related to this, I have
> stopped writing Nim libraries, because I am unsure
Well there are
[https://github.com/jackmott/nim_simd](https://github.com/jackmott/nim_simd)
and
[https://github.com/bsegovia/simd.nim](https://github.com/bsegovia/simd.nim)
for some SIMD wrapping
_At least_ in Python, an underscore at the beginning of a variable means it's
private and shouldn't be accessed by client code.
At some point I was wondering the same as the OP, but I think in Nim you just
use the `*` suffix to distinguish "public" and "private" fields:
type
A workaround, thank you.
Yet I am new to Nim (coming from C, C++, Python) and wonder, what this.x then
will mean in my Euler class. Is it the pointer to the method x or is it the
attribute x?
I consider this insensitivity being a severe restriction, the lang designers
are pulling the users'
The comparison with a leading comma is misleading. It's not only about scope
(private vs public) but about readability, when a leading underscore is used.
Paul
45 matches
Mail list logo