Compile-time computing is precisely about this, e.g. https://medium.com/@MartinCracauer/a-gentle-introduction-to-...
Compile-time computing is precisely about this, e.g. https://medium.com/@MartinCracauer/a-gentle-introduction-to-...
That said, this isn’t really an article about syntax but how several language features fit together.
Making something slightly similar in CL could be something like:
(defmacro with (it &body body)
`(let ((it ,it)) (block nil ,@body)))
(defmacro having (condition &body body)
`(if (smart-match ,condition it)
(return-from nil (progn ,@body))
(values)))
(defgeneric smart-match (matcher thing))
...
But this makes the behaviour of `having` a bit weird.I feel like this article is much more about how certain perl6 features compose nicely together (in particular smart matching, $_, expressions returning values) in a way that the existing features of given and when compose to give a useful switch mechanism for free.
There is a reason Lisp based languages are not more popular: most people don't want to learn a new language every time they work on a new project.
As for learning something new, perl6 is a new language, this construct isn't in perl5, so they are in for a learning. In Lisp no language modification was required to enable this functionality in the first place, and so you do not have to learn any new language or language construct.
Yes, you have to learn the library that you or somebody else writes to enable this "enter the data in the safest way possible". But that is learning a library, not a new language, or language evolution.
It goes back to object-oriented programming. How badly did they hack up C compilers to implement either C++ or Objective-C? In Lisp the OO system used to this day was implemented as a compile-time library. A library still used today, too.
You don't have to wait for anybody to hack up the compiler, and test it, and document it, when compile-time computing is part of the language in the first place.
ETA: Another thing you can do with compile-time computing, without waiting for somebody to hack up the compiler: https://medium.com/@MartinCracauer/static-type-checking-in-t...
Though it has been marked as experimental because the Perl6 design for this didn't fit into Perl5 as well as was hoped for. That is it had edge-cases that need to be worked through before it is recommended for general use.
use v5.10;
no warnings qw(experimental);
given (1) {
when (1) { say 'one' } # only prints this line
when (1) { say 1 }
}Not once in my career have I heard someone either inspect or begin to learn Lisp and said “ya know what, all these new languages, not for me.” People usually don’t learn (Common) Lisp because it’s an old language, people don’t recognize benefits it has vis a vis other langs like Python/Go/Rust, it doesn’t look like anything they learned before, it more-or-less bolts you down to Emacs, it has no major corporate backer promoting the language, etc.
Rakudo has a macro feature, but the current design was deemed not good enough to be part of the Perl6 specification testsuite yet.
There has been design work in this area in the 007 project. https://github.com/masak/007
Thanks, but I'd rather not.
New syntax doesn’t have to mean new lexemes or characters. New syntax can be making something that wasn’t semantically meaningful before now meaningful.
In Lisp notation, if I just have a bare (F 5), I’ll get an error: F is undefined. If I define F, in some sense, I’m adding new syntax. I can now write something down that is meaningful.
Now, it’s not strictly true that it’s new syntax. But if you agree to that, then maybe you’ll agree that
(match X (P1 R1) (P2 R2) ...)
isn’t new syntax either. (Lisp programmers, however, call it “new syntax”.) That chunk of code could represent pattern matching X against the patterns Pi, and a successful match will return Ri.Visually, lexically, and structurally, this isn’t actually “new” in a lot of ways. Still has parentheses. Looks like CASE. Doesn’t introduce any foreign evaluation semantics.
So why wouldn’t you want to be able to write things like this? What makes functions/classes/methods/variables—which we define day in and day out—more privileged than syntax like this?