☺唐鳳☻ > Language-MzScheme-0.09 > mzperl

Download:
Language-MzScheme-0.09.tar.gz

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Source  

NAME ^

mzperl - Embed Perl in MzScheme

SYNOPSIS ^

    #!/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)');

DESCRIPTION ^

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.

FUNCTIONS ^

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:

perl-eval code

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>

perl-use module [ import-list ]

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.

Fully-qualified names (Module::symbol) are always available.

perl-require module-or-filename

Loads a perl module or file, without importing any symbols.

perl-do filename

Evaluates a perl file. Also available in all 11 context forms like the perl-eval above.

;__PERL__; ... ;__END__;

The ;__PERL__; token begins a perl code region. It ends on the next ;__END__; token, or until the end of file.

WHY? ^

Scheme has no CPAN. Perl5 has no macros and no continuations. So... :-)

Continuations? In Perl?

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

AUTHORS ^

Autrijus Tang <autrijus@autrijus.org>

COPYRIGHT ^

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

syntax highlighting: