mzperl - Embed Perl in MzScheme
#!/usr/local/bin/mzperl (perl-use 'Config) (printf "<MzScheme> I'm running under Perl, version ~A.\n" (perl-eval "$Config{version}")) ;__PERL__; printf "<Perl> I'm running under MzScheme, version %s.\n", mz_eval('(version)');
Is it Scheme? Is it Perl? It's neither, it's both. It's MzPerl!
MzPerl is a "new language" that looks like MzScheme. As an added bonus, you'll get access to the full Perl runtime via the MzPerl API.
The mzperl script will normally be installed in the same directory as the perl binary on your system, for example as /usr/local/bin/mzperl.
perl
The MzPerl API is just a set of MzScheme primitives that you can use to access the Perl runtime. They are the same set of primitives defined in all Language::MzScheme->new instances:
Language::MzScheme->new
Eval a string or symbol in Perl and return the result. There are 11 variants of this call, just like any other functions exported from Perl:
; list context calls (perl-eval "string") ; if there is one return value, return it ; as a scalar, otherwise returns a list (perl-eval@ "string") ; returns a list (perl-eval^ "string") ; returns a vector (perl-eval% "string") ; returns a hash-table (perl-eval& "string") ; returns an association-list ; scalar context calls (perl-eval$ "string") ; returns a scalar of an appropriate type (perl-eval~ "string") ; returns a string (perl-eval+ "string") ; returns a number (perl-eval. "string") ; returns the first character (perl-eval? "string") ; returns a boolean (#t or #f) ; void context calls (perl-eval! "string") ; always returns #<void>
Loads a perl module, and optionally imports symbols from it, just like Perl's use keyword. Imported symbols are available in subsequent perl-eval calls, as well as in scheme code as primitives.
use
perl-eval
Fully-qualified names (Module::symbol) are always available.
Module::symbol
Loads a perl module or file, without importing any symbols.
Evaluates a perl file. Also available in all 11 context forms like the perl-eval above.
The ;__PERL__; token begins a perl code region. It ends on the next ;__END__; token, or until the end of file.
;__PERL__;
;__END__;
Scheme has no CPAN. Perl5 has no macros and no continuations. So... :-)
Yes. To wit:
#!/usr/local/bin/mzperl (let* ((yin ((perl-eval "sub { print $/; @_ }") (call/cc (perl-eval "sub { @_ }")))) (yang ((perl-eval "sub { print '*'; @_ }") (call/cc (perl-eval "sub { @_ }"))))) (yin yang))
Autrijus Tang <autrijus@autrijus.org>
Copyright 2004 by Autrijus Tang <autrijus@autrijus.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Language::MzScheme, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Language::MzScheme
CPAN shell
perl -MCPAN -e shell install Language::MzScheme
For more information on module installation, please visit the detailed CPAN module installation guide.