StardustPL / Stardust

"A programming language that doesn't make me angry to use it."
https://StardustPL.GitHub.IO/
The Unlicense
4 stars 0 forks source link

Planning: Separate Library: Units #10

Open LB-- opened 9 years ago

LB-- commented 9 years ago

Will contain the of infix operator which takes any object as its left operand and a unit as its right operand. No conversions or copies are ever performed; a unit is an adaptor based on the original type, and the of operator simply performs the cast after doing some other checks and logic.

Most common units should be supported.

For example, ((123 of seconds) of minutes) of seconds is an expression which adapts 123 as seconds 1-to-1, then adapts that value to a version of minutes that converts to/from seconds, and then adapts that value to a version of seconds that converts to/from minutes. It is also quite inefficient without optimizations.