[]wi

26 views
Skip to first unread message

Ajay Askoolum

unread,
Sep 12, 2020, 2:37:36 PM9/12/20
to APLWin
Have you got code snippets demonstrating the use of < and @ with []wi?
I am trying to get a COM server to update a variable in the workspace & wondering if < or @ are somehow involved in making it happen.

Rex Swain

unread,
Sep 12, 2020, 2:53:41 PM9/12/20
to APLWin
You probably know this already, but you use the @ symbol to get typed values.
Try  ⍉'xl.rng' ⎕wi 'xValue @'   with and without the at-sign.

You can use the less-than symbol to feed values.  The APL+Win manual gives this example: 
VB:  prefs.LongPref(27) = 999
APL:  'prefs' ⎕wi 'LongPref <' 27 999 

Are you looking to read a property?  This might be applicable:  "If you use the greater-than sign but you do not follow it with a name, this signals the system that you are referencing a property or invoking a method."

Ajay Askoolum

unread,
Sep 12, 2020, 3:31:49 PM9/12/20
to APLWin
I have written a COM in C#; one of its methods, uses a ref variable to pass pack information independently of the result of the method.In Excel:

1.       Sub aa()

2.       Set cf = CreateObject("aplwincf.componentfile")

3.       Dim feedback As String

4.       comp = ActiveSheet.Range("A1:F6").Value2

5.       cf.writecomponent "ajay", comp, feedback

6.       rb = cf.ReadComponent("ajay")

7.       End Sub

 The passback variable is feedback, declare on line 3,. If I examine its value after line 5, it contains the value passed back BUT there is no explicit assignment. In APL

      feedback←⍬
     ⎕wi 'WriteComponent' 'ajay' R feedback
 1 aplw
     feedback ⍝ does not has not changed

      (res feedback)←⎕wi 'WriteComponent' 'ajay' R feedback
      feedback ⍝ - now has the value
aplw

I was wondering whether []wi @ might enable me to get 'feedback' updated.

Thanks for your response. (I can never find the topics < > or @ in the help file). I'l  experiment further.

Davin Church

unread,
Sep 12, 2020, 3:38:56 PM9/12/20
to APLWin
What's your ADF-style definition of WriteComponent?

Ajay Askoolum

unread,
Sep 12, 2020, 3:58:22 PM9/12/20
to APLWin
Not sure what you mean by ADF definition. Doesn't ADF apply to Win32 DLLs only?

My DLL is an in-process COM DLL; if it helps:

      ⎕wi '?WriteComponent'
XWriteComponent method:
  Result@Long feedback ← ⎕WI 'XWriteComponent' Name@String value feedback [adjust]

But the signature in C# is:

 public int WriteComponent(string Name, dynamic value, ref object feedback, dynamic adjust = null)

In C# the result from the method is int (i.e. a scalar) but in APL, it is 

Result@Long feedback   

That is,  it is receiving the ref variable in the result.

Ajay Askoolum

unread,
Sep 12, 2020, 4:28:30 PM9/12/20
to APLWin
In Excel, (see attached), the function header is different - it just returns a @long
Untitled.png

Davin Church

unread,
Sep 12, 2020, 4:58:41 PM9/12/20
to APLWin
Sorry - I was thinking of []WCALL rather than []WI.  The ADF definitions apply to all []WCALLs whether they're Win32 or not.

I don't remember any specific way to return reference values from []WI, I think it may handle only explicit results.  Perhaps your routine might assign a property instead that could then be referenced with a separate []WI?

Rex Swain

unread,
Sep 12, 2020, 6:55:53 PM9/12/20
to APLWin
When you use feedback as an argument to ⎕wi, only the value of feedback is passed to ⎕wi -- there is no way that your component will know the APL name of the value that it received.  

So I am not surprised that your variable did not change.  In fact, I prefer this -- if my variable is going to be changed, I like to see an assignment arrow next to the name!

With ⎕wcall, you sometimes see variables get passed to Windows functions like that, but often they are being used to indicate the type and amount of storage needed.  The returned data is returned by ⎕wcall, not stored in the variable:

      V←144⍴⎕TCNUL
      ⎕wcall 'GetWindowsDirectory' V 144
 10 C:\Windows
      V^.=⎕TCNUL
1

Ajay Askoolum

unread,
Sep 13, 2020, 2:09:58 AM9/13/20
to APLWin
If you look at line 5 of the Excel code above, the feedback variable is also passed by values and it does change. Likewise when I execute the equivalent code in C# and []CSE.

I prefer the way []wi & []wcall work AND it is no hardship -  it would have been nice to have a feature that allowed consistency with the way it works in Excel if only because that would make code migration to APL easier.

The crucial difference is that in order for the feedback variable in the calling environment to change,  it has to be declared (strongly types). Your call in Excel VBA:

1.       Sub GetDWinDir()

2.       Dim feedback As String

3.       feedback = Space(255)

4.       ret = GetWindowsDirectory(feedback, 255)

5.       windir = Left(feedback, InStr(feedback, Chr(0)) - 1)

6.       MsgBox windir

7.       End Sub

The variable is declared in line 3 and after line 4, it has changed - line 5 uses it to extract the relevant part.

APL has NO way of declaring a variable by type. I tried to use '#' []wi 'VT' as a means of declaring a variable but that did not work (probably because []wi is designed to ignore the variable).



Davin Church

unread,
Sep 13, 2020, 11:18:20 AM9/13/20
to APLWin
GetWindowsDirectory is expecting a pointer, not an actual value.  It then uses that pointer to change the contents of what it points to.

APL can VT a variable type, but it has to be the way it's expected.  I've used it to create Date types to supply when nothing else would be accepted.
Reply all
Reply to author
Forward
0 new messages