CSE: Unexpected errors

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

Moderators: Tech Support, phpbb_admin

CSE: Unexpected errors

Postby Ajay Askoolum » September 18th, 2016, 9:12 am

I am using V16.1 (installed using the updater).

I am encountering unexpected errors: see attached WMV.

My code is:
Code: Select all
      ⎕cself←'c' ⎕cse 'Init' 'System'
⍝ Issue 1:
      ⎕cse 'Exec' (⍉,[⍬]"public static int myAge {{} get; set; {}};")
      ⎕cse 'GetLastError' ⍝ NOTE/QUERY Why is the terminating semi-colun an error?
      ⎕cse 'Exec' (⍉,[⍬]"public static int myAge {{} get; set {}}") ⍝ It works without te semi-colun
      ⎕cse 'SetValue' 'myAge' '42'
      1.25 × ⎕cse 'GetValue' myAge'
⍝ Issue 2:
      ⎕cse 'Exec' (⍉,[⍬]"public static int myAge2 {{} get; set; {}} = 42") ⍝ NOTE: No ; BUT default Value specified
      ⎕cse 'GetLastError' ⍝ Why is this an error? [NOTE error - property is of type int]
⍝ Issue 3:
      ⎕cse 'Exec' (⍉,[⍬]"public static string myName {{} get; set; {}}") ⍝ Omitting the semi-colum to avoid a repeat error
      ⎕cse 'SetValue' 'myName' 'Ajay'
      ⎕cse 'GetLastError' ⍝ ⍝ Why is this an error? [NOTE error - property is of type string]

      ⍝ Works for variables
      ⎕cse 'ExecStmt' 'public string thisName;'
      ⎕cse 'SetValue' 'thisName' 'Ajay'
      ⎕cse 'GetValue' 'thisName'
⍝ Summary:
⍝ 1. Why is the ternminating semi-colon an error? Note - the statement is valid in VS2015.
⍝ 2. Why can't I set a default value for a public property?
⍝ 3. Why can't I assign to a property of stype string?
Attachments
CSE ERRORS.wmv
(4.87 MiB) Downloaded 38 times
Ajay Askoolum
 
Posts: 656
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: CSE: Unexpected errors

Postby Ajay Askoolum » September 18th, 2016, 2:34 pm

Apologies: the property definition terminating with semi-colon is an error (in VS 2015) unless a default value is specified. Please ignore the first question.
Ajay Askoolum
 
Posts: 656
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: CSE: Unexpected errors

Postby joe_blaze » September 29th, 2016, 2:40 pm

We will research your questions are report back when we have results of that research.
joe_blaze
 
Posts: 383
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361

Re: CSE: Unexpected errors

Postby joe_blaze » September 29th, 2016, 2:58 pm

Have you seen this: http://stackoverflow.com/questions/4691888/automatic-property-with-default-value. It appears that the 'automatic property definition' syntax may not support default values and that a 'backing' variable may be needed. Where did you obtain the syntax "public static int myAge2 {{} get; set; {}} = 42"?

e.g.:

private int m_HowHigh = 5;
public int HowHigh
{
get { return m_HowHigh; }
set { m_HowHigh = value; }
}
joe_blaze
 
Posts: 383
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361

Re: CSE: Unexpected errors

Postby joe_blaze » September 29th, 2016, 3:01 pm

On the other question, the issue appears to be related to the 'static' keyword, although I don't yet understand the CS0266 error code which the C# compiler is returning


⎕cse 'ExecStmt' 'public string myName{get;set;}'
0
⎕cse 'SetValue' 'myName' 'Joe'
0
⎕cse 'ExecStmt' 'public static string myName2{get;set;}'
0
⎕cse 'SetValue' 'myName2' 'Joe'
¯1

⎕cse 'GetLastError'
(1,11): error CS0266: Cannot implicitly convert type 'object' to 'string'. An ex
plicit conversion exists (are you missing a cast?)

⎕cse 'ExecStmt' 'myName2 = myName;'
0
⎕cse 'GetValue' 'myName2'
Joe
joe_blaze
 
Posts: 383
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361

Re: CSE: Unexpected errors

Postby Ajay Askoolum » September 29th, 2016, 4:57 pm

