Cool so what you're telling me is that by default every single function call incurs the unavoidable overhead of indirecting through some lookup for a function bound to a symbol. And you're proud of this?
How about bringing some value to the community?
Next you can find out what optimizing compilers do to avoid it, where possible or where wanted.
>Next you can find out what optimizing compilers do to avoid it, where possible or where wanted.
But compilers I am an expert in and what you're implying is impossible - either you have dynamic linkage, which means symbol resolution is deferred until call (and possibly guarded) or you have the equivalent of RTLD_NOW ie early/eager binding. There is no "optimization" possible here because the symbol is not Schrodinger's cat - it is either resolved statically or at runtime - prefetching symbols with some lookahead or cabinet is the same thing as resolving at calltime/runtime because you still need a guard.
> it is either resolved statically or at runtime
Just tell Lisp which calls to statically resolve, inline, optimize. Overwrite the global default.
(defun foo (a)
(declare (inline +)
(optimize (speed 3))
(type (integer 0 100) a))
(* 10 (+ 3 a)))
Above tells Lisp to inline the + function, optimize for speed and declares the type of a to be an integer in the range 0 to 100. * (disassemble #'foo)
; disassembly for FOO
; Size: 32 bytes. Origin: #x7006DC8544 ; FOO
; 44: 40190091 ADD NL0, R0, #6
; 48: 5C0180D2 MOVZ TMP, #10
; 4C: 0A7C1C9B MUL R0, NL0, TMP
; 50: FB031AAA MOV CSP, CFP
; 54: 5A7B40A9 LDP CFP, LR, [CFP]
; 58: BF0300F1 CMP NULL, #0
; 5C: C0035FD6 RET
; 60: E00120D4 BRK #15 ; Invalid argument count trap
As you can see in the machine code, Lisp then uses the native machine code ADD and MUL instructions.Opinions may vary on that point.
Outside of that you can selectively optimize definitions to empower the system to make better decisions at the cost of runtime protection or dynamism. However these are all compiler specific.
[1] https://cmucl.org/downloads/doc/cmu-user-2010-05-03/compiler...
[2] https://www.sbcl.org/manual/#Miscellaneous-Efficiency-Issues
This isn't the default behaviour though, right?
Here the Lisp simply tries to look up the function object from the symbol. There is no function, so it signals a condition (aka exception). The default exception handler gets called (without unwinding the stack). This handler prints the restarts and calls another REPL. I define the function -> the symbol now has a function definition. We then resume and Lisp tries again to get the function definition. The computation continues where we were.
That's the DEFAULT behavior you'll find in Common Lisp implementations.