Question on Execute

General APL language issues

Question on Execute

Postby bilekflo on Sat Jul 16, 2022 6:21 pm

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
bilekflo
 
Posts: 28
Joined: Wed Mar 12, 2014 10:07 pm

Re: Question on Execute

Postby Adam|Dyalog on Sat Jul 16, 2022 11:14 pm

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│
└────┴┴────┘
User avatar
Adam|Dyalog
 
Posts: 134
Joined: Thu Jun 25, 2015 1:13 pm

Re: Question on Execute

Postby bilekflo on Mon Jul 18, 2022 5:24 am

Hi Adam,

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

Kind regards,
Florian
bilekflo
 
Posts: 28
Joined: Wed Mar 12, 2014 10:07 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest