type A = object
name: string
id: int
The first line sounds strange to me because this code defines a type and I read " This type "A" is equal to object ". Is it correct ?
So why not.
#This code is not nimrod but comes from my imagination. Don't compile this !
type object A
name:string
id:int
type object B ref of A
memberForExtendingA:someType
type tuple C
x:float
y:float
It sounds to me like "This type of object "A" contains "name" and "id" and "This type of object "B" extends "A" and contains memberForExtendingA" ecetera... I'm not an experienced programmer and I apologize in advance if I wrote stupid things and if I misunderstood the Nim syntax.
Hi @DTxplorer,
In many programming languages (including Nim), A = B doesn't mean "A equals B", but rather means "A is assigned the value of B".
So that Nim syntax is saying "A new type A is defined as an object with these fields...".
The type is defined as/equals .... what is so confusing about it? I find it very nice to read and easy understandable as it is simple stupid already as it is.
The "type" is the value and it's name "A" simply becomes the value "object ..." assigned. You can also write "type B = int" which is just as valid.
type object A is confusing to me. Esp "This type of object "A" contains "name" and "id"" does not make any sense to me. That would imply another object A which is of a different type.
I am not sure about the other languages doing something similar question. I think Haskell is similar:
data Bool = False | True ... which defines the type "Bool" as being "False" or "True".
Or using Record Syntax:
data Person = Person { firstName :: String
, lastName :: String
, age :: Int
, height :: Float
, phoneNumber :: String
, flavor :: String
} deriving (Show)
I think one way to look at it ist that = is to be seen like the { of the {} construct after which follows stuff. With that in mind a lot of code "translates" to other languages like C for example.
I also think that it is "easy" to understand that after proc there is a = sign as the "proc" gets the code "assigned".
So "proc a() = ..." is like "let a: proc() = ..." which makes sense. "a" is of type proc and actually IS the proc after that "assignment". I find it understandable that = is being used "everywhere" some symbol gets its meaning assigned.
See for example Java Script:
var test = function(a) { console.log(a) }
With Nim like syntax that would be:
function test(a) = console.log(a)