Question on Execute

General APL language issues
Post Reply
bilekflo
Posts: 28
Joined: Wed Mar 12, 2014 10:07 pm

Question on Execute

Post by bilekflo »

I wanted to use Execute to convert numeric characters to numbers.

⍎¨'12 4' ' ' '4566'

Since the third item is a blank, the whole statement returns nothing. I wonder if this is according to the specifications because the two other items can be executed and would return values. Should not be that the statement should return a two element vector?

Kind regards,
Florian
User avatar
Adam|Dyalog
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: Question on Execute

Post by Adam|Dyalog »

By definition, f¨Y must give an array of the same shape as Y, so if Y has 3 elements, as in your example, the result must too. But since one of the applications of ⍎ returns nothing, then ⍎¨ cannot return anything either.

You could work around this by appending ',⍬' to each vector before execution, which also ensures that each returned element is a vector (4566 would be a scalar otherwise):
      ⍎¨'12 4' ' ' '4566',¨⊂',⍬'
┌────┬┬────┐
│12 4││4566│
└────┴┴────┘

However, using ⍎ to convert text to numbers is in general unsafe and unreliable. The industrial solution is to use ⎕VFI:
      2⊃∘⎕VFI¨'12 4' ' ' '4566'
┌────┬┬────┐
│12 4││4566│
└────┴┴────┘
bilekflo
Posts: 28
Joined: Wed Mar 12, 2014 10:07 pm

Re: Question on Execute

Post by bilekflo »

Hi Adam,

Thanks for the explanations and suggestion. I use ⎕VFI now instead of execute.

Kind regards,
Florian
Post Reply