How to execute a variable

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 !

How to execute a variable

Postby lancepawl on Sun Oct 08, 2023 12:18 am

I don't know what this is called, but I think it's possible in APL. Let's say I have matrixes with for example, calendar data, called CAL2020, CAL2021, CAL2022, and I have a function that I call with a year value for Y, for example PLOTCALENDAR 2021. So when the function is called, Y will have a value such as 2021, 2022, etc. I then want to read from the matrix for that year, such as CAL2021. I believe there is a way to access the variable using by piecing together 'CAL' and Y. Does anyone know? Thanks.
lancepawl
 
Posts: 10
Joined: Tue Sep 05, 2017 1:43 pm

Re: How to execute a variable

Postby rex on Sun Oct 08, 2023 3:06 pm

You used the right word in your subject line.
You want the "execute" primitive ⍎.

If your Y is a character vector like '2021', then you want
M←⍎'CAL',Y
If your Y is an integer like 2021, then you want
M←⍎'CAL',⍕Y
rex
 
Posts: 12
Joined: Sat Jun 10, 2023 10:49 pm

Re: How to execute a variable

Postby yaemmanuelli on Mon Oct 09, 2023 10:27 am

Hello,
If Y is an integer, a simple answer is :
⍎'CAL',⍕Y
--
Yves-Antoine Emmanuelli.
--
Yves-Antoine Emmanuelli
User avatar
yaemmanuelli
 
Posts: 16
Joined: Sat Aug 01, 2020 6:29 pm
Location: Recloses, France

Re: How to execute a variable

Postby lancepawl on Tue Oct 10, 2023 10:31 am

Thanks very much for the answers! I appreciate it.
Regards,
Lance
lancepawl
 
Posts: 10
Joined: Tue Sep 05, 2017 1:43 pm


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest