SlideShare a Scribd company logo
Ring Documentation, Release 1.6
wow!
Message from f1
hello world
hello world
hello world
Example:
Func Main
aList = [1,2,3,4]
Map (aList , func x {
return x*x
} )
see aList
aList = [4,9,14,25]
Map(aList, :myfilter )
see aList
aList = [11,12,13,14]
Map (aList , func x {
if x%2=0
return "even"
else
return "odd"
ok
})
see aList
Func myfilter x
if x = 9
return "True"
else
return "False"
ok
Func Map aList,cFunc
for x in aList
x = call cFunc(x)
next
Output:
1
4
9
16
False
True
False
False
odd
even
odd
even
41.5 Equality of functions
We can test if function = function or not using the ‘=’ or ‘!=’ operators
41.5. Equality of functions 303
Ring Documentation, Release 1.6
Example:
f1 = func { see "hello" + nl }
f2 = func { see "how are you?" + nl }
f3 = f1
call f1()
call f2()
call f3()
see (f1 = f2) + nl
see (f2 = f3) + nl
see (f1 = f3) + nl
Output:
hello
how are you?
hello
0
0
1
41.5. Equality of functions 304
CHAPTER
FORTYTWO
REFLECTION AND META-PROGRAMMING
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.
‱ locals()
‱ globals()
‱ functions()
‱ cfunctions()
‱ islocal()
‱ isglobal()
‱ isfunction()
‱ iscfunction()
‱ packages()
‱ ispackage()
‱ classes()
‱ isclass()
‱ packageclasses()
‱ ispackageclass()
‱ classname()
‱ objectid()
‱ isobject()
‱ attributes()
‱ methods()
‱ isattribute()
‱ isprivateattribute()
‱ ismethod()
‱ isprivatemethod()
‱ addattribute()
‱ addmethod()
305
Ring Documentation, Release 1.6
‱ getattribute()
‱ setattribute()
‱ mergemethods()
‱ packagename()
42.1 locals() Function
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")
func test cMsg
see cMsg + nl
x = 10
y = 20
z = 30
see locals()
Output:
hello
cmsg
x
y
z
42.2 globals() Function
We can get a list of variables names in the global scope using the globals() function.
Syntax:
globals() --> a list contains variables names in the global scope
Example:
x=10 y=20 z=30
test()
func test
see "message from test()" + nl +
"Global Variables:" + nl
see globals()
Output:
42.1. locals() Function 306
Ring Documentation, Release 1.6
message from test()
Global Variables:
x
y
z
42.3 functions() Function
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
42.4 cfunctions() Function
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()
42.3. functions() Function 307
Ring Documentation, Release 1.6
clock()
...
Note: The complete list is removed from the previous output.
42.5 islocal() Function
We can check if a variable is deïŹned 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
42.6 isglobal() Function
We can check if a variable is deïŹned 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
42.5. islocal() Function 308
Ring Documentation, Release 1.6
42.7 isfunction() Function
We can check if a Ring function is deïŹned 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
42.8 iscfunction() Function
We can check if a C function is deïŹned or not using the iscfunction() function.
Syntax:
iscfunction(cFunctionName) --> returns 1 if the C function is defined
returns 0 if the C function is not defined
Example:
see iscfunction("len") + nl +
iscfunction("add") + nl +
iscfunction("test") + nl
Output:
1
1
0
42.9 packages() Function
We can get a list of packages names using the packages() function.
Syntax:
packages() --> a list contains packages names
42.7. isfunction() Function 309
Ring Documentation, Release 1.6
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
42.10 ispackage() Function
We can check if a package is deïŹned or not using the ispackage() function.
Syntax:
ispackage(cPackageName) --> returns 1 if the Package is defined
returns 0 if the Package is not defined
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
42.10. ispackage() Function 310
Ring Documentation, Release 1.6
Output:
1
1
0
1
42.11 classes() Function
We can get a list of classes names using the classes() function.
Syntax:
classes() --> a list contains classes names
Example:
See classes()
Class class1
Func f1
Class class2
Func f1
Class class3
Func f1
Output:
class1
class2
class3
42.12 isclass() Function
We can check if a class is deïŹned or not using the isclass() function.
Syntax:
isclass(cClassName) --> returns 1 if the Class is defined
returns 0 if the Class is not defined
Example:
see isclass("class4") + nl +
isclass("class3") + nl +
isclass("class2") + nl
Class class1
func f1
class class2
func f1
class class3
func f1
42.11. classes() Function 311
Ring Documentation, Release 1.6
Output:
0
1
1
42.13 packageclasses() Function
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
42.14 ispackageclass() Function
We can check if a class is deïŹned 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 +
42.13. packageclasses() Function 312

