|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
type conversionsecho int(3.14) # 3 echo int(3.99) # 3 , integer part echo float(2) # 2.0 let a = 2 pi = 3.14159 echo $a # "2" echo $pi # "3.14159" In Nim, the What is this $ operator?Actually, it's a procedure. Nim allows operators and punctuation symbols to be used as procedure names, so These are equivalent: echo $42 # "42" echo $(42) # "42" echo `$`(42) # "42" The backtick syntax works for any operator in Nim — it's how you call operators as regular functions: echo 2 + 3 # 5 #echo +(2, 3) # syntax error echo `+`(2, 3) # 5 The standard library defines Default string representation of an object: type Dog = object name: string let dog = Dog(name: "Dogmeat") echo dog # (name: "Dogmeat") With customized string representation: import std/strformat # &"Hello {name}!" type Dog = object name: string proc `$`(self: Dog): string = &"Dog('{self.name}')" let dog = Dog(name: "Dogmeat") echo dog # Dog('Dogmeat') echo $dog # Dog('Dogmeat') 𝥶Here, |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |