⎕SIGNAL/

For users of dfns, both novice and expert

⎕SIGNAL/

Postby Phil Last on Wed Mar 13, 2019 12:27 am

While writing code intended to be used as far back as Dyalog v14.0 I recently got hit with an error that I'd managed to avoid for the best part of twenty years because Dyalog introduced another way to avoid it.

v16.0 introduced a shy result to
      [msg] ⎕SIGNAL ⍬
that previously had none. Prior to that it was thought to be necessary to place all instances of ⎕SIGNAL within dfns behind guards to avoid the consequences of their not having results when they weren't tiggered.

Since the introducton of the result I've used it a few times in v16.0 forgetting that I had a solution all along that would have worked in v9.0 had I thought of it back then; it actually took me 'til about v11.0 or v12.0.
      z←⎕signal/ b ↓ m n
where m is the error message, n is the error number and b is a boolean scalar indicating no error.

If b is true m is dropped, the argument to ⎕SIGNAL/ is singleton n and reduction runs its operand exactly zero times on such an argument, returning it unchanged, so the dfn can continue.

If false, reduction inserts ⎕SIGNAL between m and n and signals as expected.
User avatar
Phil Last
 
Posts: 512
Joined: Thu Jun 18, 2009 6:29 pm

Re: ⎕SIGNAL/

Postby gil on Wed Mar 13, 2019 9:50 pm

Neat! I'll try to remember that.
gil
 
Posts: 66
Joined: Mon Feb 15, 2010 12:42 am


Return to Functional Programming

Who is online

Users browsing this forum: No registered users and 0 guests