:For :EndFor question

Using (or providing) Microsoft.NET Classes

:For :EndFor question

Postby PGilbert on Sun Nov 23, 2014 11:00 pm

For the following function named 'test':

      ∇test[⎕]∇
[0] test objects;object;⎕USING
[1]
[2] ⎕USING←'System.Windows.Controls,WPF/PresentationFramework.dll'
[3]
[4] :For object :In objects
[5]
[6] object
[7]
[8] :EndFor


The following will work as expected:

Code: Select all
      ⎕USING←'System,mscorlib.dll'

      test DateTime DateTime  ⍝ case 1
(System.DateTime)
(System.DateTime)


But If you do:

Code: Select all
      test DateTime     ⍝ case 2

VALUE ERROR
test[4] :For object :In objects
                    ∧


All the following cases will work:

Code: Select all
      dt←⎕NEW DateTime ⎕TS

      test dt         ⍝ case 3
      test dt dt      ⍝ case 4
      test ,DateTime  ⍝ case 5


And if I remove line [2] of the function 'test' (⎕USING←'System.Windows.Controls,WPF/PresentationFramework.dll') then all the cases are working correctly.

Question: Why case 2 is not working ?

Thanks in advance.
User avatar
PGilbert
 
Posts: 419
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: :For :EndFor question

Postby Tomas Gustafsson on Mon Nov 24, 2014 12:57 pm

5 cents:

Imho this is a bit ouch'ish - at line 1 of fn "test", the interpreter is (kind of) without any ⎕USING at all, yet at that point it has to manage a .net object (passed to the fn). Seems a bit risky? But odd that APL actually is able to recognize the DateTime at all, when there are 2 .net dll's involved. At line 4 in "test" it has to match one created with mscorlib.dll against the ones living in PresentationFramework.dll. But yes, there is an inconsistency.
Tomas Gustafsson
 
Posts: 91
Joined: Mon Sep 19, 2011 6:43 pm

Re: :For :EndFor question

Postby PGilbert on Mon Nov 24, 2014 3:03 pm

Tomas: Your comments are pertinent. I like to be able to use a local ⎕USING in a DFN function for example, but sometimes I am wondering if I should use only one big global ⎕USING for the workspace. Looks tricky to me also to bring a .net object created outside a function into another function that has a local ⎕USING. I have the feeling that, for the interpreter, if you load once the dll into memory it will be available for all the .net objects. Let's wait for the response from Dyalog that should clarify how ⎕USING is behaving under those circumstances.
User avatar
PGilbert
 
Posts: 419
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: :For :EndFor question

Postby Tomas Gustafsson on Mon Nov 24, 2014 5:17 pm

PGilbert wrote:sometimes I am wondering if I should use only one big global ⎕USING for the workspace.

Ah yes that's the conclusion i also made at some point. At very beginning of LX i have

Code: Select all
⎕USING←,⊂'Dyalog,',SYS.Folder,'\bridge132.dll'

and some rows later a jump into fn #._Init.Using

Code: Select all
 Using sysfolder;a

 #.⎕USING,←⊂'System,system.dll'
 #.⎕USING,←⊂   etc

 :If #.SYS.SOCKET_A
     #.⎕USING,←⊂'System.Net,System.Net.dll'
     #.⎕USING,← etc
 :End
etc...

and this #.⎕USING is persistent throughout the lifetime of the app (it's slightly adjusted by what the program is enabled to perform, eg. networking, that's why i set #.⎕USING in two parts, to eb able to adjust, read .ini's etc. before doing the 2nd part). With exceptions ofc; i do indeed also call fns with local ⎕USING, eg.

Code: Select all
 R←Serial2;a;b;b1;b2;b3;c;dnr;getNumber;getQuoteValue;mos;mosobj;M1;M2;z;⎕USING

 ⎕USING←,⊂'System.Management,System.Management.dll'

 mos←ManagementObjectSearcher.New'SELECT * FROM Win32_LogicalDiskToPartition'

but in that case, the .net objects processed are stricly local to that fn.

In particular, it's imho beneficial to have a #.⎕USING, ie. in the root - then a .net constructor is always available from anywhere in the ws, by just assuming root. Also i found that a clean proggy shutdown, that also clears #.⎕USING, is good. Much nicer to be clinically clean when saving the ws :-). I hate having small variables, small global settings etc hanging around, that then the production code (mistakenly or not) relies on.

If one just grabs the prog startup folder at an early stage, one can keep 3rd party assemblies there, and the distribution & packaging of files is much easier.

Code: Select all
 ⎕NA'I Kernel32|GetCurrentDirectoryA I >0T[255]'
 SYS.Folder←2⊃GetCurrentDirectoryA 255 ''⍝ Program startup folder
 ⎕EX'GetCurrentDirectoryA'
Tomas Gustafsson
 
Posts: 91
Joined: Mon Sep 19, 2011 6:43 pm

Re: :For :EndFor question

Postby Vince|Dyalog on Tue Nov 25, 2014 3:05 pm

Hi Pierre and Tomas,

I've logged your :For :In question with a single DateTime as 11674.

Tomas, are you using Dyalog Unicode or Dyalog Classic?

There is an issue logged in our system with localized ⎕USING not completely working as expected--5963.

I think this topic should be in our .NET forum, and I will move it soon.

Regards,

Vince
Vince|Dyalog
 
Posts: 347
Joined: Wed Oct 01, 2008 9:39 am

Re: :For :EndFor question

Postby PGilbert on Tue Nov 25, 2014 3:38 pm

Hello Vince, I have found a workaround for my problem.

      ∇test[⎕]∇
[0] test objects;object;⎕USING
[1]
[2] ⍝ With this line before the ⎕USING the function is working correctly for all the cases.
[3] ⍝ But if it is after the ⎕USING I still get a VALUE ERROR for case 2.
[4] objects←,objects
[5]
[6] ⎕USING←'System.Windows.Controls,WPF/PresentationFramework.dll'
[7]
[8] :For object :In objects
[9]
[10] object
[11]
[12] :EndFor


If I add line [4] before the ⎕USING all cases are working. If line [4]is added after the ⎕USING you still get a VALUE ERROR for case 2.

P.S.: You are correct this is .NET question now.
User avatar
PGilbert
 
Posts: 419
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: :For :EndFor question

Postby Tomas Gustafsson on Tue Nov 25, 2014 6:00 pm

Vince|Dyalog wrote:Tomas, are you using Dyalog Unicode or Dyalog Classic?

Classicum. Anything to decrease the cycles :-).
Tomas Gustafsson
 
Posts: 91
Joined: Mon Sep 19, 2011 6:43 pm


Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest