< Back to IRCAM Forum

APPLY function Bug

Hello,
I’ve noticed that the APPLY function no longer works after 2048 elements in a list. Although it’s easy to get the desired result in another way, I’d just like to know if there’s a way of overcoming this limitation. The crash I experienced a few months ago when calculating long musical sequences may be due to this problem, which I’ve just isolated.
Thanks in advance for your help.
apply-bug.omp (2.8 KB)

Dear Philippe,

No, this is not a bug, just a LispWorks limitation: See here for more info:

Best
K

Thank you very much dear Karim,
What legendary responsiveness on this early summer Sunday! After consulting your exchange with Thierry de Mey, I’ve come to the conclusion that simply replacing APPLY with REDUCE is a much more elegant way of solving this limitation than what I’d been “tinkering” with in the meantime.
Wishing you a pleasant evening.
apply-vs-reduce.omp (4.4 KB)

2 Likes

I’ve come to the conclusion that simply replacing APPLY with REDUCE is a much more elegant way of solving this limitation

You’re right. Variadic functions (those with a &rest parameter) are intended for reasonably small lists. The bound on the length can be inspected through the system constant cl:call-arguments-limit. As well as overcoming that discomforting restriction, (reduce) can be more efficient, as (apply) may copy the entire list just to be safe.

Depending on your task, you may:

  • Rewrite your function, or add a wrapper, to take a list as an argument;
    • Keep the function variadic and let it take a list argument; ((apply) itself does this in one sense;)
      • Write a macro to perform these steps for multiple functions.

– Jonathan

1 Like

Thanks Jonathan
These additional details to Karim’s will help me to identify any problems of this type, should they arise again. Wishing you a pleasant summer,
Sincerely

1 Like