More Related Content

What's hot (20)

PDF
The Ring programming language version 1.2 book - Part 21 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 74 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 38 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 24 of 88
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 33 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 31 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5 book - Part 6 of 31
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 81 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 91 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 26 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 78 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 88 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 34 of 210
Mahmoud Samir Fayed
 
PPTX
Programming Java - Lection 07 - Puzzlers - Lavrentyev Fedor
Fedor Lavrentyev
 
PDF
The Ring programming language version 1.5.1 book - Part 75 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 16 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 32 of 180
Mahmoud Samir Fayed
 
PDF
Pooya Khaloo Presentation on IWMC 2015
Iran Entrepreneurship Association
 
PDF
The Ring programming language version 1.4 book - Part 9 of 30
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 87 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 21 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 74 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 38 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 24 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 33 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 31 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 6 of 31
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 81 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 91 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 26 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 78 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 88 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 34 of 210
Mahmoud Samir Fayed
 
Programming Java - Lection 07 - Puzzlers - Lavrentyev Fedor
Fedor Lavrentyev
 
The Ring programming language version 1.5.1 book - Part 75 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 16 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 32 of 180
Mahmoud Samir Fayed
 
Pooya Khaloo Presentation on IWMC 2015
Iran Entrepreneurship Association
 
The Ring programming language version 1.4 book - Part 9 of 30
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 87 of 202
Mahmoud Samir Fayed
 

Similar to The Ring programming language version 1.6 book - Part 34 of 189 (20)

PDF
The Ring programming language version 1.5.1 book - Part 30 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 37 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 35 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 30 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 32 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 35 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 18 of 88
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 35 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 33 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 92 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 27 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5 book - Part 5 of 31
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 37 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 41 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 33 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 22 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 41 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 43 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 31 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 31 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 30 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 37 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 35 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 30 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 32 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 35 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 18 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 35 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 33 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 92 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 27 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 5 of 31
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 37 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 41 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 33 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 22 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 41 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 43 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 31 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 31 of 184
Mahmoud Samir Fayed
 
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 211 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 210 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 208 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 207 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 205 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 206 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 204 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 203 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 202 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 201 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 200 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 199 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 198 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 197 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 196 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 195 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 194 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 193 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 192 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 212 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 211 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 210 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 208 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 207 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 205 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 206 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 204 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 203 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 202 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 201 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 200 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 199 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 198 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 197 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 196 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 195 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 194 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 193 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 192 of 212
Mahmoud Samir Fayed
 
Ad

Recently uploaded (20)

PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Import Data Form Excel to Tally Services
Tally xperts
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 

