17 ms·
because .first invokes some machinery. Usually some OOP/FP machinery. The function CAR is a primitive operation in Lisp, which usually gets compiled to only a
by lispm 4y ago
because .first invokes some machinery. Usually some OOP/FP machinery.
The function CAR is a primitive operation in Lisp, which usually gets compiled to only a few basic machine instructions. CAR is basically just returning the first part of a cell made of two pointers (or similar sized immediate data like fixnum integers).
- jefftk 4y ago> because .first invokes some machinery. Usually some OOP/FP machinery. It depends on the language and how you use it. Accessing a member of a C/C++ struct, a final member of a C++ class, Python class with __slots__, etc, is as efficient as a CAR operation. They all give you data that's at a particular place relative to the start your cell/struct/class.
- daly 4y agoWhich is fine until someone changes the C++ struct definition. This 'non-local' change affects the semantics of your code. Lisp's CAR definition is unaffected by non-local changes. You can think in any language but as noted by Wittgenstein “the limits of my language mean the limits of my world." For example, while it is technically possible in any language, the ability to write self-modifying code is unlikely to be thought of in most languages. Try writing non-object oriented code in Java.
- jefftk 4y ago> changes the C++ struct definition I don't think that's right? If we were talking about a class, then yes, but with a struct I don't think there is anything you can do that would change the nature of a property lookup. > This 'non-local' change affects the semantics of your code. I thought we were talking about how to pick a language for performance constrained solo prototyping? In which case you don't need to worry about someone else making changes to your code.