Define a primitive data type: Difference between revisions

Improved VB.NET (e.g. added missing operators); converted C# to translation of VB.NET; added explanation
(Improved VB.NET (e.g. added missing operators); converted C# to translation of VB.NET; added explanation)
Line 192:
As of February 2009 no open source libraries to do this task have been located.
 
=={{header|C sharp|C#}}==
Strictly speaking, this task is impossible in C# because a type that behaves like an integer (<code>int</code>, or <code>System.Int32</code>; <code>Integer</code> in VB.NET) must be a struct (in order to have value-type semantics), and, since C# does not allow the definition of a parameterless constructor for a struct (instead generating a default parameterless constructor that sets each of its fields to the default value for the type of the field), an instance of the struct with the forbidden value of zero can be created through that default constructor.
<lang csharp>public struct TinyInt
 
A way to overcome this in the type's public interface, however, is to expose the field exclusively as a property that checks whether its backing field is out of range, and, if so, returns a valid default value.
 
Through operator overloading, it is possible to declare types in C# with the full complement of operators available on the primitive types. The following structure attempts to mimic the behavior of the <code>int</code> type in C# on .NET Core as much as possible, including interfaces and static members, delegating as much implementation as possible to the <code>Integer</code> type itself.
 
<lang csharp>using System;
using System.Globalization;
 
struct LimitedInt : IComparable, IComparable<LimitedInt>, IConvertible, IEquatable<LimitedInt>, IFormattable
{
private const int minimalValueMIN_VALUE = 1;
private const int maximalValueMAX_VALUE = 10;
 
privatepublic static readonly intLimitedInt MinValue = new valueLimitedInt(MIN_VALUE);
public static readonly LimitedInt MaxValue = new LimitedInt(MAX_VALUE);
 
static bool IsValidValue(int value) => value >= MIN_VALUE && value <= MAX_VALUE;
private TinyInt(int i)
 
readonly int _value;
public int Value => this._value == 0 ? MIN_VALUE : this._value; // Treat the default, 0, as being the minimum value.
 
public LimitedInt(int value)
{
if (minimalValue > i || i > maximalValue!IsValidValue(value))
throw new ArgumentOutOfRangeException(nameof(value), value, $"Value must be between {MIN_VALUE} and {MAX_VALUE}.");
{
this._value = value;
throw new System.ArgumentOutOfRangeException();
}
value = i;
}
 
#region IComparable
public static implicit operator int(TinyInt i)
public int CompareTo(object obj)
{
if (obj is LimitedInt l) return ithis.Value.valueCompareTo(l);
throw new ArgumentException("Object must be of type " + nameof(LimitedInt), nameof(obj));
}
#endregion
 
#region IComparable<LimitedInt>
public static implicit operator TinyInt(int i)
public int CompareTo(LimitedInt other) => this.Value.CompareTo(other.Value);
#endregion
 
#region IConvertible
public TypeCode GetTypeCode() => this.Value.GetTypeCode();
bool IConvertible.ToBoolean(IFormatProvider provider) => ((IConvertible)this.Value).ToBoolean(provider);
byte IConvertible.ToByte(IFormatProvider provider) => ((IConvertible)this.Value).ToByte(provider);
char IConvertible.ToChar(IFormatProvider provider) => ((IConvertible)this.Value).ToChar(provider);
DateTime IConvertible.ToDateTime(IFormatProvider provider) => ((IConvertible)this.Value).ToDateTime(provider);
decimal IConvertible.ToDecimal(IFormatProvider provider) => ((IConvertible)this.Value).ToDecimal(provider);
double IConvertible.ToDouble(IFormatProvider provider) => ((IConvertible)this.Value).ToDouble(provider);
short IConvertible.ToInt16(IFormatProvider provider) => ((IConvertible)this.Value).ToInt16(provider);
int IConvertible.ToInt32(IFormatProvider provider) => ((IConvertible)this.Value).ToInt32(provider);
long IConvertible.ToInt64(IFormatProvider provider) => ((IConvertible)this.Value).ToInt64(provider);
sbyte IConvertible.ToSByte(IFormatProvider provider) => ((IConvertible)this.Value).ToSByte(provider);
float IConvertible.ToSingle(IFormatProvider provider) => ((IConvertible)this.Value).ToSingle(provider);
string IConvertible.ToString(IFormatProvider provider) => this.Value.ToString(provider);
object IConvertible.ToType(Type conversionType, IFormatProvider provider) => ((IConvertible)this.Value).ToType(conversionType, provider);
ushort IConvertible.ToUInt16(IFormatProvider provider) => ((IConvertible)this.Value).ToUInt16(provider);
uint IConvertible.ToUInt32(IFormatProvider provider) => ((IConvertible)this.Value).ToUInt32(provider);
ulong IConvertible.ToUInt64(IFormatProvider provider) => ((IConvertible)this.Value).ToUInt64(provider);
#endregion
 
#region IEquatable<LimitedInt>
public bool Equals(LimitedInt other) => this == other;
#endregion
 
#region IFormattable
public string ToString(string format, IFormatProvider formatProvider) => this.Value.ToString(format, formatProvider);
#endregion
 
#region operators
public static bool operator ==(LimitedInt left, LimitedInt right) => left.Value == right.Value;
public static bool operator !=(LimitedInt left, LimitedInt right) => left.Value != right.Value;
public static bool operator <(LimitedInt left, LimitedInt right) => left.Value < right.Value;
public static bool operator >(LimitedInt left, LimitedInt right) => left.Value > right.Value;
public static bool operator <=(LimitedInt left, LimitedInt right) => left.Value <= right.Value;
public static bool operator >=(LimitedInt left, LimitedInt right) => left.Value >= right.Value;
 
public static LimitedInt operator ++(LimitedInt left) => (LimitedInt)(left.Value + 1);
public static LimitedInt operator --(LimitedInt left) => (LimitedInt)(left.Value - 1);
 
public static LimitedInt operator +(LimitedInt left, LimitedInt right) => (LimitedInt)(left.Value + right.Value);
public static LimitedInt operator -(LimitedInt left, LimitedInt right) => (LimitedInt)(left.Value - right.Value);
public static LimitedInt operator *(LimitedInt left, LimitedInt right) => (LimitedInt)(left.Value * right.Value);
public static LimitedInt operator /(LimitedInt left, LimitedInt right) => (LimitedInt)(left.Value / right.Value);
public static LimitedInt operator %(LimitedInt left, LimitedInt right) => (LimitedInt)(left.Value % right.Value);
 
public static LimitedInt operator &(LimitedInt left, LimitedInt right) => (LimitedInt)(left.Value & right.Value);
public static LimitedInt operator |(LimitedInt left, LimitedInt right) => (LimitedInt)(left.Value | right.Value);
public static LimitedInt operator ^(LimitedInt left, LimitedInt right) => (LimitedInt)(left.Value ^ right.Value);
public static LimitedInt operator ~(LimitedInt left) => (LimitedInt)~left.Value;
 
public static LimitedInt operator >>(LimitedInt left, int right) => (LimitedInt)(left.Value >> right);
public static LimitedInt operator <<(LimitedInt left, int right) => (LimitedInt)(left.Value << right);
 
public static implicit operator int(LimitedInt value) => value.Value;
public static explicit operator LimitedInt(int value)
{
returnif (!IsValidValue(value)) throw new TinyIntOverflowException(i);
return new LimitedInt(value);
}
#endregion
 
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider provider = null)
=> this.Value.TryFormat(destination, out charsWritten, format, provider);
 
public override int GetHashCode() => this.Value.GetHashCode();
public override bool Equals(object obj) => obj is LimitedInt l && this.Equals(l);
public override string ToString() => this.Value.ToString();
 
#region static methods
public static bool TryParse(ReadOnlySpan<char> s, out int result) => int.TryParse(s, out result);
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out int result) => int.TryParse(s, style, provider, out result);
public static int Parse(string s, IFormatProvider provider) => int.Parse(s, provider);
public static int Parse(string s, NumberStyles style, IFormatProvider provider) => int.Parse(s, style, provider);
public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, ref int result) => int.TryParse(s, style, provider, out result);
public static int Parse(string s) => int.Parse(s);
public static int Parse(string s, NumberStyles style) => int.Parse(s, style);
public static int Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null) => int.Parse(s, style, provider);
public static bool TryParse(string s, ref int result) => int.TryParse(s, out result);
#endregion
}</lang>
 
Line 2,285 ⟶ 2,380:
 
=={{header|Visual Basic .NET}}==
See [[#C#|C#]] for why this task ''technically'' impossible in VB.NET.
 
Through operator overloading, it is possible to declare types in VB.NET with the full complement of operators available on the primitive types. The following structure attempts to mimic the behavior of the <code>Integer</code> type in VB.NET on .NET Core as much as possible, including interfaces and static members, delegating as much implementation as possible to the <code>Integer</code> type itself.
Visual Basic .NET has full support for creating your own primitives, but every operator has to be implemented explicitly. Often developers will only implement the parts they are using and skip the rest.
 
Also noteNote that some operators return a <code>Double</code> instead of a new <code>LimitedInt</code>. This was by choiceintentional in order to match the behavior of Integersthe corresponding <code>Integer</code> operators in VB.NET. Also note that some members are commented out. This is because the newest supported release of VB.NET (as of 2019-09-14) does not support the .NET Core <code>Span(Of T)</code> and <code>ReadOnlySpan(Of T)</code> types.
 
<lang vbnet>Structure LimitedInt
Implements IComparable, IComparable(Of LimitedInt), IConvertible, IEquatable(Of LimitedInt), IFormattable
Implements IEquatable(Of LimitedInt)
 
Private Const MIN_VALUE = 1
Private m_Value As Integer 'treat the default, 0 as being really 1
Private Const MAX_VALUE = 10
 
Shared ReadOnly MinValue As New LimitedInt(MIN_VALUE)
Public ReadOnly Property Value() As Integer
Shared ReadOnly MaxValue As New LimitedInt(MAX_VALUE)
Get
Return If(m_Value = 0, 1, m_Value)
End Get
End Property
 
Public Sub New(ByValPrivate Shared Function IsValidValue(value As Integer) As Boolean
If value < 1 OrReturn value >= 10MIN_VALUE ThenAndAlso Throwvalue New<= ArgumentOutOfRangeException("value")MAX_VALUE
m_ValueEnd = valueFunction
End Sub
 
Private ReadOnly _value As Integer
Public Function CompareTo(ByVal other As LimitedInt) As Integer Implements System.IComparable(Of LimitedInt).CompareTo
ReturnReadOnly Property Me.Value -As other.ValueInteger
End Function Get
' Treat the default, 0, as being the minimum value.
Return If(Me._value = 0, MIN_VALUE, Me._value)
Public Overloads Function Equals(ByVal other As LimitedInt) As Boolean Implements System.IEquatable(Of LimitedInt).Equals
Return Me.Value = other.Value End Get
End FunctionProperty
 
Public Overrides FunctionSub GetHashCodeNew()value As Integer)
If Not IsValidValue(value) Then Throw New ArgumentOutOfRangeException(NameOf(value), value, $"Value must be between {MIN_VALUE} and {MAX_VALUE}.")
Return Value.GetHashCode
Me._value = value
End Function
End Sub
 
#Region "IComparable"
Public Overrides Function Equals(ByVal obj As Object) As Boolean
Function CompareTo(obj As Object) As Integer Implements IComparable.CompareTo
If TypeOf obj Is LimitedInt Then Return CType(obj, LimitedInt) = Me
If TypeOf obj IsNot LimitedInt Then Throw New ArgumentException("Object must be of type " + NameOf(LimitedInt), NameOf(obj))
End Function
Return Me.CompareTo(DirectCast(obj, LimitedInt))
End Function
#End Region
 
#Region "IComparable(Of LimitedInt)"
Public Shared Operator =(ByVal left As LimitedInt, ByVal right As LimitedInt) As Boolean
Function CompareTo(other As LimitedInt) As Integer Implements IComparable(Of LimitedInt).CompareTo
Return left.Equals(right)
Return Me.Value.CompareTo(other.Value)
End Operator
End Function
#End Region
 
#Region "IConvertible"
Public Shared Operator <>(ByVal left As LimitedInt, ByVal right As LimitedInt) As Boolean
Function GetTypeCode() As TypeCode Implements IConvertible.GetTypeCode
Return Not (left = right)
Return Me.Value.GetTypeCode()
End Operator
End Function
 
Private Function ToBoolean(provider As IFormatProvider) As Boolean Implements IConvertible.ToBoolean
Public Shared Operator +(ByVal left As LimitedInt, ByVal right As LimitedInt) As LimitedInt
Return DirectCast(Me.Value, IConvertible).ToBoolean(provider)
Dim temp As Integer = left.Value + right.Value
SelectEnd Case tempFunction
Case 1 To 10 : Return New LimitedInt(temp)
Case Else : Throw New OverflowException
End Select
End Operator
 
Private Function ToByte(provider As IFormatProvider) As Byte Implements IConvertible.ToByte
Public Shared Operator -(ByVal left As LimitedInt, ByVal right As LimitedInt) As LimitedInt
Dim temp As Integer =Return leftDirectCast(Me.Value, - rightIConvertible).ValueToByte(provider)
SelectEnd Case tempFunction
Case 1 To 10 : Return New LimitedInt(temp)
Case Else : Throw New OverflowException
End Select
End Operator
 
Private Function ToChar(provider As IFormatProvider) As Char Implements IConvertible.ToChar
Public Shared Operator *(ByVal left As LimitedInt, ByVal right As LimitedInt) As LimitedInt
Dim temp As Integer =Return leftDirectCast(Me.Value, * rightIConvertible).ValueToChar(provider)
SelectEnd Case tempFunction
Case 1 To 10 : Return New LimitedInt(temp)
Case Else : Throw New OverflowException
End Select
End Operator
 
Private Function ToDateTime(provider As IFormatProvider) As Date Implements IConvertible.ToDateTime
Public Shared Operator /(ByVal left As LimitedInt, ByVal right As LimitedInt) As Double
Return leftDirectCast(Me.Value, / rightIConvertible).ValueToDateTime(provider)
End OperatorFunction
 
Private Function ToDecimal(provider As IFormatProvider) As Decimal Implements IConvertible.ToDecimal
Public Shared Operator \(ByVal left As LimitedInt, ByVal right As LimitedInt) As LimitedInt
Return DirectCast(Me.Value, IConvertible).ToDecimal(provider)
Dim temp As Integer = left.Value \ right.Value
SelectEnd Case tempFunction
Case 1 To 10 : Return New LimitedInt(temp)
Case Else : Throw New OverflowException
End Select
End Operator
 
Private Function ToDouble(provider As IFormatProvider) As Double Implements IConvertible.ToDouble
Public Shared Operator Mod(ByVal left As LimitedInt, ByVal right As LimitedInt) As LimitedInt
Dim temp As Integer =Return leftDirectCast(Me.Value, Mod rightIConvertible).ValueToDouble(provider)
SelectEnd Case tempFunction
Case 1 To 10 : Return New LimitedInt(temp)
Case Else : Throw New OverflowException
End Select
End Operator
 
Private Function ToInt16(provider As IFormatProvider) As Short Implements IConvertible.ToInt16
Public Shared Operator And(ByVal left As LimitedInt, ByVal right As LimitedInt) As LimitedInt
Dim temp As Integer =Return leftDirectCast(Me.Value, And rightIConvertible).ValueToInt16(provider)
SelectEnd Case tempFunction
Case 1 To 10 : Return New LimitedInt(temp)
Case Else : Throw New OverflowException
End Select
End Operator
 
Private Function ToInt32(provider As IFormatProvider) As Integer Implements IConvertible.ToInt32
Public Shared Operator Or(ByVal left As LimitedInt, ByVal right As LimitedInt) As LimitedInt
Dim temp As Integer =Return leftDirectCast(Me.Value, Or rightIConvertible).ValueToInt32(provider)
SelectEnd Case tempFunction
Case 1 To 10 : Return New LimitedInt(temp)
Case Else : Throw New OverflowException
End Select
End Operator
 
Private Function ToInt64(provider As IFormatProvider) As Long Implements IConvertible.ToInt64
Public Shared Operator Xor(ByVal left As LimitedInt, ByVal right As LimitedInt) As LimitedInt
Dim temp As Integer =Return leftDirectCast(Me.Value, Xor rightIConvertible).ValueToInt64(provider)
SelectEnd Case tempFunction
Case 1 To 10 : Return New LimitedInt(temp)
Case Else : Throw New OverflowException
End Select
End Operator
 
Private Function ToSByte(provider As IFormatProvider) As SByte Implements IConvertible.ToSByte
Public Shared Operator ^(ByVal left As LimitedInt, ByVal right As LimitedInt) As Double
Return leftDirectCast(Me.Value, ^ rightIConvertible).ValueToSByte(provider)
End OperatorFunction
 
Private Function ToSingle(provider As IFormatProvider) As Single Implements IConvertible.ToSingle
Public Shared Operator <(ByVal left As LimitedInt, ByVal right As LimitedInt) As Boolean
Return leftDirectCast(Me.Value, < rightIConvertible).ValueToSingle(provider)
End OperatorFunction
 
Private Overloads Function ToString(provider As IFormatProvider) As String Implements IConvertible.ToString
Public Shared Operator >(ByVal left As LimitedInt, ByVal right As LimitedInt) As Boolean
Return left.Value > right Return Me.Value.ToString(provider)
End OperatorFunction
 
Private Function ToType(conversionType As Type, provider As IFormatProvider) As Object Implements IConvertible.ToType
Public Shared Operator <=(ByVal left As LimitedInt, ByVal right As LimitedInt) As Boolean
Return leftDirectCast(Me.Value, <= rightIConvertible).ValueToType(conversionType, provider)
End OperatorFunction
 
Private Function ToUInt16(provider As IFormatProvider) As UShort Implements IConvertible.ToUInt16
Public Shared Operator >=(ByVal left As LimitedInt, ByVal right As LimitedInt) As Boolean
Return leftDirectCast(Me.Value, >= rightIConvertible).ValueToUInt16(provider)
End OperatorFunction
 
Private Function ToUInt32(provider As IFormatProvider) As UInteger Implements IConvertible.ToUInt32
Public Shared Widening Operator CType(ByVal left As LimitedInt) As Integer
Return leftDirectCast(Me.Value, IConvertible).ToUInt32(provider)
End OperatorFunction
 
Private Function ToUInt64(provider As IFormatProvider) As ULong Implements IConvertible.ToUInt64
Public Shared Narrowing Operator CType(ByVal left As Integer) As LimitedInt
Return NewDirectCast(Me.Value, LimitedIntIConvertible).ToUInt64(leftprovider)
End OperatorFunction
#End Region
 
#Region "IEquatable(Of LimitedInt)"
Overloads Function Equals(other As LimitedInt) As Boolean Implements IEquatable(Of LimitedInt).Equals
Return Me = other
End Function
#End Region
 
#Region "IFormattable"
Private Overloads Function ToString(format As String, formatProvider As IFormatProvider) As String Implements IFormattable.ToString
Return Me.Value.ToString(format, formatProvider)
End Function
#End Region
 
#Region "Operators"
Shared Operator =(left As LimitedInt, right As LimitedInt) As Boolean
Return left.Value = right.Value
End Operator
 
Shared Operator <>(left As LimitedInt, right As LimitedInt) As Boolean
Return left.Value <> right.Value
End Operator
 
Shared Operator <(left As LimitedInt, right As LimitedInt) As Boolean
Return left.Value < right.Value
End Operator
 
Shared Operator >(left As LimitedInt, right As LimitedInt) As Boolean
Return left.Value > right.Value
End Operator
 
Shared Operator <=(left As LimitedInt, right As LimitedInt) As Boolean
Return left.Value <= right.Value
End Operator
 
Shared Operator >=(left As LimitedInt, right As LimitedInt) As Boolean
Return left.Value >= right.Value
End Operator
 
Shared Operator +(left As LimitedInt) As LimitedInt
Return CType(+left.Value, LimitedInt)
End Operator
 
Shared Operator -(left As LimitedInt) As LimitedInt
Return CType(-left.Value, LimitedInt)
End Operator
 
Shared Operator +(left As LimitedInt, right As LimitedInt) As LimitedInt
Return CType(left.Value + right.Value, LimitedInt)
End Operator
 
Shared Operator -(left As LimitedInt, right As LimitedInt) As LimitedInt
Return CType(left.Value - right.Value, LimitedInt)
End Operator
 
Shared Operator *(left As LimitedInt, right As LimitedInt) As LimitedInt
Return CType(left.Value * right.Value, LimitedInt)
End Operator
 
Shared Operator /(left As LimitedInt, right As LimitedInt) As Double
Return left.Value / right.Value
End Operator
 
Shared Operator \(left As LimitedInt, right As LimitedInt) As LimitedInt
Return CType(left.Value \ right.Value, LimitedInt)
End Operator
 
Shared Operator ^(left As LimitedInt, right As LimitedInt) As Double
Return left.Value ^ right.Value
End Operator
 
Shared Operator Mod(left As LimitedInt, right As LimitedInt) As LimitedInt
Return CType(left.Value Mod right.Value, LimitedInt)
End Operator
 
Shared Operator And(left As LimitedInt, right As LimitedInt) As LimitedInt
Return CType(left.Value And right.Value, LimitedInt)
End Operator
 
Shared Operator Or(left As LimitedInt, right As LimitedInt) As LimitedInt
Return CType(left.Value Or right.Value, LimitedInt)
End Operator
 
Shared Operator Xor(left As LimitedInt, right As LimitedInt) As LimitedInt
Return CType(left.Value Xor right.Value, LimitedInt)
End Operator
 
Shared Operator Not(left As LimitedInt) As LimitedInt
Return CType(Not left.Value, LimitedInt)
End Operator
 
Shared Operator >>(left As LimitedInt, right As Integer) As LimitedInt
Return CType(left.Value >> right, LimitedInt)
End Operator
 
Shared Operator <<(left As LimitedInt, right As Integer) As LimitedInt
Return CType(left.Value << right, LimitedInt)
End Operator
 
Shared Widening Operator CType(value As LimitedInt) As Integer
Return value.Value
End Operator
 
Shared Narrowing Operator CType(value As Integer) As LimitedInt
If Not IsValidValue(value) Then Throw New OverflowException()
Return New LimitedInt(value)
End Operator
#End Region
 
'Function TryFormat(destination As Span(Of Char), ByRef charsWritten As Integer, Optional format As ReadOnlySpan(Of Char) = Nothing, Optional provider As IFormatProvider = Nothing) As Boolean
' Return Me.Value.TryFormat(destination, charsWritten, format, provider)
'End Function
 
Overrides Function GetHashCode() As Integer
Return Me.Value.GetHashCode
End Function
 
Overrides Function Equals(obj As Object) As Boolean
Return TypeOf obj Is LimitedInt AndAlso Me.Equals(DirectCast(obj, LimitedInt))
End Function
 
Overrides Function ToString() As String
Return Me.Value.ToString()
End Function
 
#Region "Shared Methods"
'Shared Function TryParse(s As ReadOnlySpan(Of Char), ByRef result As Integer) As Boolean
' Return Integer.TryParse(s, result)
'End Function
 
'Shared Function TryParse(s As ReadOnlySpan(Of Char), style As Globalization.NumberStyles, provider As IFormatProvider, ByRef result As Integer) As Boolean
' Return Integer.TryParse(s, style, provider, result)
'End Function
 
Shared Function Parse(s As String, provider As IFormatProvider) As Integer
Return Integer.Parse(s, provider)
End Function
 
Shared Function Parse(s As String, style As Globalization.NumberStyles, provider As IFormatProvider) As Integer
Return Integer.Parse(s, style, provider)
End Function
 
Shared Function TryParse(s As String, style As Globalization.NumberStyles, provider As IFormatProvider, ByRef result As Integer) As Boolean
Return Integer.TryParse(s, style, provider, result)
End Function
 
Shared Function Parse(s As String) As Integer
Return Integer.Parse(s)
End Function
Shared Function Parse(s As String, style As Globalization.NumberStyles) As Integer
Return Integer.Parse(s, style)
End Function
 
'Shared Function Parse(s As ReadOnlySpan(Of Char), Optional style As Globalization.NumberStyles = Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As Integer
' Return Integer.Parse(s, style, provider)
'End Function
 
Shared Function TryParse(s As String, ByRef result As Integer) As Boolean
Return Integer.TryParse(s, result)
End Function
#End Region
End Structure</lang>
 
=={{header|Visual FoxPro}}==
Visual FoxPro can't define primitives but they can be emulated with custom classes.
<lang vfp>LOCAL o As BoundedInt
LOCAL o As BoundedInt
o = NEWOBJECT("BoundedInt")
DO WHILE NOT o.lHasError
Line 2,462 ⟶ 2,688:
ENDIF
THIS.lHasError = .T.
ENDDEFINE </lang>
</lang>
{{omit from|AWK}}
{{omit from|Axe}}
Anonymous user