How to create a mutable object prefrably without ref

2022-11-30 Thread halloleo
Very helpful detail, @Stefan_Salewski. I have read the main chapters of Nim in Action which was good, but I have forgotten quite a bit and it is always good to find out what is "nimonic"... So thanks again!

How to create a mutable object prefrably without ref

2022-11-27 Thread Stefan_Salewski
> or ref objects Use ref objects only when you really need them, see e.g. my post in . I think that is the advice of most people, but I know in the past, we had a few people, at least one I think, which said they would always use ref objects. But that was 4 or

How to create a mutable object prefrably without ref

2022-11-27 Thread halloleo
Thanks @amadan and @Stefan_Salewski! Interesting! In the Nim community what is more commonly used when you want to create a class-like "thing", i.e. a data structure with a fix number of fields and a couple of methods operating on this structure? Objects handed into the methods as `var`s or `re

How to create a mutable object prefrably without ref

2022-11-24 Thread amadan
You can make the parameter in the function be bar type MyObj = object prop: string proc doitWithObj(myObj: var MyObj) = myObj.prop = "hallo" var x: MyObj x = MyObj() x.prop = "bon jour" echo x.prop doitWithObj((x) e

How to create a mutable object prefrably without ref

2022-11-24 Thread halloleo
I need some objects where the properties can be changed in multiple procedures. So I chose the implementation with `ref`: type MyObj = ref object prop: string proc doitWithObj(myObj: MyObj) = myObj.prop = "hallo" var x: MyObj x = MyObj

How to create a mutable object prefrably without ref

2022-11-24 Thread Stefan_Salewski
Use var parameters for your procs. And maybe read a tutorial or a book :-)