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 !
Post Reply
lancepawl
Posts: 10
Joined: Tue Sep 05, 2017 1:43 pm

How to execute a variable

Post 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.
rex
Posts: 12
Joined: Sat Jun 10, 2023 10:49 pm
Contact:

Re: How to execute a variable

Post 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
User avatar
yaemmanuelli
Posts: 16
Joined: Sat Aug 01, 2020 6:29 pm
Location: Recloses, France
Contact:

Re: How to execute a variable

Post by yaemmanuelli »

Hello,
If Y is an integer, a simple answer is :
⍎'CAL',⍕Y
--
Yves-Antoine Emmanuelli.
--
Yves-Antoine Emmanuelli
lancepawl
Posts: 10
Joined: Tue Sep 05, 2017 1:43 pm

Re: How to execute a variable

Post by lancepawl »

Thanks very much for the answers! I appreciate it.
Regards,
Lance
Post Reply