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 ]

type definition

In C, we have typedef. With typedef we can put a new type name on an existing type. How to do the same in Nim?

typedef
#include <stdio.h>

typedef int whole;

int main()
{
    int x = 2;

    whole y = 5;

    printf("%d, %d\n", x, y); // 2, 5

    return 0;
}
type
  CharSet = set[char]

let
  digits1: set[char] = {'1' .. '9'}

  digits2: CharSet = {'1' .. '9'}

echo digits1  # {'1', '2', '3', '4', '5', '6', '7', '8', '9'}
echo digits2  # {'1', '2', '3', '4', '5', '6', '7', '8', '9'}

In the C example, whole is just a different name for int.

It's the same in Nim: CharSet is just a more readable name for set[char], and the two are interchangeable.

Subtle difference: in C, we put the secondary name to the end. In Nim, we put the secondary name to the beginning.

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 09, 00:12