Is it possible to implement lisp "language" in Perl 6?

Perl 6's grammar is just a grammar written in Perl 6, and very malleable (though current implementations don't quite provide all of the specced flexibility).

So what you ask is possible in principle, but might need more care. In particular are round parenthesis perfectly valid Perl 6 syntax, and even (defun a b) parses as valid Perl 6. So you'd need to be /really/ careful with disambiguation rules, and it would be a huge can of worms.

It probably makes more sense to restrict Lisp syntax to some specially delimited syntactic construct (like lisp(...) or q:lisp{...}), though some amount of mixing would probably be implementable.

I'm sure that once such features are available in a compiler, we'll see a whole lot of interesting experiments, and only those experiments will show what kind of language mixing is both feasible and useful.


[I seem to have missed the question is about Perl6, not Perl5. Leaving my answer up anyway since it might be of interest to some.]

It's my understanding that Scheme and Lisp are related. If you're ok with Scheme instead, Inline::MzScheme allows one to have blocks of Scheme code in Perl.

Even if you're not ok with Scheme, you could surely fork the module to edit it to use your favorite Lisp engine without too much trouble.

It's not quite what you described, but as moritz explained, what you described is impossible because there's no way to know what parts of the code should be treated as Perl code and which parts should be treated as Lisp code.

On the other handle, through the use of 5.14's pluggable token handler (used by feature::qw_comments to override qw, for example), it should be relatively easy to do the following:

my $emacs_func = lisp(defun perl-backward-to-start-of-continued-exp (lim)
   (if (= (preceding-char) ?\))
      (forward-sexp -1))
   (beginning-of-line)
   (if (<= (point) lim)
      (goto-char (1+ lim)))
   (skip-chars-forward " \t\f"));

(Note the addition of lisp to your code.)


Carl Masak recently (late 2014) created ipso, "A metacircular Lisp in Perl 6" that works on current Rakudo.

There will be ways it can be combined with P6 inline; please explore "slangs" for more about that, eg a recent blog post about macros/slangs enabling recursive inlining of arbitrary langs.

See also Damian Conway's Quicksort in (P6ish) Lisp