Anonymous user
Define a primitive data type: Difference between revisions
→{{header|JavaScript}}
(Add Racket entry) |
|||
Line 715:
var y = new Num(0); //TypeError
var z = new Num(11); //TypeError
</lang>
=={{header|Lasso}}==
<lang Lasso>define littleint => type {
data private value
public oncreate(value::integer) => {
fail_if(#value < 1,#value+' less than 1 ')
fail_if(#value > 10,#value+' greater than 10')
.value = #value
}
public +(rhs::integer) => littleint(.value + #rhs)
public -(rhs::integer) => littleint(.value - #rhs)
public *(rhs::integer) => littleint(.value * #rhs)
public /(rhs::integer) => littleint(.value / #rhs)
public %(rhs::integer) => littleint(.value % #rhs)
public asstring() => string(.value)
}
littleint(1) // 1
littleint(10) // 10
littleint(0) // Error: 0 less than 1
littleint(2) - 5 // Error: -3 less than 1
littleint(11) // Error: 11 greater than 10
littleint(10) + 1 // Error: 11 greater than 10
littleint(10) * 2 // Error: 20 greater than 10
</lang>
|