Page 1 of 1

How to execute a variable

Posted: Sun Oct 08, 2023 12:18 am
by lancepawl
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.

Re: How to execute a variable

Posted: Sun Oct 08, 2023 3:06 pm
by rex
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

Re: How to execute a variable

Posted: Mon Oct 09, 2023 10:27 am
by yaemmanuelli
Hello,
If Y is an integer, a simple answer is :
⍎'CAL',⍕Y
--
Yves-Antoine Emmanuelli.

Re: How to execute a variable

Posted: Tue Oct 10, 2023 10:31 am
by lancepawl
Thanks very much for the answers! I appreciate it.
Regards,
Lance