SlideShare a Scribd company logo
1 of 10
Download to read offline
Ring Documentation, Release 1.5.1
• Before defining any variable, Ring try to find the variable and use it if it’s found.
Note: Try to avoid the global variables, use the main function and start their names with $
Tip: In large programs protect your classes and define their members using self.attribute
39.14 Using This.Attribute and This.Method()
Inside class methods we have access to the object scope directly. we don’t need to use Self.attribute or Self.method to
read/write attribute and call methods.
But we can use braces {} while we are inside methods to access another object, In this case the current object scope
will be changed while we are inside the brace.
How we can get access to our class attributes and methods while we are inside braces?
This can be done using This.Attribute and This.Method()
Example:
new point
class point
x=10 y=20 z=30
print()
func print
new UI {
display(this.x,this.y,this.z)
}
Class UI
func display x,y,z
see x + nl + y + nl + z + nl
39.14. Using This.Attribute and This.Method() 265
CHAPTER
FORTY
FUNCTIONAL PROGRAMMING
In previous chapters we learned about Functions and Recursion.
In this chapter we are going to learn about more Functional Programming (FP) concepts like
• Pure Functions
• First-class functions
• Higher-order functions
• Anonymous and nested functions.
• Equality of functions
40.1 Pure Functions
We can create pure functions (functions that doesn’t change the state) by the help of the assignment operator to copy
variables (Lists & Objects) by value to create new variables instead of working on the original data that are passed to
the function by reference.
Example:
Func Main
aList = [1,2,3,4,5]
aList2 = square(aList)
see "aList" + nl
see aList
see "aList2" + nl
see aList2
Func Square aPara
a1 = aPara # copy the list
for x in a1
x *= x
next
return a1 # return new list
Output:
aList
1
2
3
4
5
266
Ring Documentation, Release 1.5.1
aList2
1
4
9
16
25
40.2 First-class Functions
Functions inside the Ring programming language are first-class citizens, you can pass functions as parameters, return
them as value or store them in variables.
We can pass/return the function by typing the function name as literal like “FunctionName” or :FunctionName for
example.
We can pass/return functions using the variable that contains the function name.
We can call function from variables contains the function name using the Call command
Syntax:
Call Variable([Parameters])
Example:
Func Main
see "before test2()" + nl
f = Test2(:Test)
see "after test2()" + nl
call f()
Func Test
see "Message from test!" + nl
Func Test2 f1
call f1()
See "Message from test2!" + nl
return f1
Output:
before test2()
Message from test!
Message from test2!
after test2()
Message from test!
40.3 Higher-order Functions
Higher-order functions are the functions that takes other functions as parameters.
Example:
Func Main
times(5,:test)
40.2. First-class Functions 267
Ring Documentation, Release 1.5.1
Func Test
see "Message from the test function!" + nl
Func Times nCount,F
for x = 1 to nCount
Call F()
next
Output:
Message from the test function!
Message from the test function!
Message from the test function!
Message from the test function!
Message from the test function!
40.4 Anonymous and Nested Functions
Anonymous Functions are functions without names that can be passed as parameters to other functions or stored in
variables.
Syntax:
Func [Parameters] { [statements] }
Example:
test( func x,y {
see "hello" + nl
see "Sum : " + (x+y) + nl
} )
new great { f1() }
times(3, func { see "hello world" + nl } )
func test x
call x(3,3)
see "wow!" + nl
func times n,x
for t=1 to n
call x()
next
Class great
func f1
f2( func { see "Message from f1" + nl } )
func f2 x
call x()
Output:
hello
Sum : 6
40.4. Anonymous and Nested Functions 268
Ring Documentation, Release 1.5.1
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
40.5 Equality of functions
We can test if function = function or not using the ‘=’ or ‘!=’ operators
40.5. Equality of functions 269
Ring Documentation, Release 1.5.1
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
40.5. Equality of functions 270
CHAPTER
FORTYONE
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.
41.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
41.2 globals() Function
We can get a list of variables names in the global scope using the globals() function.
Syntax:
271
Ring Documentation, Release 1.5.1
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:
message from test()
Global Variables:
x
y
z
41.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
41.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:
41.3. functions() Function 272
Ring Documentation, Release 1.5.1
aList = cfunctions()
See "Count : " + len(aList) + nl
for x in aList
see x + "()" + nl
next
Output:
Count : 197
len()
add()
del()
get()
clock()
...
Note: The complete list is removed from the previous output.
41.5 islocal() Function
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
41.6 isglobal() Function
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:
41.5. islocal() Function 273
Ring Documentation, Release 1.5.1
x=10 y=20
test()
func test
see isglobal("x") + nl +
isglobal("y") + nl +
isglobal("z") + nl
Output:
1
1
0
41.7 isfunction() Function
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
41.8 iscfunction() Function
We can check if a C function is defined 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
41.7. isfunction() Function 274

More Related Content

What's hot

Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.4 book - Part 9 of 30
The Ring programming language version 1.4 book - Part 9 of 30The Ring programming language version 1.4 book - Part 9 of 30
The Ring programming language version 1.4 book - Part 9 of 30Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 32 of 181
The Ring programming language version 1.5.2 book - Part 32 of 181The Ring programming language version 1.5.2 book - Part 32 of 181
The Ring programming language version 1.5.2 book - Part 32 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 33 of 189
The Ring programming language version 1.6 book - Part 33 of 189The Ring programming language version 1.6 book - Part 33 of 189
The Ring programming language version 1.6 book - Part 33 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84Mahmoud Samir Fayed
 
Array within a class
Array within a classArray within a class
Array within a classAAKASH KUMAR
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 36 of 196
The Ring programming language version 1.7 book - Part 36 of 196The Ring programming language version 1.7 book - Part 36 of 196
The Ring programming language version 1.7 book - Part 36 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 31 of 184
The Ring programming language version 1.5.3 book - Part 31 of 184The Ring programming language version 1.5.3 book - Part 31 of 184
The Ring programming language version 1.5.3 book - Part 31 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 6 of 31
The Ring programming language version 1.5 book - Part 6 of 31The Ring programming language version 1.5 book - Part 6 of 31
The Ring programming language version 1.5 book - Part 6 of 31Mahmoud Samir Fayed
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondMario Fusco
 
The Ring programming language version 1.10 book - Part 42 of 212
The Ring programming language version 1.10 book - Part 42 of 212The Ring programming language version 1.10 book - Part 42 of 212
The Ring programming language version 1.10 book - Part 42 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 39 of 210
The Ring programming language version 1.9 book - Part 39 of 210The Ring programming language version 1.9 book - Part 39 of 210
The Ring programming language version 1.9 book - Part 39 of 210Mahmoud Samir Fayed
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()daewon jeong
 
Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)Trisha Gee
 
Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)stasimus
 
The Ring programming language version 1.2 book - Part 22 of 84
The Ring programming language version 1.2 book - Part 22 of 84The Ring programming language version 1.2 book - Part 22 of 84
The Ring programming language version 1.2 book - Part 22 of 84Mahmoud Samir Fayed
 

What's hot (20)

Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88The Ring programming language version 1.3 book - Part 24 of 88
The Ring programming language version 1.3 book - Part 24 of 88
 
The Ring programming language version 1.4 book - Part 9 of 30
The Ring programming language version 1.4 book - Part 9 of 30The Ring programming language version 1.4 book - Part 9 of 30
The Ring programming language version 1.4 book - Part 9 of 30
 
The Ring programming language version 1.5.2 book - Part 32 of 181
The Ring programming language version 1.5.2 book - Part 32 of 181The Ring programming language version 1.5.2 book - Part 32 of 181
The Ring programming language version 1.5.2 book - Part 32 of 181
 
