Draft:Odin (programming language): Difference between revisions

Content deleted Content added
Added design section, add some description to the swizzling example and break it down
Tags: nowiki added Visual edit
Xplane80 (talk | contribs)
m Remove untyped literals information which is wrong; indentation style example
Line 73:
a : : 3 // Declares constant a. Type is inferred from RHS expression
a :: 3 // : and : are usually written together
</syntaxhighlight>The semicolons are statement terminators and optional. Unlike Go, the Odin permits a newline in certain places where semicolon could otherwise be inserted, allowing programmer to have a higher selection of [[Indentation style|indentation styles]], for example chosing to use Stroustrup'sAllman variation of K&R indentation style:<syntaxhighlight>
if cond {
} else {
} else { // Go requires else to be on the same line as closing }
}
 
if cond
{
}
else { // Odin allows else to be on the next line
{
}
</syntaxhighlight>
 
=== Untyped Literals ===
Odin allows numeric and string literals to not have a concrete type until the value is casted or assigned to an lvalue.<syntaxhighlight>
a: float = (2 - 1)/3 // assigns 0.333 to a
c: int = (2 - 1)/3 // assigns 0 to a
</syntaxhighlight>The untyped expression is calculated in the type to which it is being assigned or casted. For floats the computation would be equivalent to <code>(2.0-1.0)/3.0</code> and for integers its the same as <code>(2-1)/3</code>. In the case where the type of the variable is unspecified, the untyped expression is casted to the default type, that is <code>int</code>, if the untyped expression is composed of integers, and <code>float</code> if it contained untyped floats.
 
[[Constant (computer programming)|Constant]]<nowiki/>s can be untyped, meaning when these constants are used within other expressions they are treated the same as if they were untyped literals.
 
Under Odin terminology both untyped literals and untyped constants would have "untyped" types, which is a [[misnomer]].
 
=== Explicit procedure overloading ===