Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Nim2
* Scala


[ edit | logout ]
[ sandbox | passwd ]

const example

We've already seen const here.

The value of a const variable is determined at compile tile.

Consider the following example:

proc get_string(): string =
  result = ""
  echo "Generating the string..."
  result.add("hello ")
  result.add("nim")

const TEXT = get_string()

echo TEXT

Let's compile and execute it:

$ nim c --hints:off --warnings:off main.nim
Generating the string...

$ ./main
hello nim

Notice that the text "Generating the string…" only appears during the compilation.

The compiler calls get_string() and figures out its return value. Thus the const line will be transformed to this:

const TEXT = "hello nim"

And this code is compiled further.

Keep in my mind that if (for instance) you create a huge const array, then the size of the binary can increase. If you declare it with let, the program may run slower (since the array will be created at runtime), but the EXE can be smaller. So always evaluate the pros and cons.

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 April 03, 13:40