Function with multiple arguments

General discussions related to using the C# Script Engine in APL+Win.

Moderators: Tech Support, phpbb_admin

Function with multiple arguments

Postby Ajay Askoolum » November 12th, 2013, 3:41 pm

Please refactor this code
Code: Select all
using System;
public static int add(int a,int b,int c)
        {
            return (a+b+c);
        }

and show me how to call it using []cse such that a, b and c are passed from the workspace which already has these values defined.

I have tried everything I can think of to no avail.

Code: Select all
      '∆we' ⎕cse 'GetValue' 'add' 1 2 3 
CSE ERROR: Incorrect number of arguments
      '∆we' ⎕cse 'GetValue' 'add' 1 2 3   
            ^
      '∆we' ⎕cse 'GetValue' 'add(,,)' 1 2 3 
CSE ERROR: Incorrect number of arguments
      '∆we' ⎕cse 'GetValue' 'add(,,)' 1 2 3   
            ^
      '∆we' ⎕cse 'SetValue' 'add' 1 2 3 
CSE ERROR: Incorrect number of arguments
      '∆we' ⎕cse 'SetValue' 'add' 1 2 3   
            ^
      '∆we' ⎕cse 'ExecStmt' 'add' 1 2 3 
CSE ERROR: Incorrect number of arguments
      '∆we' ⎕cse 'ExecStmt' 'add' 1 2 3   
            ^
      '∆we' ⎕cse 'SetValue' 'add' (⊂1 2 3)
CSE ERROR: failed to create VARIANT variable
      '∆we' ⎕cse 'SetValue' 'add' (⊂1 2 3) 
            ^
      '∆we' ⎕cse 'SetValue' 'add' (1 2 3)
¯1
      '∆we' ⎕cse 'SetValue' 'add' (⊂(1 1⍴1) (1 1⍴2) (1 1⍴3)  )
CSE ERROR: failed to create VARIANT variable
      '∆we' ⎕cse 'SetValue' 'add' (⊂(1 1⍴1) (1 1⍴2) (1 1⍴3)  )
            ^
      '∆we' ⎕cse 'SetValue' 'add' ((1 1⍴1) (1 1⍴2) (1 1⍴3)  )
¯1
Ajay Askoolum
 
Posts: 656
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Fuunction with multiple arguments

Postby joe_blaze » November 13th, 2013, 12:27 am

Hi Ajay,

Transferring APL+Win data to the C# domain of a CSE instance requires that the creation of a compatible recipient variable on the C# side to contain the APL+Win data.
Execution of a C# method and transfer of data from APL+Win to C# are separate operations.

Here are some ways to accomplish the intent of your example:
[]cse 'ExecStmt' 'Int32 a =0; Int32 b=0; Int32 c=0;'
[]cse 'SetValue' 'a' 123
[]cse 'SetValue' 'b' 456
[]cse 'SetValue' 'c' 789
[]cse 'GetValue' 'add(a,b,c)'
or
[]cse 'ExecStmt' 'Int32[] x = new Int32[]{};'
[]cse 'SetValue' 'x' (123 456 789)
[]cse 'GetValue' 'add(x[0], x[1], x[2])'
or
[]cse 'GetValue' 'add(123, 456, 789)'

The syntax you are requesting: something like: []cse 'GetValue' 'add(a,b,c)' 123 456 689, would require that APL+Win perform parsing of an C# executable statement.
The APL+Win interpreter would have to duplicate all the parsing technology of C# and the .Net Framework.
That is because the C# debugger and compilier only accept valid C# executable statements.

In your example APL+Win would have to convert: []cse 'GetValue' 'add(a,b,c)' 123 456 789 to a valid C# executable statement: []cse 'GetValue' 'add(123,456,789)'.
That analysis by APL+Win may seem simple, but there are many more syntactical possibilities in C# which would have to be performed in APL+Win.
In addition if any argument to the C# method (add(,,) in your example) were not a C# data type analogous to an APL+Win data type, some conversion would have to be performed
or some intermediate C# variables would have to be created.

Duplicating the C# parsing engine in APL+Win would mean that every time there is a Microsoft modification to the .Net Framework, the APL+Win interpreter would need modification too.
That is not the intention of the []cse implementation.
Instead the []cse is an interface to the .Net Framework via the C# programming language.
The []cse system function in APL+Win is designed to send valid C# executable statements (unmodified by the APL+Win interpreter) to the C# debugger and compiler.
The CSE in APL+Win has been implemented this way so that no (code breaking) modifications or syntax were required in APL+Win and transparent access to the full .Net Framework is possible in APL+Win.
This means that the []CSE interface to .Net in APL+Win is not a duplication, reduction or cover for .Net functionality.
APL+Win exposes the full .Net Framework, but APL+Win is not integrated with the .Net Framework (i.e. it is not modified to suit the .Net Framework).

VisualAPL supports the C# syntax that you are requesting in a very direct and simple way,
e.g. in VisualAPL one could just type: add(123, 456, 789) [Enter] and get the result.
That's because VisualAPL is integrated with .Net, VisualAPL has direct access to the C# debugger and compiler and
VisualAPL is a modified form of APL which has numerous additional syntactical options not found in traditional APL, including comma-separated arguments to VisualAPL functions.
Some of the modifications to APL necessary to integrate VisualAPL with the .Net Framework would 'break' traditional APL code.

For APL+Win to have the same benefits of VisualAPL would mean that APL+Win would have to become VisualAPL
with all the modifications to APL which were required in VisualAPL to accommodate the .Net Framework requirements.

The origin of your request is probably a potential parallel in the available syntax for the APL+Win []wi ActiveX interface.
The APL+Win []wi ActiveX interface provides for implied syntactical placeholders and implied intermediate variables between the ActiveX component and APL+Win.
That works with APL+Win and ActiveX because ActiveX components and APL+Win share the same simple data types.

Joe Blaze
joe_blaze
 
Posts: 384
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361

Re: Function with multiple arguments

Postby Ajay Askoolum » November 13th, 2013, 1:41 am

Given:

using System;
public static int add(int a,int b,int c)
{
return (a+b+c);
}

EITHER:

Code: Select all
      '∆we' ⎕cse 'GetValue' 'add(1,2,3);'     
6


This can be really messy for all but simple arguments.

OR:

Code: Select all
      '∆we' ⎕cse 'ExecStmt' 'int a; int b; int c;'
0
      '∆we' ⎕cse 'SetValue' 'a' 1
0
      '∆we' ⎕cse 'SetValue' 'b' 2
0
      '∆we' ⎕cse 'SetValue' 'c' 3
0
      '∆we' ⎕cse 'GetValue' 'add(a,b,c);'     
6


After my last statement, a, b, c remain as clutter and if I should accidentally refer to any of those variables, I will get spurious answers.

WISH:

Code: Select all
      '∆we' ⎕cse 'GetValue' 'add(,,);' 1 2 3


With Reflection, []CSE can figure out the names of the arguments and pass them by position? And report any errors immediately?
Ajay Askoolum
 
Posts: 656
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Function with multiple arguments

Postby joe_blaze » May 22nd, 2014, 11:27 am

In the version of the CSE which is included with APL+Win v14.1.01 check out the section of the CSE manual which discusses the new 'Scalar value type substitution of APL+Win values' feature.
joe_blaze
 
Posts: 384
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361


Return to APL+Win & The C# Script Engine

Who is online

Users browsing this forum: No registered users and 1 guest

cron