|
Oktatás * Programozás 2 * Szkriptnyelvek * Adator. prog. Teaching • Prog. for Data Sci. Félévek Linkek * kalendárium |
Nim2 /
How to import a packageImporting is very similar to Python. Import just some parts of a packageThe following code drops an error: # read a line of words from stdin and print the first word reversed import std/strutils import std/unicode # reversed let parts = stdin.readLine.splitWhitespace echo parts[0].reversed Error message: main.nim(9, 27) Error: ambiguous call; both strutils.splitWhitespace(s: string, maxsplit: int) [func declared in /home/jabba/.choosenim/toolchains/nim-2.4.0/lib/pure/strutils.nim(924, 6)] and unicode.splitWhitespace(s: string) [proc declared in /home/jabba/.choosenim/toolchains/nim-2.4.0/lib/pure/unicode.nim(1464, 6)] match for: (string) The error comes from Solution #1From the package unicode I only need the function import std/strutils from std/unicode import reversed let parts = stdin.readLine.splitWhitespace echo parts[0].reversed Solution #2To avoid ambiguity, we can qualify the call explicitly: import std/strutils import std/unicode let parts = strutils.splitWhitespace(stdin.readLine) echo parts[0].reversed Here it's clear which |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |