Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Has anyone grafted Zig style macros into Common Lisp?


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


You can do that, I think, with EVAL-WHEN.


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


Isn’t this kind of thing sort of the default thing in Lisp? Code is data so you can transform it.


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


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


> Lisp is so powerful, but <tired old shit from someone who's never used Lisp>.

You use defmethod for overloading. Types check themselves.


And a modern compiler will jmp past the type checks if the inferencer OKs it!


Which 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), 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.


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


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


> but without static types

So add static types.

https://github.com/coalton-lang/coalton


No need for overloading when you have CLOS and multi-method dispatch.


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


Since we are specifically speaking about Common Lisp, there certainly is; see e.g. https://www.lispworks.com/documentation/HyperSpec/Body/s_eva...


The truth of this varies between Lisp based languages.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: