[% setvar title with takes a context %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/

TITLE

with takes a context

VERSION

  Maintainer: David Nicol <perl6rfc@davidnicol.com>
  Date: 28 Sep 2000
  Mailing List: perl6-language@perl.org
  Number: 340
  Version: 1
  Status: Developing

ABSTRACT

"call frames" become useful as objects. The current one is always with with no argument and you can get into an arbitrary one by using with $whatever BLOCK in either forward or backward form, like if.

DESCRIPTION =item description by commented example

	sub A{
		my $A = shift;
		return with;
	};

	$context1 = A(3);
	print "$context1";		# something like CONTEXT(0XF0GD0G)
        print "$A" with $context1;	# prints 3
        with $context1{print "$A"};	# same thing
  • coexistence w/ pascal-like with
  • The context-access with takes a scalar argument, the pascal-like with takes a hash. If the pascal-like with is considered as describing aliases to defined variables, the two have deep similarities.

  • CONTEXT objects in other contexts
  • In an array context, one of these CONTEXT things will expand into key-value pairs if it can.

  • warning about memory leaks
  • using with to store contexts may adversely affect memory recycling.

    IMPLEMENTATION

    Perl5 has the hooks required to do this: the closure stuff. This proposed with keyword makes access into such things more explicit.

    REFERENCES

    None.