cosmos72 / cl-parametric-types

(BETA) C++-style templates for Common Lisp
45 stars 8 forks source link

Importing CL-STL source code #5

Open guicho271828 opened 8 years ago

guicho271828 commented 8 years ago

https://github.com/show-matz/CL-STL is an attempt to implement STL in CL. It's based on CLOS (so it is slow) but yesterday the author, @show-matz , gave a talk on it at Shibuya.lisp Lisp Meetup and I had an opportunity to discuss this project.

cosmos72 commented 8 years ago

I had a look, and it really tries to replicate C++ up to the last detail, including compile-time conditionals to decide between C++98 and some other version of the C++ standard (C++11?), and including vectors, iterators and operators.

My idea for CL-PARAMETRIC-TYPES was: Lispy and fast, i.e. trying to take the good ideas from C++ (templates = generation of specialized code = speed, templatized generic containers, templatized algorithms ...) without necessarily replicating all the details and quirks of C++ standard library

Examples of C++ features I would avoid reimplementing in CL: temporary objects, C++11 rvalue references, copy constructors, assignment operators, destructors, separate pop() and back() due to exception safety in the face of hostile copy-constructors that may throw exceptions... you get the idea.

For example, since CL lacks pointers, to implement one-dimensional arrays I would start from CL native arrays, i.e. (simple-array <t> (*)) for some <t>, and: 1) use it directly if possible - i.e. when no resize is needed 2) wrap it with some template struct to implement resizable arrays

cosmos72 commented 8 years ago

I am currently implementing the following template structs:

guicho271828 commented 8 years ago

BIVECTOR is a deque in C++? I guess keeping the same name as in C++ would be helpful (reduces the learning overhead)

cosmos72 commented 8 years ago

At the moment, BIVECTOR is both C++ std::vector and std::deque. Good point, I will rename it to DEQUE.

More generally, this is the right time to start deciding names, and the fact that several useful names (MAP, LIST, SET, VECTOR...) are already reserved in package COMMON-LISP really does not help. Suggestions are welcome! :) My very incomplete proposal is: