2 ms·
Perl 6 includes the ability to modify the grammar and parser on the fly in a way which is much more convenient than reader macros in Common Lisp (and different
by dan-robertson 7y ago
Perl 6 includes the ability to modify the grammar and parser on the fly in a way which is much more convenient than reader macros in Common Lisp (and different to macros in CL). Saying “new syntax” is also slightly disingenuous because the only convenient new syntax available is made of parens.
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.