{

Welcome to my blog !


Nim How to get Variable datatype with example?

May 4, 2023 ·  2 min read

This tutorial explains How to find the variable data type in Nim With examples Nim typeof Operator Example typeOf(variable) returns the datatype of a variable Here is an examples int type: var number=12 echo typeOf(number) #int Float types var number1=12.123 echo typeOf(number1) #float64 char type: var character='a' echo typeOf(character) #char String type: var str="name" echo typeOf(str) # string Object type type Employee = object id: int name: string echo typeOf(Employee) # Employee bool var isFlag = false; echo typeOf(isFlag) # bool sequence types let sequence = @['a', 'b', 'c'] echo typeOf(sequence) # seq[char] let numbers = @[1,2,3] echo typeOf(numbers) # seq[int] let numbers1 = @["one", "two"] echo typeOf(numbers1) # seq[string] Array types var arr: array[3, int] = [7, 8, 9,] echo typeof(arr) # array[0....

How to convert a string into a sequence of characters in Nim?

May 4, 2023 ·  2 min read

This tutorial explains how to convert a String into a Sequence of characters in the Nim Programming language The string is a type that contains a collection of characters, enclosed in double quotes. The sequence is a collection of elements with dynamic in size. Both are different data types and automatic conversion is not required. Convert String into a sequence of characters in Nim with an example Multiple ways we can convert a String into a sequence...

Nim Generate Random Numbers with Examples?

May 3, 2023 ·  1 min read

This tutorial explains Nim Random Generators Nim Random Number Generator Example random is a nim module that provides a procedure to generate Random numbers. It is based on the xoroshiro128 library. Import random library into a code Next, call randomize() method to initialize a random generator. This is required to generate a random number for every call Rand(n) procedure returns the random number between 1 to n. Here is an example...

How to read command line arguments in Nim with examples?

May 3, 2023 ·  1 min read

This tutorial explains how to read command line arguments in NIm code For example, You have hello.nim code, that you want to run the code by passing arguments separated by space. nim compile --run hello.nim arguments How to read command line arguments Multiple ways to read command line arguments in Nim programming language using the os commandLineParams procedure commandLineParams returns the Sequence of a string that passed to the command line Here is an example...

Nim example - epoch unix timestamp, Local and Utc datetime

May 2, 2023 ·  1 min read

This tutorial explains multiple ways to get Datetime in Local and UTC as well as EPOCH timestamp. How to get the Current Epoch unix timestamp in NIm. times module hasepochTime() proc that returns a number of milliseconds since the 1970 date. It returns a floating number. import std/[times] let currentTimestamp = epochTime() echo currentTimestamp Output 1682999883.740629 How to get Current DateTime in Local and UTC NIm. now() in the times module returns the current DateTime in Local time....

Subscribe
You'll get a notification every time a post gets published here.