Page 1 of 1

Question on Execute

Posted: Sat Jul 16, 2022 6:21 pm
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

Re: Question on Execute

Posted: Sat Jul 16, 2022 11:14 pm
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│
└────┴┴────┘

Re: Question on Execute

Posted: Mon Jul 18, 2022 5:24 am
by bilekflo
Hi Adam,

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

Kind regards,
Florian