Comments (5)
Hello Stefan!
Thanks for your anwer!
Sorry for my hesitating with respond.
The information of version my Nim compiler:
Nim Compiler Version 2.0.0 [Windows: amd64]
Compiled at 2023-08-01
Copyright (c) 2006-2023 by Andreas Rumpf
I am using the scoop for many apps.
C:\Users<name>\source\nimProjct\StefanSalewski>scoop info nim
Name : nim
Description : A statically typed compiled systems programming language, which combines successful concepts from mature
languages like Python, Ada and Modula.
Version : 2.0.0
Bucket : main
Website : https://nim-lang.org
License : MIT
Updated at : 31.08.2023 13:25:07
Updated by : Rashil Gandhi
Installed : 2.0.0
Binaries : bin\nim.exe | bin\nimble.exe | bin\nimgrab.exe | bin\nimgrep.exe | bin\nimpretty.exe | bin\nimsuggest.exe | bin\vccexe.exe | bin\testament.exe
Suggestions : mingw-winlibs
Although, I use MSYS2 default version MSYS2 UCRT64. According to manual on
https://www.msys2.org/docs/environments/
there are recommendations :
UCRT (Universal C Runtime) is a newer version which is also used by Microsoft Visual Studio by default. It should work and behave as if the code was compiled with MSVC.
So, I guess we will expected new version of Nim for windows soon ...
:-)
Best regards!
from nimprogrammingbook.
Thanks for reporting.
Actually, I think I never tested the combination of the new default object values introduced for Nim 2.0 in conjunction with the std/with package. I will test it soon. Please let us know your Nim compiler version (execute "nim -v" in a terminal window.)
from nimprogrammingbook.
You are right! And it is not related to std/with package.
For $ nim -v
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2023-09-13
the default values for objects are only used, when the object variable is created with Nim's constructor syntax as in
#import std/with
type
Computer = object
freeShipping: bool = true
manufacturer: string = "bananas"
cpu: string
powerConsumption: float
ram: int # GB
ssd: int # GB
quantity: int = 7
price: float = 1000.0
proc main =
var
#comp: Computer # no defaults!
#comp = Computer()
comp = Computer(cpu: "AMD Skylake")
echo comp
#with comp:
# cpu = "Intel i7"
# powerConsumption = 17
# ram = 32
# ssd = 1024
# quantity = 3
# price = 499.99
#echo comp
main()
Both comp = Computer() and comp = Computer(cpu: "AMD Skylake") works.
Actually I missed that fact, I will make this more clear in the book. I am currently not sure if this behaviour is intended. I guess Mr. Rumpf has good reasons for this behaviour.
Also note, that Nim 2.0 now has the new experimental pragma {.experimental: "strictDefs".}, see https://nimprogrammingbook.com/book/nimprogramming_rouge_molokai.html#_strictdefs
When applying that pragma, the compiler shows a warning for a plain comp: Computer
/tmp/hhh/t.nim(22, 8) Warning: use explicit initialization of 'comp' for clarity [Uninit]
from nimprogrammingbook.
Yes, from the current version of the language manual we learn that for a plain variable declaration like "comp: Computer" the defaults are not used: https://nim-lang.github.io/Nim/manual.html#types-default-values-for-object-fields
I will try to fix that soon in the book.
from nimprogrammingbook.
Fixed.
from nimprogrammingbook.
Related Issues (17)
- Typo HOT 1
- Permission to translate the book HOT 3
- Expand section on templates HOT 2
- License? HOT 13
- maybe an effecient way to broadcast message in the chat server application HOT 4
- executable examples HOT 5
- Some thoughts about async HOT 3
- Broken URL HOT 2
- Wrong word HOT 5
- [FR] Dark theme option HOT 4
- The tail insert of linked object HOT 1
- Debug code left in regex example HOT 2
- Needs introduction to analysis of algorithms HOT 1
- Minor update to the book for nims 2.0 release as of today (01.08.2023) HOT 8
- Re: Permission to use the book in YouTube video series. HOT 3
- Use of word "concept" in place of "defer" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nimprogrammingbook.