The Ring programming language version 1.6 book - Part 33 of 189
The Ring programming language version 1.6 book - Part 33 of 189The Ring programming language version 1.6 book - Part 33 of 189
The Ring programming language version 1.6 book - Part 33 of 189
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84
 
Array within a class
Array within a classArray within a class
Array within a class
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84
 
The Ring programming language version 1.7 book - Part 36 of 196
The Ring programming language version 1.7 book - Part 36 of 196The Ring programming language version 1.7 book - Part 36 of 196
The Ring programming language version 1.7 book - Part 36 of 196
 
The Ring programming language version 1.5.3 book - Part 31 of 184
The Ring programming language version 1.5.3 book - Part 31 of 184The Ring programming language version 1.5.3 book - Part 31 of 184
The Ring programming language version 1.5.3 book - Part 31 of 184
 
The Ring programming language version 1.5 book - Part 6 of 31
The Ring programming language version 1.5 book - Part 6 of 31The Ring programming language version 1.5 book - Part 6 of 31
The Ring programming language version 1.5 book - Part 6 of 31
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
 
The Ring programming language version 1.10 book - Part 42 of 212
The Ring programming language version 1.10 book - Part 42 of 212The Ring programming language version 1.10 book - Part 42 of 212
The Ring programming language version 1.10 book - Part 42 of 212
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
The Ring programming language version 1.9 book - Part 39 of 210
The Ring programming language version 1.9 book - Part 39 of 210The Ring programming language version 1.9 book - Part 39 of 210
The Ring programming language version 1.9 book - Part 39 of 210
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
 
Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)
 
The Ring programming language version 1.2 book - Part 22 of 84
The Ring programming language version 1.2 book - Part 22 of 84The Ring programming language version 1.2 book - Part 22 of 84
The Ring programming language version 1.2 book - Part 22 of 84
 

Similar to Ring Documentation Functions Guide

The Ring programming language version 1.5.2 book - Part 31 of 181
The Ring programming language version 1.5.2 book - Part 31 of 181The Ring programming language version 1.5.2 book - Part 31 of 181
The Ring programming language version 1.5.2 book - Part 31 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 40 of 210
The Ring programming language version 1.9 book - Part 40 of 210The Ring programming language version 1.9 book - Part 40 of 210
The Ring programming language version 1.9 book - Part 40 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 34 of 189
The Ring programming language version 1.6 book - Part 34 of 189The Ring programming language version 1.6 book - Part 34 of 189
The Ring programming language version 1.6 book - Part 34 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 41 of 212
The Ring programming language version 1.10 book - Part 41 of 212The Ring programming language version 1.10 book - Part 41 of 212
The Ring programming language version 1.10 book - Part 41 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 32 of 184
The Ring programming language version 1.5.3 book - Part 32 of 184The Ring programming language version 1.5.3 book - Part 32 of 184
The Ring programming language version 1.5.3 book - Part 32 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 20 of 180
The Ring programming language version 1.5.1 book - Part 20 of 180The Ring programming language version 1.5.1 book - Part 20 of 180
The Ring programming language version 1.5.1 book - Part 20 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 174 of 180
The Ring programming language version 1.5.1 book - Part 174 of 180 The Ring programming language version 1.5.1 book - Part 174 of 180
The Ring programming language version 1.5.1 book - Part 174 of 180 Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 25 of 202
The Ring programming language version 1.8 book - Part 25 of 202The Ring programming language version 1.8 book - Part 25 of 202
The Ring programming language version 1.8 book - Part 25 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 30 of 181
The Ring programming language version 1.5.2 book - Part 30 of 181The Ring programming language version 1.5.2 book - Part 30 of 181
The Ring programming language version 1.5.2 book - Part 30 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 22 of 88
The Ring programming language version 1.3 book - Part 22 of 88The Ring programming language version 1.3 book - Part 22 of 88
The Ring programming language version 1.3 book - Part 22 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.5.1 book - Part 19 of 180The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.5.1 book - Part 19 of 180Mahmoud Samir Fayed
 

Similar to Ring Documentation Functions Guide (20)

The Ring programming language version 1.5.2 book - Part 31 of 181
The Ring programming language version 1.5.2 book - Part 31 of 181The Ring programming language version 1.5.2 book - Part 31 of 181
The Ring programming language version 1.5.2 book - Part 31 of 181
 
The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84
 
The Ring programming language version 1.9 book - Part 40 of 210
The Ring programming language version 1.9 book - Part 40 of 210The Ring programming language version 1.9 book - Part 40 of 210
The Ring programming language version 1.9 book - Part 40 of 210
 
The Ring programming language version 1.6 book - Part 34 of 189
The Ring programming language version 1.6 book - Part 34 of 189The Ring programming language version 1.6 book - Part 34 of 189
The Ring programming language version 1.6 book - Part 34 of 189
 
The Ring programming language version 1.10 book - Part 41 of 212
The Ring programming language version 1.10 book - Part 41 of 212The Ring programming language version 1.10 book - Part 41 of 212
The Ring programming language version 1.10 book - Part 41 of 212
 
The Ring programming language version 1.5.3 book - Part 32 of 184
The Ring programming language version 1.5.3 book - Part 32 of 184The Ring programming language version 1.5.3 book - Part 32 of 184
The Ring programming language version 1.5.3 book - Part 32 of 184
 
The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181
 
The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185
 
The Ring programming language version 1.5.1 book - Part 20 of 180
The Ring programming language version 1.5.1 book - Part 20 of 180The Ring programming language version 1.5.1 book - Part 20 of 180
The Ring programming language version 1.5.1 book - Part 20 of 180
 
The Ring programming language version 1.5.1 book - Part 174 of 180
The Ring programming language version 1.5.1 book - Part 174 of 180 The Ring programming language version 1.5.1 book - Part 174 of 180
The Ring programming language version 1.5.1 book - Part 174 of 180
 
The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210
 
The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202The Ring programming language version 1.8 book - Part 36 of 202
The Ring programming language version 1.8 book - Part 36 of 202
 
The Ring programming language version 1.8 book - Part 25 of 202
The Ring programming language version 1.8 book - Part 25 of 202The Ring programming language version 1.8 book - Part 25 of 202
The Ring programming language version 1.8 book - Part 25 of 202
 
The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88
 
The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196
 
The Ring programming language version 1.5.2 book - Part 30 of 181
The Ring programming language version 1.5.2 book - Part 30 of 181The Ring programming language version 1.5.2 book - Part 30 of 181
The Ring programming language version 1.5.2 book - Part 30 of 181
 
The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196
 
The Ring programming language version 1.3 book - Part 22 of 88
The Ring programming language version 1.3 book - Part 22 of 88The Ring programming language version 1.3 book - Part 22 of 88
The Ring programming language version 1.3 book - Part 22 of 88
 
The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.5.1 book - Part 19 of 180The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.5.1 book - Part 19 of 180
 

More from Mahmoud Samir Fayed

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

More from Mahmoud Samir Fayed (20)

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

Recently uploaded

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Ring Documentation Functions Guide

  • 1. Ring Documentation, Release 1.5.1 • Before defining any variable, Ring try to find the variable and use it if it’s found. Note: Try to avoid the global variables, use the main function and start their names with $ Tip: In large programs protect your classes and define their members using self.attribute 39.14 Using This.Attribute and This.Method() Inside class methods we have access to the object scope directly. we don’t need to use Self.attribute or Self.method to read/write attribute and call methods. But we can use braces {} while we are inside methods to access another object, In this case the current object scope will be changed while we are inside the brace. How we can get access to our class attributes and methods while we are inside braces? This can be done using This.Attribute and This.Method() Example: new point class point x=10 y=20 z=30 print() func print new UI { display(this.x,this.y,this.z) } Class UI func display x,y,z see x + nl + y + nl + z + nl 39.14. Using This.Attribute and This.Method() 265
  • 2. CHAPTER FORTY FUNCTIONAL PROGRAMMING In previous chapters we learned about Functions and Recursion. In this chapter we are going to learn about more Functional Programming (FP) concepts like • Pure Functions • First-class functions • Higher-order functions • Anonymous and nested functions. • Equality of functions 40.1 Pure Functions We can create pure functions (functions that doesn’t change the state) by the help of the assignment operator to copy variables (Lists & Objects) by value to create new variables instead of working on the original data that are passed to the function by reference. Example: Func Main aList = [1,2,3,4,5] aList2 = square(aList) see "aList" + nl see aList see "aList2" + nl see aList2 Func Square aPara a1 = aPara # copy the list for x in a1 x *= x next return a1 # return new list Output: aList 1 2 3 4 5 266
  • 3. Ring Documentation, Release 1.5.1 aList2 1 4 9 16 25 40.2 First-class Functions Functions inside the Ring programming language are first-class citizens, you can pass functions as parameters, return them as value or store them in variables. We can pass/return the function by typing the function name as literal like “FunctionName” or :FunctionName for example. We can pass/return functions using the variable that contains the function name. We can call function from variables contains the function name using the Call command Syntax: Call Variable([Parameters]) Example: Func Main see "before test2()" + nl f = Test2(:Test) see "after test2()" + nl call f() Func Test see "Message from test!" + nl Func Test2 f1 call f1() See "Message from test2!" + nl return f1 Output: before test2() Message from test! Message from test2! after test2() Message from test! 40.3 Higher-order Functions Higher-order functions are the functions that takes other functions as parameters. Example: Func Main times(5,:test) 40.2. First-class Functions 267
  • 4. Ring Documentation, Release 1.5.1 Func Test see "Message from the test function!" + nl Func Times nCount,F for x = 1 to nCount Call F() next Output: Message from the test function! Message from the test function! Message from the test function! Message from the test function! Message from the test function! 40.4 Anonymous and Nested Functions Anonymous Functions are functions without names that can be passed as parameters to other functions or stored in variables. Syntax: Func [Parameters] { [statements] } Example: test( func x,y { see "hello" + nl see "Sum : " + (x+y) + nl } ) new great { f1() } times(3, func { see "hello world" + nl } ) func test x call x(3,3) see "wow!" + nl func times n,x for t=1 to n call x() next Class great func f1 f2( func { see "Message from f1" + nl } ) func f2 x call x() Output: hello Sum : 6 40.4. Anonymous and Nested Functions 268
  • 5. Ring Documentation, Release 1.5.1 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 40.5 Equality of functions We can test if function = function or not using the ‘=’ or ‘!=’ operators 40.5. Equality of functions 269
  • 6. Ring Documentation, Release 1.5.1 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 40.5. Equality of functions 270
  • 7. CHAPTER FORTYONE 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. 41.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 41.2 globals() Function We can get a list of variables names in the global scope using the globals() function. Syntax: 271
  • 8. Ring Documentation, Release 1.5.1 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: message from test() Global Variables: x y z 41.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 41.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: 41.3. functions() Function 272
  • 9. Ring Documentation, Release 1.5.1 aList = cfunctions() See "Count : " + len(aList) + nl for x in aList see x + "()" + nl next Output: Count : 197 len() add() del() get() clock() ... Note: The complete list is removed from the previous output. 41.5 islocal() Function 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 41.6 isglobal() Function 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: 41.5. islocal() Function 273
  • 10. Ring Documentation, Release 1.5.1 x=10 y=20 test() func test see isglobal("x") + nl + isglobal("y") + nl + isglobal("z") + nl Output: 1 1 0 41.7 isfunction() Function 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 41.8 iscfunction() Function We can check if a C function is defined 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 41.7. isfunction() Function 274