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 ]

echo

Similar to Python's print(). It also adds a newline after the last element. However, when you print several elements, no space is added between them.

echo "hello nim"          # hello nim

echo 2, true, 3.14        # 2true3.14

echo(2, true, 3.14)       # 2true3.14

In Nim, parentheses for procedure calls are optional when there is no ambiguity. This is a general language rule, not specific to echo.

If you don't need the automatic newline, use stdout.write() :

stdout.write("hello ")
stdout.write("nim")
stdout.write("\n")

stdout is a global variable, available without any import.

Why is it echo() and not print() ?

It's one character shorter. You need to type less :)

You can print anything with stdout.write()

Similarly to echo(), you can print anything (not only strings) with stdout.write(). However, Python's sys.stdout.write() can only print strings!

stdout.write() is strong
import sys

sys.stdout.write("hello\n")

# sys.stdout.write(42)  # TypeError: write() argument must be str

# sys.stdout.write("aa", "bb")  # ERROR: provide just 1 argument
stdout.write("hello\n")

stdout.writeLine("world")  # newline added

stdout.write(42, "\n")  # Multiple arguments? Fine.

stdout.writeLine("END")

𝥶This time Nim has the advantage. stdout.write() can print any type, not only strings, and it accepts multiple arguments. It also has a variation that adds a newline (stdout.writeLine()).

How does it work? Implicitly, it converts the input parameters to string with the `$` proc, and then it prints strings to the standard output.

What is echo() then?

From the docstring of echo(): "Special built-in that takes a variable number of arguments. Each argument is converted to a string via `$`, so it works for user-defined types that have an overloaded `$` operator. echo(x) is roughly equivalent to stdout.writeLine(x); stdout.flushFile()."

Flushing means that it prints immediately to the standard output without buffering.

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 08, 19:11