My code above has managed to acquire stray curly brackets; apologies.
It appears that the 'automatic property definition' syntax may not support default values and that a 'backing' variable may be needed.
That is definitely not the case and neither is a backing variable required. You could try out the code in Visual Studio - the project is in PROOF.ZIP which is attached. For convenience here's the code:
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PROOF
{
    class Program
    { // Trying it in VS2015
        public static int myAge2 { get; set; } = 42;
        public static string thisName { get; set; } = "apl2000";
        static void Main(string[] args)
        {
            Console.WriteLine("Writing Defaults:");
            Console.WriteLine("muAge2 = {0} thisName = {1}",myAge2,thisName);
           
            Console.WriteLine("Overwriting Defaults:");
            myAge2 = 42 + 42;
            thisName = "APL LLC";
            Console.WriteLine("muAge2 = {0} thisName = {1}", myAge2, thisName);
            Console.ReadLine();
        }
    }
}
As you can see both the int and string properties have a default value and I can simply override them.

Alternatively, you could simply run \C#\VS2015\PROOF\PROOF\bin\Release\PROOF.exe from the location wherein you have extracted the files from the ZIP.

[]cse does NOT allow the default values. With the string property, I get the error you show:
Code: Select all
 Œcse 'SetValue' 'thisName' 'apl2000'
CSE ERROR: (1,12): error CS0266: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
I think I should be able to assign to a string property in the same manner as I can assign to a string variable.
Attachments
PropertyDefault.png
PropertyDefault.png (7.2 KiB) Viewed 1605 times
PROOF.zip
(42.39 KiB) Downloaded 31 times
Ajay Askoolum
 
Posts: 656
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: CSE: Unexpected errors

Postby joe_blaze » September 30th, 2016, 2:44 am

The error messages received come directly from the C# debugger or compiler and not APL+Win, so it may be that the operations you want to perform, which are available in the version of Visual Studio you are using, may not be available in the Dynamic Language Runtime used by the CSE. What is the version of Visual Studio you are using?
joe_blaze
 
Posts: 383
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361

Re: CSE: Unexpected errors

Postby Ajay Askoolum » September 30th, 2016, 6:00 am

I am using Visual Studio 2015 Enterprise. The project uses .Net Framework 4.6.1.

I realize that the error is coming from c#.

I understand that CSE is also using framework 4.6.

[]cse 'ExecStmt' 'string myVariable;'
[]cse 'SetValue' 'myVariable' 'new value'

In the latter statement, there must be something that is permitting 'new value' to make its way from APL+Win to the C# debugger/compiler' successfully. The same thing is required for string properties, I believe.

There is no issue with int properties.

As regards the default value for properties, my guess is that []cse must be validating the statement and validating the syntax - ensuring that there is NO trailing semi-colon. When you specify a default value, there is a terminating semi-colon.
Ajay Askoolum
 
Posts: 656
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: CSE: Unexpected errors

Postby joe_blaze » September 30th, 2016, 11:55 am

Actually all validation of a C# statement is done by the C# parser, debugger or compiler and not by APL+Win, so there is still some investigation to be done, but that will take more time.

Note the difference with a static or non-static string property - that is what will need further checking.

⎕cse 'ExecStmt' 'public string myName{get;set;}'
0
⎕cse 'SetValue' 'myName' 'Joe'
0 <---- non-static string property successfully set
⎕cse 'ExecStmt' 'public static string myName2{get;set;}'
0
⎕cse 'SetValue' 'myName2' 'Joe'
¯1 <---- stati string propery not successfully set
joe_blaze
 
Posts: 383
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361

Re: CSE: Unexpected errors

Postby Ajay Askoolum » October 1st, 2016, 2:53 am

Thank you. It is interesting that a static variable does NOT have the same issue.
Code: Select all
      ⎕cse 'ExecStmt' 'static string qw;'
0
       ⎕cse 'SetValue' 'qw' 'ajay askoolum'
0
      ⎕cse 'GetValue' 'qw'
ajay askoolum
I'll await the results of your investigation
1. Why does the assignment to a static string property fail?
2. Why does []cse not permit default values for properties, static or non-static?

What is the compiler version used by []CSE? Is it:
Code: Select all
Compiler version 4.0.30319.17929
or later? This or earlier versions appear to have the same problem.
You may be interested in this:
Attachments
Roslyn.png
Roslyn.png (20.3 KiB) Viewed 1581 times
Ajay Askoolum
 
Posts: 656
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: CSE: Unexpected errors

Postby joe_blaze » October 13th, 2016, 3:56 am

Hi Ajay:

Here is a way to do what you request:

⎕cself←'c1'⎕cse 'Init' 'System'
⎕cse 'ExecStmt' 'using System;'
0
⎕cse 'ExecStmt' 'public static string s3 {get;set;}'
0
⎕cse 'ExecStmt' 's3={0}' '"s3"'
0
⎕cse 'GetValue' 's3'
s3

The syntax for the default value of a property without a back property, will require updating the CSE to a newer version of the Microsoft Roslyn C# compiler. We are examining that possibility.
joe_blaze
 
Posts: 383
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