ŒVAL Force value result


Implemented for External classes only.

Syntax:

    data „ objref.ŒVAL

The niladic system method ŒVAL attempts to force data within an external object to be 'unboxed', so that the value of the data, rather than an object reference, is returned to APLX.

When used on an object which would normally be returned to APL as data, it does nothing; it simply returns the data as normal. Similarly, when used on an object which cannot be converted to simple APL data types, it also does nothing; the object reference is returned.

Where ŒVAL becomes useful is for cases where you have created an object (using typically ŒNEW or ŒREF) in the external environment, and where the object can be represented as ordinary APL data. The two most common cases are strings and arrays, but it can also be used with numeric types (which can be converted to integers or floating-point values).

In this example, we create an array of three strings in .Net:

      StringType„'.net' ŒGETCLASS 'System.String'    © Get Type of System.String    
      ArrayType„'.net' ŒGETCLASS 'System.Array'      © Get Type of System.Array
                                                     © so we can call static 
                                                     © method 'CreateInstance'
      ArrayType.CreateInstance StringType 3          © Create array of 3 strings
[NULL OBJECT] [NULL OBJECT] [NULL OBJECT]            © Oops! Array was unboxed            

      A„ArrayType.CreateInstance.ŒREF StringType 3   © Keep array as object
      A
[.net:String[]]                                      © Reference to .Net array
      A.SetValue 'First Item' 0                      © Insert some values
      A.SetValue 'Second Item' 1
      A.SetValue 'Third Item' 2
      
      A                                              © Still a reference
[.net:String[]]
      A.ŒVAL                                         © Unbox array to get contents
 First Item Second Item Third Item
      ŒDISPLAY A.ŒVAL
Ú…ÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÌ
Û Ú…ÎÎÎÎÎÎÎÎÎÌ Ú…ÎÎÎÎÎÎÎÎÎÎÌ Ú…ÎÎÎÎÎÎÎÎÎÌ Û
Û ÛFirst ItemÛ ÛSecond ItemÛ ÛThird ItemÛ Û
Û ÀÎÎÎÎÎÎÎÎÎÎÙ ÀÎÎÎÎÎÎÎÎÎÎÎÙ ÀÎÎÎÎÎÎÎÎÎÎÙ Û
À¹ÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÙ

This example in R creates a 'factor' and uses ŒVAL to extract from it the underlying vector of indices:

      r„'r' Œnew 'r'      
      f„r.factor (›'abc' 'def' 'abc')
      f
[r:factor]
      f.Œval
1 2 1

See also ŒREF which does the opposite: it attempts to force data, which would otherwise be 'unboxed', to be returned as an object reference.


Topic: APLX Help : Help on APL language : System Methods : ŒVAL Force value result
[ Previous | Contents | Index ]