Professional Documents
Culture Documents
Example:
f1 = func { see "hello" + nl }
f3 = f1
call f1()
call f2()
call f3()
Output:
hello
how are you?
hello
0
0
1
FORTYONE
Since the Ring programming language is a dynamic language, we can get answers about the program code and we can
modify our code during the runtime.
In this chapter we will learn about this and the available functions to use.
We can get a list of variables names in the current scope using the locals() function.
Syntax:
locals() --> a list contains the variables names in the current scope
Example:
test("hello")
see cMsg + nl
x = 10
y = 20
z = 30
see locals()
Output:
hello
cmsg
x
y
z
We can get a list of variables names in the global scope using the globals() function.
Syntax:
286
Ring Documentation, Release 1.5.3
Example:
x=10 y=20 z=30
test()
func test
see "message from test()" + nl +
"Global Variables:" + nl
see globals()
Output:
message from test()
Global Variables:
x
y
z
We can get a list of functions names written in the Ring language using the functions() function.
Syntax:
functions() --> a list contains functions names
Example:
see functions()
func f1
see "f1" + nl
func f2
see "f2" + nl
func f3
see "f3" + nl
Output:
f1
f2
f3
We can get a list of functions names written in the C language using the cfunctions() function.
Syntax:
cfunctions() --> a list contains functions names
Example:
aList = cfunctions()
See "Count : " + len(aList) + nl
for x in aList
see x + "()" + nl
next
Output:
Count : 197
len()
add()
del()
get()
clock()
...
We can check if a variable is defined in the local scope or not using the islocal() function.
Syntax:
islocal(cVariableName) --> returns 1 if the variable is defined in the local scope
returns 0 if the variable is not defined in the local scope
Example:
test()
func test
x=10 y=20
see islocal("x") + nl +
islocal("y") + nl +
islocal("z") + nl
Output:
1
1
0
We can check if a variable is defined in the global scope or not using the isglobal() function.
Syntax:
isglobal(cVariableName) --> returns 1 if the variable is defined in the global scope
returns 0 if the variable is not defined in the global scope
Example:
x=10 y=20
test()
func test
see isglobal("x") + nl +
isglobal("y") + nl +
isglobal("z") + nl
Output:
1
1
0
We can check if a Ring function is defined or not using the isfunction() function.
Syntax:
isfunction(cFunctionName) --> returns 1 if the Ring function is defined
returns 0 if the Ring function is not defined
Example:
see isfunction("f1") + nl +
isfunction("f2") + nl +
isfunction("f3") + nl
func f1
see "message from f1()" + nl
func f2
see "message from f2()" + nl
Output:
1
1
0
Example:
see iscfunction("len") + nl +
iscfunction("add") + nl +
iscfunction("test") + nl
Output:
1
1
0
Example:
See packages()
Package Package1
Class class1
Func f1
Package Package2
Class class1
Func f1
Package Package3
Class class1
Func f1
Package Package4
Class class1
Func f1
Output:
package1
package2
package3
package4
Example:
See ispackage("package1") + nl +
ispackage("package4") + nl +
ispackage("package5") + nl +
ispackage("package3") + nl
Package Package1
Class class1
Func f1
Package Package2
Class class1
Func f1
Package Package3
Class class1
Func f1
Package Package4
Class class1
Func f1
Output:
1
1
0
1
Example:
See classes()
Class class1
Func f1
Class class2
Func f1
Class class3
Func f1
Output:
class1
class2
class3
Example:
see isclass("class4") + nl +
isclass("class3") + nl +
isclass("class2") + nl
Class class1
func f1
class class2
func f1
class class3
func f1
Output:
0
1
1
We can get a list of classes names inside a package using the packageclasses() function.
Syntax:
packageclasses(cPackageName) --> a list contains classes names inside the package
Example:
see "classes in Package1" + nl
see packageclasses("Package1")
see "classes in Package2" + nl
see packageclasses("Package2")
Package Package1
Class class1
Func f1
Package Package2
Class class1
Func f1
Class class2
Func f1
Class class3
func f1
Output:
classes in Package1
class1
classes in Package2
class1
class2
class3
We can check if a class is defined inside package or not using the ispackageclass() function.
Syntax:
ispackageclass(cPackageName,cClassName) --> returns 1 if the Class is defined
returns 0 if the Class is not defined
Example:
see ispackageclass("package1","class1") + nl +
ispackageclass("package1","class2") + nl +
ispackageclass("package2","class1") + nl +
ispackageclass("package2","class2") + nl
Package Package1
Class class1
Func f1
Package Package2
Class class1
Func f1
Class class2
Func f1
Class class3
func f1
Output:
1
0
1
1
We can know the class name of an object using the classname() function
Syntax:
classname(object) --> Returns the object class name
Example:
o1 = new point
o2 = new rect
class point
class rect
Example:
o1 = new point
see objectid(o1) + nl
test(o1)
func test v
see objectid(v) + nl
Class point x y z
Output:
021B5808
021B5808
We can check the variable to know if it’s an object or not using the isobject() function
Syntax:
isobject(variable) --> Returns True if it's an object, False if it's not
Example:
o1 = new point
aList = attributes(o1) # we can use see attributes(o1)
for t in aList see t next # print xyz
Class Point x y z