Need some way of representing numeric values. JavaScript just has the Number type, though there may be some advantage to us supporting an integer type as well. We should certainly have some way of verifying that a value is an integer, though we can do that with a distinct type or with some kind of round function or regex.
number: year; // Declare as a number
year {
// How to validate as an integer?
valid: year >= 2000;
}
Currently we only support the string and boolean types. Nice thing about both of those is that they can never be invalid. A text box can be an empty string, but that it is still a string. A check box can be checked or not, but both are valid booleans.
For numbers, the user can input "hello" which is not a valid number. I'm not entirely sure how we want the Uniform code to respond to that case. We have a couple options:
Set year to be null. We can then define each operator to reject nulls in the way that most makes sense, ie. null > x => null. We can then allow the programmer to compare against null and change their logic accordingly to handle it.
throw an error. We can break out of the expression and treat the statement as having thrown an error. However, there's no real way for developers to catch the exception and handle it which could make logic more difficult.
I don't really care for either solution here, is there a more elegant way we might be able to handle this?
Need some way of representing numeric values. JavaScript just has the
Number
type, though there may be some advantage to us supporting aninteger
type as well. We should certainly have some way of verifying that a value is an integer, though we can do that with a distinct type or with some kind of round function or regex.Currently we only support the
string
andboolean
types. Nice thing about both of those is that they can never be invalid. A text box can be an empty string, but that it is still a string. A check box can be checked or not, but both are valid booleans.For numbers, the user can input
"hello"
which is not a valid number. I'm not entirely sure how we want the Uniform code to respond to that case. We have a couple options:year
to benull
. We can then define each operator to reject nulls in the way that most makes sense, ie.null > x
=>null
. We can then allow the programmer to compare againstnull
and change their logic accordingly to handle it.throw
an error. We can break out of the expression and treat the statement as having thrown an error. However, there's no real way for developers to catch the exception and handle it which could make logic more difficult.I don't really care for either solution here, is there a more elegant way we might be able to handle this?