Feature request: Force default result on calls without one.

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

Feature request: Force default result on calls without one.

Postby norbertjurkiewicz84 on Fri Jul 28, 2017 1:34 pm

Often times my D functions call other functions and .NET methods that do not return anything. This happens often with WPF calls. I often fall back to executing a statement within a nested guarded expression or covering the (.NET) call in a Tfn to force a result. An I-Beam or another language feature to do the same would be a nice shortcut.

      test←{
⎕USING←'System' 'System.Windows,WPF/PresentationFramework.dll'

⍝ Option 0. Execute and get out
w←⎕NEW Window
⍝ w.Show
⍝ ...

⍝ Option 1. Fails with a VALUE ERROR
w←⎕NEW Window
ok←w.Show

⍝ Option 2. This works but needs extra encapsulation.
w←⎕NEW Window
ok←{6::0 ⋄ _←⍵.Show}w

⍝ Option 3. Use a TradFn for the call
exec←'Z←ShowCover window' 'window.Show' 'Z←0'
_←⎕FX exec
w←⎕NEW Window
ok←ShowCover w

⍝ ...
⍝ do other stuff ...
⍝ ...
0
}


My thought is maybe something along these lines.

Code: Select all
     ⍝ ok ← (?⌶)w.Show
     ⍝ ok = 0
     ⍝ ok ← 1(?⌶)w.Show
     ⍝ ok = 1
User avatar
norbertjurkiewicz84
 
Posts: 62
Joined: Mon Nov 01, 2010 7:26 pm

Re: Feature request: Force default result on calls without o

Postby JohnS|Dyalog on Fri Jul 28, 2017 2:31 pm

I think a function derived from I-beam might be a problem because the VALUE ERROR would occur before we got to it. However a system operator (⎕something) might fit the bill. See http://dfns.dyalog.com/n_do.htm for a model.

PS: I like your idea of optionally passing the preferred result as left argument.
JohnS|Dyalog
 

Re: Feature request: Force default result on calls without o

Postby norbertjurkiewicz84 on Fri Jul 28, 2017 3:04 pm

JohnS|Dyalog wrote:I think a function derived from I-beam might be a problem because the VALUE ERROR would occur before we got to it. However, a system operator (⎕something) might fit the bill. See http://dfns.dyalog.com/n_do.htm for a model.

PS: I like your idea of optionally passing the preferred result as the left argument.



I think I used that technique a while back but it has the same issue as the above. You need to create it in your namespace or reference a full path to a utility.
User avatar
norbertjurkiewicz84
 
Posts: 62
Joined: Mon Nov 01, 2010 7:26 pm


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest