fn: scope
[contents]

Contents

Syntax

The syntax for scope calls is:

f++:  
scope()
scope{option}(var) 

n++:  
@scope()
@scope{option}(var) 

Description

The scope function either:

  • takes zero parameters and returns the current scope; or
  • takes a single variable parameter and either returns the scope the variable is defined at or with the in option returns the set of scopes at which the variable can be accessed from

Options

The following options are available for content calls:

option description
in return set of scopes at which variable can be accessed from
option description

f++ example

Example of scope being used with f++:

function(example.fn)
{
	:={scope+="teji."}(int, x=0)
	console(scope(x))
	console(scope{in}(x))
}

example.fn()

n++ example

Examples of scope being used with n++:

@function(example.fn)
{
	@:={scope+="teji."}(int, x=0)
	@console(@scope(x))
	@console(@scope{in}(x))
}

@example.fn()

@:={private}(int, obj.pair.first, obj.pair.second)
@funcdef{private}(obj.pair.set){}
@funcdef(another.example.func)
{
	@console("current scope: '@scope()'")
}

@console("root scope: '@scope()'")
@console("scope of obj.pair.first: '@scope(obj.pair.first)'")
@console("scope of obj.pair.set: '@scope(obj.pair.set)'")
@another.example.func()

@/*
	expected output:
		root scope: ''
		scope of obj.pair.first: 'obj.pair.'
		scope of obj.pair.set: 'obj.pair.'
		current scope: 'another.example.'
*/