4 ms·
Has anyone grafted Zig style macros into Common Lisp?
by User23 1y ago
Has anyone grafted Zig style macros into Common Lisp?
- toxik 1y agoIsn’t this kind of thing sort of the default thing in Lisp? Code is data so you can transform it.
- fn-mote 1y agoThere are no limitations on the transformations in lisp. That can make macros very hard to understand. And hard for later program transformers to deal with. The innovation in Zig is the restrictions that limit the power of macros.
- TinkersW 1y agoLisp is so powerful, but without static types you can't even do basic stuff like overloading, and have to invent a way to even check the type(for custom types) so you can branch on type.
- pjmlp 1y agoNo need for overloading when you have CLOS and multi-method dispatch.
- dokyun 1y ago> Lisp is so powerful, but <tired old shit from someone who's never used Lisp>. You use defmethod for overloading. Types check themselves.
- User23 1y agoAnd a modern compiler will jmp past the type checks if the inferencer OKs it!
- aidenn0 1y agoWhich the inferencer probably can't do because of how dynamic standard-class can be. Also, if we want to get pedantic, method-dispatch does not dispatch on types in Common Lisp, but rather via EQL or the class of the argument. Since sub-classes can be made (and methods added or even removed) after a method invocation is compiled, there is no feasible way in a typical lisp implementation[1] to do compile-time dispatch of any type that is a subtype of standard-object. Now none of this prevents you from extending lisp in such a way that lets you freeze the method dispatch (see e.g. https://github.com/alex-gutev/static-dispatch https://github.com/alex-gutev/static-dispatch), but "a modern compiler will jmp past the type checks" is false for all of the CLOS implementations I'm familiar with. 1: SICL is a research implementation that has first-class global environments. If you save the global-environment of a method invocation, you can re-compile the invocation whenever a method is defined (or removed) and get static-dispatch. There's a paper somewhere (probably on metamodular?) that discusses this possibility.
- User23 1y agoVery interesting comment! To clarify, as you know CLOS isn’t the CL type system. I was particularly thinking about things like fixnum arithmetic. The CMUCL and SBCL manual sections on code generation discuss this and it can be verified with DISASSEMBLE.
- aidenn0 1y agoMissed your reply when it happened. Note that you cannot specialize a method on "fixnum" since it's not a class (though you can on "number" or "integer" since they are classes).
- wild_egg 1y ago> but without static types So add static types. https://github.com/coalton-lang/coalton https://github.com/coalton-lang/coalton
- Zambyte 1y agoThere isn't really as clear of a distinction between "runtime" and "compile time" in Lisp. The comptime keyword is essentially just the opposite of quote in Lisp. Instead of using comptime to say what should be evaluated early, you use quote to say what should be evaluated later. Adding comptime to Lisp would be weird (though obviously not impossible, because it's Lisp), because that is essentially the default for expressions.
- Conscat 1y agoThe Scopes language might be similar to what you're asking about. Its notion of "spices" which complement the "sugars" feature is a similar kind of constant evaluation. It's not a Common Lisp dialect, though, but it is sexp based.
- pron 1y agoThat wouldn't be very meaningful. The semantics of Zig's comptime is more like that of subroutines in a dynamic language - say, JavaScript functions - than that of macros. The point is that it's executed, and yields errors, at a different phase, i.e. compile time.
- User23 1y agoYou can do that, I think, with EVAL-WHEN.