Hacker News new | ask | show | jobs
by lispm 1114 days ago
Usually 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)
1 comments

So 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
There is some SBCL compiler optimizer at work.