NAME

Language::MzScheme::Env - MzScheme runtime environment

SYNOPSIS

use Language::MzScheme;
my $env = Language::MzScheme->new;
# ...

DESCRIPTION

None at this moment.

METHODS

All methods below, except new, returns an Language::MzScheme::Object instance.

new

Constructs and returns a new environment object. Calling this method is identical to Language::MzScheme->new.

lookup($name)

Given a global MzScheme variable name $name, returns the current value.

define($name, $code, $sigil)

Defines a new MzScheme primitive $name from $code, with the calling context $sigil, and returns it.

If $sigil is omitted, look at the end of $name for a sigil character; if not found, uses the auto context. See "CONTEXTS" for a list of sigils and their meanings.

If $code is omitted, defines a package with the name $name and import all its symbols. Otherwise, pass it and the sigil to the lambda method, and bind the returned lambda to $name.

lambda($code, $sigil)

Builds and returns a MzScheme procedure, as a wrapper for $code.

If $code is a Perl code reference, returns a lambda that takes any number of parameters, under the context specified by $sigil:

(func ...)          ; ==> $code->(...)

Otherwise, treat $code as a class name or an object, and returns a lambda that takes a mandatory method argument, followed by any number of parameters.

(obj 'method ...)   ; ==> $obj->$method(...)

Generally, you should only set $sigil for code references, and let the user specity the context with the method name:

(obj 'set! ...)     ; void context
(obj 'isa? ...)     ; boolean context

eval($expr)

Evaluates a MzScheme expression, passed as an object or a string, and returns the result.

apply($name, @args)

Applies a MzScheme procedure, passed as an object or a global name, to @args, and returns the result.

val($scalar)

Return a MzScheme object that represents the content of $scalar, which may be a simple scalar or a reference.

sym($string)

Returns a MzScheme symbol object named $string.

CONTEXTS

There are 10 different sigils, each representing a way to interpret values returned by a Perl function or method.

If no sigils are specified, then auto-context is assumed: it will call the perl code with Perl's list context, and look at the number of values returned. If there is exactly one return value, receive it as a scalar; otherwise, returns a MzScheme list that contains all return values.

; list context calls
(perl-func "string")    ; auto-context
(perl-func@ "string")   ; a list
(perl-func^ "string")   ; a vector
(perl-func% "string")   ; a hash-table
(perl-func& "string")   ; an association-list

; scalar context calls
(perl-func$ "string")   ; a scalar of an appropriate type
(perl-func~ "string")   ; a string
(perl-func+ "string")   ; a number
(perl-func. "string")   ; a character
(perl-func? "string")   ; a boolean (#t or #f)

; void context calls
(perl-func! "string")   ; always #<void>

SEE ALSO

Language::MzScheme, Language::MzScheme::Object

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