There are no 'untyped' objects in .Net and hence there are no 'untyped' objects (variables) in VisualAPL.
VisualAPL incorporates a .Net datatype called 'cvar' which is used as the data type argument to APL operators and many quad-functions. The cvar data type has additional properties which are analogous to traditional APL properties, e.g. []dr values. Even though an object of cvar .Net type might have have a []dr result of 323 (integer), that object's .Net type is cvar and not Int32.
When .Net value types, e.g. Int32, double, string, etc. are passed by the VisualAPL programmer to an APL operator, the arguments are generally first cast (i.e. coerced, if possible and if necessary) to cvar data types and then the APL operator method is applied to those cvar arguments. The result has .Net type cvar. This process is especially necessary for cvar array objects.
Only if the APL programmer explicitly casts a cvar result to a .Net value type will the .Net type of the result be changed from .Net cvar type.
The casting (directly or implicitly) of .Net value types to .Net cvar type is implemented in VisualAPL only for a selection of .Net value types. For example a recent version update of VisualAPL implemented an additional cast option (See
http://forum.apl2000.com/viewtopic.php?t=710).
VisualAPL uses the underlying .Net operators and methods whenever possible, so, for example, 1+ 1.234 56.789 in VisualAPL iterates thruough the elements of the array utilizing the .Net arithmetic operator plus on scalar doubles.
Providing an argument to an APL operator of a .Net type which cannot be implicitly cast to cvar will result in an error. For example:
X = (decimal) 1.234
X.GetTypeCode()
X+1 2 3 4 //Returns bad args to this method <method: op_Addition on System.Decimal> because an implicit cast from decimal[] to cvar array is not currently implemented in VisualAPL
On the other hand:
X=1.234
X.GetType() //Returns in System.Double
X+1 2 3 4 //Returns in 2.234 3.234 4.234 5.234
(X+1 2 3 4).GetType() //Returns in VisualCielo.Numeric.DataObjects.cvar
If the VisualAPL programmer wants to return a .Net type of array of double (i.e. double[]):
(double[])(X+1 2 3 4) //Returns Unable to cast object of type 'VisualCielo.Numeric.DataObjects.cvar' to type 'System.Double[]' because an implicit cast from double[] to cvar array is not currently implemented in VisualAPL.
Casting the result (X+1 2 3 4) to double[] can be done by the VisualAPL programmer by assigning the result to a variable name and iterating through the elements and individually assigning them to the elements of a pre-defined variable of .Net type double[].
Casting arguments to APL operators as .Net cvar types is done only when necessary. Scalar operator methods are generally performed using the .Net value types without conversion to .Net cvar type. For example:
X=1.2345 //Note that VisualAPL assumes that this is a double and not decimal .Net value type.
X.GetType() //Returns System.Double, so X=(double)1.2345 would be superfluous
(1+X).GetType() //The result of this scalar operator is System.Double
String and Char[] Specification:
'abcd'.GetType() //Returns System.Char[], an array of characters
"abcd".GetType() //Returns System.String
Traditional APL only supports the Char[] data type with the enclose/disclose operator used to emulate the string datatype and may permit ' and " pairs to be interchanged.
Some implicit casting of .Net (scalar) value types is done because it is inherently available in .Net:
f=(float) 1.234
1+f //Returns 2.234
(1+f).GetType() //Returns System.Single
d=(double)100.0001
d.GetTypeCode() //Returns Double
(1+d).GetType() //Returns System.Double
(f+d) //Returns 101.23409996757
(f+d).GetType() //Returns System.Double
Limits upon the implicit and explicit casting of .Net types is not unusual in .Net. When such methods are not available in .Net, an exception is thrown. VisualAPL follows this style. For example, .Net collections contain many special methods for conversion between collection types and arrays rather than providing implicit casting. These methods use iteration through the elements to perform the type casting to and from arrays. In addition these conversion methods illustrate that there are different needs, such as extensions to the conversions related to sorting and selecting, which implicit coercion would not satisfy.
Analogously whenever VisualAPL does not provide an implicit cast to or from cvar arrays, the VisualAPL programmer can use iteration through the array elements to perform the cast. Such casting methods can be developed within a separate VisualAPL .Net 'utility' assembly and referenced for use in many VisualAPL projects.
Use Interfaces:
When programming in VisualAPL and working with .Net assemblies developed in other .Net languages, a suggested approach is to clearly define the interface between the two code bases. Required datatype conversions are explicitly performed within interface methods in the VisualAPL code base which represent the methods of the 'external' assemblies. In the VisualAPL code base strong typing can then be avoided except in these interface methods.
Depending on customer support for VisualAPL, enhancements for implicit casting of arrays of .Net value types to cvar arrays can be considered for a future release. Limitations on implicit casting of arrays are not structural in VisualAPL, but represent the limits on implementation costs which are imposed by the product's current customer base.