Note: By convention, the package name is the same as the last element in the import path. If no prefix is present, the import will look relative to the current file. The core: prefix is used to state where the import is meant to look this is called a library collection. The following program imports the the fmt and os packages from the core library collection. Programs begin running in the package main. Packages #Įvery Odin program is made up of packages. Z :: y 7 // constant computations are possibleįor more information regarding value declarations in general, please see the Odin FAQ and Ginger Bill’s article On the Aesthetics of the Syntax of Declarations. The constant’s value must be able to be evaluated at compile time: x :: "what" // constant `x` has the untyped string value "what"Ĭonstants can be explicitly typed like a variable declaration: y : int : 123 X: = 123 // default type for an integer literal is `int`Ĭonstants are entities (symbols) which have an assigned value. The following are all equivalent: x: int = 123 You can assign multiple variables with it: x, y := 1, "hello" // declares `x` and `y` and infers the types from the assignments The assignment statement assigns a new value to a variable/location: x: int = 123 // declares a new variable `x` with type `int` and assigns a value to it Variables are initialized to zero by default unless specified otherwise. Y, z: int // declares y and z to have type `int` X = 1 // `1` is an untyped integer literal which can implicitly convert to `int`Ī variable declaration declares a new variable for the current scope. x: int = 1.0 // A float literal but it can be represented by an integer without precision lossĬonstant literals are “untyped” which means that they can implicitly convert to a type. In Odin, if a number constant can be represented by a type without precision loss, it will automatically convert to that type. A leading zero does not produce an octal constant (unlike C). If a number literal is suffixed with i, it is an imaginary number literal: 2i (2 multiply the square root of -1).īinary literals are prefixed with 0b, octal literals with 0o, and hexadecimal literals with 0x. A number that contains a dot is a floating point literal: 1.0e9 (one billion). A useful feature in Odin is that underscores are allowed for better readability: 1_000_000_000 (one billion). Numerical literals are written similar to most other programming languages.
0 Comments
Leave a Reply. |