Angel \”Java\” Lopez on Blog

July 12, 2014

Mass Programming Language (5) Variables Scope

Filed under: .NET, C Sharp, Mass, Open Source Projects, Programming Languages — ajlopez @ 6:18 pm

Previos Post

I finally started a new implementation of variables and their scope in programming language Mass. My idea is:

– Have local variables

– No need to explicitly declare

– Access available "outside" if necessary

The basic idea is:

– Any variable assignment involves the local level

That is, if I assign

a = 3

in a function, this refers to a local variable in the function. No matter if there is a variable external to the function

See for example

https://github.com/ajlopez/Mass/blob/master/Src/Mass.Core.Tests/MachineFiles/Local.ms

# file variable
a = 1

define foo()
    a = 2 # local variable
end

foo()

The first variable a is a variable of the file in process (the module). The variable assigned in the foo function is local to that function, and it is different from the outside variable.

But if we do not assign the variable, and only consulted it, its value is returned. example:

https://github.com/ajlopez/Mass/blob/master/Src/Mass.Core.Tests/MachineFiles/Scope.ms

# file variable
a = 1

define foo()
   a # access file variable
end

foo()

In this case, the function foo returns the value to "outside", since this variable has not been assigned in the function when evaluating the return value.

How to edit an "external” variable, that is, a non-local variablel? Well, this is a topic for an upcoming post. The idea: to access the value of a non-local variable, it must be implied, without declaring anything extra. BUT modifying its value must should be explicit: we put something to explicitly declare "we are changing the value of a non-local variable".

Stay tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

1 Comment »

  1. […] Previous Post Next Post […]

    Pingback by Mass Programming Language (4) Lexer and Parser | Angel "Java" Lopez on Blog — July 12, 2014 @ 6:20 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: