News for hackers. Stuff that matters.
Re:It's 2023, so of course I'm learning Common Lisp by mathisfun123 on Thursday July 27, 2023 @04:25AM (#36890569)
>Common Lisp programs run by default in a way that calls to undefined functions are detected.

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?

Re:It's 2023, so of course I'm learning Common Lisp by ghfwlc on Thursday July 27, 2023 @04:46AM (#36890698)
Compared to Python, Common Lisp hardly has any performance issues.
Re:It's 2023, so of course I'm learning Common Lisp by mathisfun123 on Thursday July 27, 2023 @04:55AM (#36890778)
Okay well when pytorch, tensorflow, pandas, Django, flask, numpy, networks, script, xgboost, matplotlib, spacy, scrapy, selenium get ported to lisp, I'll consider switching (only consider though since the are probably at least another 20 python python packages that I couldn't do my job without).
Re:It's 2023, so of course I'm learning Common Lisp by svetlyak40wt on Thursday July 27, 2023 @06:24AM (#36891478)
That is a typical consumerism: "Give me everything ready to use and then I'll use it."

How about bringing some value to the community?

Re:It's 2023, so of course I'm learning Common Lisp by rwxrwxrwx on Thursday July 27, 2023 @10:54AM (#36894525)
For the sake of anyone reading this thread who isn't in the know: many of these libraries are really written in C/C++ and have Python bindings.
Re:It's 2023, so of course I'm learning Common Lisp by mathisfun123 on Thursday July 27, 2023 @04:21PM (#36899597)
i said ported not implemented; the likelihood that any of those libraries sprout lisp bindings is about as likely as them being rewritten in lisp. so it's the same thing and the point is clear: i don't care about some zany runtime feature, i care about the ecosystem.
Re:It's 2023, so of course I'm learning Common Lisp by rwxrwxrwx on Friday July 28, 2023 @12:44AM (#36903177)
Stop moving the goalposts: your answer to a commenter who stated that Common Lisp was faster than Python (a fact) was a list of packages, many of which are (1) not even written in Python and (2) some of them actually do have Common Lisp bindings.
Re:It's 2023, so of course I'm learning Common Lisp by lispm on Thursday July 27, 2023 @04:50AM (#36890735)
I thought you know Lisp? Now you are surprised that Lisp often looks up functions via symbols -> aka "late binding"? How can that be? That's one of the basic Lisp features.

Next you can find out what optimizing compilers do to avoid it, where possible or where wanted.

Re:It's 2023, so of course I'm learning Common Lisp by mathisfun123 on Thursday July 27, 2023 @05:03AM (#36890858)
At no point in time did I claim to know lisp well. I stated my familiarity at the outset. But what you all did was claim to know a lot about every other interpreted runtime without a grain of salt.

>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.

Re:It's 2023, so of course I'm learning Common Lisp by lispm on Thursday July 27, 2023 @05:37AM (#36891101)
> But compilers I am an expert in and what you're implying is impossible

> 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.
Re:It's 2023, so of course I'm learning Common Lisp by tsimionescu on Thursday July 27, 2023 @06:17AM (#36891417)
What you're missing is that, unlike any other commonly used language runtime, compilation in CL is not all-or-nothing, nor is it left solely to the runtime to decide which to use. A CL program can very well have a mix of interpreted functions and compiled functions, and use late or eager binding based on that. This is mostly up to the programmer to decide, by using declarations to control how, when, and if compilation should happen.
Re:It's 2023, so of course I'm learning Common Lisp by regularfry on Thursday July 27, 2023 @09:56AM (#36893574)
To be fair, any dynamic language with a JIT will mix interpreted and compiled functions, and will probably claim as a strength not leaving to the programmer the problem of which to compile.

Opinions may vary on that point.

Re:It's 2023, so of course I'm learning Common Lisp by whartung on Thursday July 27, 2023 @02:17PM (#36897928)
It should also be noted that by spec symbols in the system package (like + and such) should not be redefined. This offers “unspecified” behavior and lets the system make optimizations out of the box.

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.

Re:It's 2023, so of course I'm learning Common Lisp by kazinator on Friday July 28, 2023 @03:33AM (#36903981)
* * *
Re:It's 2023, so of course I'm learning Common Lisp by tsimionescu on Thursday July 27, 2023 @06:12AM (#36891384)
Do you think Python or Ruby or PHP are any different? And yet, not one of them actually chose to use this in a sane way, where a simple lookup error doesn't have to crash the whole program.
Re:It's 2023, so of course I'm learning Common Lisp by User23 on Thursday July 27, 2023 @01:57PM (#36897618)
That depends. The Common Lisp standard says nothing on the subject. CMUCL[1] and its descendent SBCL[2] do something clever called local call. It's not terribly difficult to optimize hot spots in your code to use local call. Outside of the bottlenecks, the full call overhead isn't significant for the overwhelming majority of cases. It's not like full call is any more expensive than a vtable lookup anyhow.

[1] https://cmucl.org/downloads/doc/cmu-user-2010-05-03/compiler...

[2] https://www.sbcl.org/manual/#Miscellaneous-Efficiency-Issues

Re:It's 2023, so of course I'm learning Common Lisp by kazinator on Friday July 28, 2023 @02:41AM (#36903696)
* * *
Re:It's 2023, so of course I'm learning Common Lisp by chuchana on Friday July 28, 2023 @04:39AM (#36904331)
> If f and g are in the same file, where g calls f, then implementations are not required to allow f and go to be separately redefinable. So that is to say, if f is redefined only, the existing g may keep calling the old f. The intent is that redefinition has the granularity of compiled files: if a new version of the entire compiled file is loaded, then f and g get redefined together and all is cool.

This isn't the default behaviour though, right?