4 ms·
> So reduce can be obviated by just letting the function take variable args too. In Common Lisp the max number of arguments can be small. $ abcl Armed Bea
by lispm 3y ago
> So reduce can be obviated by just letting the function take variable args too.
In Common Lisp the max number of arguments can be small.
$ abcl
Armed Bear Common Lisp 1.8.0
Java 11.0.19 Ubuntu
OpenJDK 64-Bit Server VM
Low-level initialization completed in 0.304 seconds.
Startup completed in 1.501 seconds.
Type ":help" for a list of available commands.
CL-USER(1): CALL-ARGUMENTS-LIMIT
50
- nbernard 3y agoInteresting. Do you know if that is due to constraints coming from ABCL running on a JVM, or is it an arbitrary choice ? (By contrast, SBCL on a x86_64 laptop returns 4611686018427387903...)
- lispm 3y agoUsually these limits are based on the capabilities of the underlying platform (like the JVM) or the implementation choice. One of the goals is to have fast function calls and less so to have long arguments lists. Less than 2^16 isn't that rare. SBCL is more on the large side. Implementations like ABCL, CLISP and some others have much smaller max arglist length limits. Don't use (apply #'+ long-list-of-numbers) but use (reduce #'+ long-list-of-numbers)
- User23 3y agoSo this wasn't what I was expecting. * (disassemble (lambda () (apply #'+ '(1 2 3 4 5)))) ; disassembly for (LAMBDA ()) ; Size: 21 bytes. Origin: #x5345C11B ; (LAMBDA ()) ; 1B: 498B4510 MOV RAX, [R13+16] ; thread.binding-stack-pointer ; 1F: 488945F8 MOV [RBP-8], RAX ; 23: BA1E000000 MOV EDX, 30 ; 28: 488BE5 MOV RSP, RBP ; 2B: F8 CLC ; 2C: 5D POP RBP ; 2D: C3 RET ; 2E: CC10 INT3 16 ; Invalid argument count trap NIL * (disassemble (lambda () (reduce #'+ '(1 2 3 4 5)))) ; disassembly for (LAMBDA ()) ; Size: 21 bytes. Origin: #x5345C1AB ; (LAMBDA ()) ; AB: 498B4510 MOV RAX, [R13+16] ; thread.binding-stack-pointer ; AF: 488945F8 MOV [RBP-8], RAX ; B3: BA1E000000 MOV EDX, 30 ; B8: 488BE5 MOV RSP, RBP ; BB: F8 CLC ; BC: 5D POP RBP ; BD: C3 RET ; BE: CC10 INT3 16 ; Invalid argument count trap NIL
- lispm 3y agoThere is some SBCL compiler optimizer at work.