The Ring programming language version 1.6 book - Part 34 of 189

  • 1. Ring Documentation, Release 1.6 wow! Message from f1 hello world hello world hello world Example: Func Main aList = [1,2,3,4] Map (aList , func x { return x*x } ) see aList aList = [4,9,14,25] Map(aList, :myfilter ) see aList aList = [11,12,13,14] Map (aList , func x { if x%2=0 return "even" else return "odd" ok }) see aList Func myfilter x if x = 9 return "True" else return "False" ok Func Map aList,cFunc for x in aList x = call cFunc(x) next Output: 1 4 9 16 False True False False odd even odd even 41.5 Equality of functions We can test if function = function or not using the ‘=’ or ‘!=’ operators 41.5. Equality of functions 303
  • 2. Ring Documentation, Release 1.6 Example: f1 = func { see "hello" + nl } f2 = func { see "how are you?" + nl } f3 = f1 call f1() call f2() call f3() see (f1 = f2) + nl see (f2 = f3) + nl see (f1 = f3) + nl Output: hello how are you? hello 0 0 1 41.5. Equality of functions 304
  • 3. CHAPTER FORTYTWO REFLECTION AND META-PROGRAMMING 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. ‱ locals() ‱ globals() ‱ functions() ‱ cfunctions() ‱ islocal() ‱ isglobal() ‱ isfunction() ‱ iscfunction() ‱ packages() ‱ ispackage() ‱ classes() ‱ isclass() ‱ packageclasses() ‱ ispackageclass() ‱ classname() ‱ objectid() ‱ isobject() ‱ attributes() ‱ methods() ‱ isattribute() ‱ isprivateattribute() ‱ ismethod() ‱ isprivatemethod() ‱ addattribute() ‱ addmethod() 305
  • 4. Ring Documentation, Release 1.6 ‱ getattribute() ‱ setattribute() ‱ mergemethods() ‱ packagename() 42.1 locals() Function 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") func test cMsg see cMsg + nl x = 10 y = 20 z = 30 see locals() Output: hello cmsg x y z 42.2 globals() Function We can get a list of variables names in the global scope using the globals() function. Syntax: globals() --> a list contains variables names in the global scope Example: x=10 y=20 z=30 test() func test see "message from test()" + nl + "Global Variables:" + nl see globals() Output: 42.1. locals() Function 306
  • 5. Ring Documentation, Release 1.6 message from test() Global Variables: x y z 42.3 functions() Function 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 42.4 cfunctions() Function 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() 42.3. functions() Function 307
  • 6. Ring Documentation, Release 1.6 clock() ... Note: The complete list is removed from the previous output. 42.5 islocal() Function We can check if a variable is deïŹned 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 42.6 isglobal() Function We can check if a variable is deïŹned 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 42.5. islocal() Function 308
  • 7. Ring Documentation, Release 1.6 42.7 isfunction() Function We can check if a Ring function is deïŹned 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 42.8 iscfunction() Function We can check if a C function is deïŹned or not using the iscfunction() function. Syntax: iscfunction(cFunctionName) --> returns 1 if the C function is defined returns 0 if the C function is not defined Example: see iscfunction("len") + nl + iscfunction("add") + nl + iscfunction("test") + nl Output: 1 1 0 42.9 packages() Function We can get a list of packages names using the packages() function. Syntax: packages() --> a list contains packages names 42.7. isfunction() Function 309
  • 8. Ring Documentation, Release 1.6 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 42.10 ispackage() Function We can check if a package is deïŹned or not using the ispackage() function. Syntax: ispackage(cPackageName) --> returns 1 if the Package is defined returns 0 if the Package is not defined 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 42.10. ispackage() Function 310
  • 9. Ring Documentation, Release 1.6 Output: 1 1 0 1 42.11 classes() Function We can get a list of classes names using the classes() function. Syntax: classes() --> a list contains classes names Example: See classes() Class class1 Func f1 Class class2 Func f1 Class class3 Func f1 Output: class1 class2 class3 42.12 isclass() Function We can check if a class is deïŹned or not using the isclass() function. Syntax: isclass(cClassName) --> returns 1 if the Class is defined returns 0 if the Class is not defined Example: see isclass("class4") + nl + isclass("class3") + nl + isclass("class2") + nl Class class1 func f1 class class2 func f1 class class3 func f1 42.11. classes() Function 311
  • 10. Ring Documentation, Release 1.6 Output: 0 1 1 42.13 packageclasses() Function 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 42.14 ispackageclass() Function We can check if a class is deïŹned 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 + 42.13. packageclasses() Function 312