SlideShare a Scribd company logo
1 of 10
Download to read offline
Ring Documentation, Release 1.5.3
Return [Expression]
Tip: the Expression after the return command is optional and we can use the return command to end the function
execution without returning any value.
Note: if the function doesn’t return explicit value, it will return NULL (empty string = “” ).
Example:
load "stdlib.ring"
if novalue() = NULL {
print("the function doesn't return a valuen")
}
func novalue { }
24.8 Recursion
The Ring programming language support Recursion and the function can call itself using different parameters.
Example:
load "stdlib.ring"
print( fact(5) ) # output = 120
func fact(x) { if x = 0 { return 1 else return x * fact(x-1) } }
24.8. Recursion 185
CHAPTER
TWENTYFIVE
PROGRAM STRUCTURE
In this chapter we will learn about using many source code files in the same project.
25.1 Source Code File Sections
Each source code file may contains the next sections (in the same order).
Source Code File Sections
Load Files
Statements and Global Variables
Functions
Packages and Classes
The application maybe one or more of files.
25.2 Using Many Source Code Files
To include another source file in the project, just use the load command.
Syntax:
Load "filename.ring"
Note: The Load command is executed directly by the compiler in the parsing stage
Tip: if you don’t know the file name until the runtime, or you need to use functions to get the file path, just use eval().
Example:
# File : Start.ring
Load "sub.ring"
sayhello("Mahmoud")
# File : sub.ring
func sayhello cName
see "Hello " + cName + nl
186
CHAPTER
TWENTYSIX
LISTS
In this chapter we are going to learn how to deal with lists.
26.1 Create Lists
We can create new lists by defining the list items inside square bracts.
Example:
aList = [1,2,3,4,5]
Also we can create new lists using the : operator
Example:
aList = 1:5
aList2 = "a":"z"
Example:
aList = 5:1
aList2 = "z":"a"
Also we can create lists using the list() function
Syntax:
list = list(size)
Example
aList = list(10) # aList contains 10 items
Note: the list index start from 1
26.2 Add Items
To add new items to the list, we can use the Add() function.
Syntax:
Add(List,Item)
187
Ring Documentation, Release 1.5.3
Example:
aList = ["one","two"]
add(aList,"three")
see aList
Also we can do that using the + operator.
Syntax:
List + item
Example:
aList = 1:10 # create list contains numbers from 1 to 10
aList + 11 # add number 11 to the list
see aList # print the list
26.3 Get List Size
We can get the list size using the len() function
Syntax:
Len(List)
Example:
aList = 1:20 see len(aList) # print 20
26.4 Delete Item From List
To delete an item from the list, we can use the del() function
Syntax:
del(list,index)
Example:
aList = ["one","two","other","three"]
Del(aList,3) # delete item number three
see aList # print one two three
26.5 Get List Item
To get an item from the list, we uses the next syntax
List[Index]
Example:
aList = ["Cairo","Riyadh"]
see "Egypt : " + aList[1] + nl +
"KSA : " + aList[2] + nl
26.3. Get List Size 188
Ring Documentation, Release 1.5.3
26.6 Set List Item
To set the value of an item inside the list, we can use the next syntax
List[Index] = Expression
Example:
aList = list(3) # create list contains three items
aList[1] = "one" aList[2] = "two" aList[3] = "three"
see aList
26.7 Search
To find an item inside the list we can use the find() function
Syntax:
Find(List,ItemValue) ---> Item Index
Find(List,ItemValue,nColumn) ---> Search in nColumn, returns the Item Index
Find(List,ItemValue,nColumn,cAttribute) ---> Item Index
Example:
aList = ["one","two","three","four","five"]
see find(aList,"three") # print 3
Example:
mylist = [["one",1],
["two",2],
["three",3]]
see find(mylist,"two",1) + nl # print 2
see find(mylist,2,2) + nl # print 2
Also we can use the binarysearch() function to search in sorted list.
Syntax:
BinarySearch(List,ItemValue) ---> Item Index
BinarySearch(List,ItemValue,nColumn) ---> Search in nColumn, returns the Item Index
Example:
aList = ["one","two","three","four","five"]
aList = sort(aList)
see binarysearch(aList,"three")
Output:
five
four
one
three
two
4
26.6. Set List Item 189
Ring Documentation, Release 1.5.3
26.8 Sort
We can sort the list using the sort() function.
Syntax:
Sort(List) ---> Sorted List
Sort(List,nColumn) ---> Sorted List based on nColumn
Sort(List,nColumn,cAttribute) ---> Sorted List based on Object Attribute
Example:
aList = [10,12,3,5,31,15]
aList = sort(aList) see aList # print 3 5 10 12 15 31
We can sort list of strings
Example:
mylist = ["mahmoud","samir","ahmed","ibrahim","mohammed"]
see mylist # print list before sorting
mylist = sort(mylist) # sort list
see "list after sort"+nl
see mylist # print ahmed ibrahim mahmoud mohammed samir
We can sort a list based on a specific column.
Example:
aList = [ ["mahmoud",15000] ,
["ahmed", 14000 ] ,
["samir", 16000 ] ,
["mohammed", 12000 ] ,
["ibrahim",11000 ] ]
aList2 = sort(aList,1)
see aList2
Output:
ahmed
14000
ibrahim
11000
mahmoud
15000
mohammed
12000
samir
16000
26.9 Reverse
We can reverse a list using the reverse() function.
Syntax:
26.8. Sort 190
Ring Documentation, Release 1.5.3
Reverse(List) ---> Reversed List
Example:
aList = [10,20,30,40,50]
aList = reverse(aList)
see aList # print 50 40 30 20 10
26.10 Insert Items
To insert an item in the list we can use the insert() function.
Syntax:
Insert(List,Index,Item)
The inserted item will be AFTER the Index
Example:
aList = ["A","B","D","E"]
insert(aList,2,"C") # Inserts AFTER Index 2, "C" into Position 3
see aList # print A B C D E
26.11 Nested Lists
The list may contain other lists
Example:
aList = [ 1 , [10,20,30] , 5 , [100,1000,5000] ]
aList2 = [
"one","two",
[3,4],
[20,30], ["three",
"four",
"five",[100,200,300]
]
]
see aList[2] # print 10 20 30
see aList[4][3] + nl # print 5000
see aList2[5][2] + nl # print four
see aList2[5][4][3] # print 300
26.12 Copy Lists
We can copy lists (including nested lists) using the Assignment operator.
Example:
26.10. Insert Items 191
Ring Documentation, Release 1.5.3
aList = [
"one","two",
[3,4],
[20,30], ["three",
"four",
"five",[100,200,300]
]
]
aList2 = aList # Copy aList to aList2
aList2[5] = "other" # modify item number five
see aList2[5] + nl # print other
see aList[5] # print three four five 100 200 300
26.13 First-class lists
Lists are first-class citizens where we can store lists in variables, pass lists to functions, and return lists from functions.
Example:
aList = duplicate( [1,2,3,4,5] )
see aList[10] + nl # print 5
see mylist() # print 10 20 30 40 50
func duplicate list
nMax = len(list)
for x = 1 to nMax
list + list[x]
next
return list
func mylist return [10,20,30,40,50]
26.14 Using Lists during definition
We can use the list items while we are defining the list for the first time.
Example:
aList = [ [1,2,3,4,5] , aList[1] , aList[1] ]
see aList # print 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
26.15 Passing Lists to Functions
Lists are passed to functions by reference, This means that the called function will work on the same list and can
modify it.
Example:
func main
aList = [1,2,3,4,5] # create list, local in function main
26.13. First-class lists 192
Ring Documentation, Release 1.5.3
myfunc(aList) # call function, pass list by reference
see aList # print 1 2 3 4 5 6 7 8 9 10
func myfunc list
list + [6,7,8,9,10]
26.16 Access List Items by String Index
Instead of using numbers to determine the item index when we get item value or set item value, We can access items
using string index if the item is a list contains two items and the first item is a string.
Example:
aList = [ ["one",1] , ["two",2] , ["three",3] ]
see aList["one"] + nl +
aList["two"] + nl +
aList["three"] # print 1 2 3
This type of lists can be defined in a better syntax using the : and = operators.
Example:
aList = [ :one = 1 , :two = 2 , :three = 3 ]
see aList["one"] + nl +
aList["two"] + nl +
aList["three"] + nl # print 1 2 3
see aList[1] # print one 1
Tip: using : before identifier (one word) means literal
Note: using = inside list definition create a list of two items where the first item is the left side and the second item is
the right side.
We can add new items to the list using the string index
Example:
aList = []
aList["Egypt"] = "Cairo"
aList["KSA"] = "Riyadh"
see aList["Egypt"] + nl + # print Cairo
aList["KSA"] + nl # print Riyadh
26.17 Passing Parameters Using List
This type of lists is very good for passing parameters to functions Where the order of parameters will not be important
(we can change the order).
Also some parameters maybe optional.
Example:
26.16. Access List Items by String Index 193
Ring Documentation, Release 1.5.3
myconnect ( [ :server = "myserver.com" , :port = 80 ,
:username = "mahmoud" , :password = "password" ] )
func myconnect mypara
# print connection details
see "User Name : " + mypara[:username] + nl +
"Password : " + mypara[:password] + nl +
"Server : " + mypara[:server] + nl +
"Port : " + mypara[:port]
26.18 Swap Items
We can swap the list items using the Swap() function.
Example:
aList = [:one,:two,:four,:three]
see aList
see copy("*",50) + nl
swap(aList,3,4)
see aList
Output
one
two
four
three
**************************************************
one
two
three
four
26.18. Swap Items 194

More Related Content

What's hot

The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181Mahmoud Samir Fayed
 
Arrays in python
Arrays in pythonArrays in python
Arrays in pythonLifna C.S
 
The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30Mahmoud Samir Fayed
 
Arrays in python
Arrays in pythonArrays in python
Arrays in pythonmoazamali28
 
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185Mahmoud Samir Fayed
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaEdureka!
 
The Ring programming language version 1.5.1 book - Part 21 of 180
The Ring programming language version 1.5.1 book - Part 21 of 180The Ring programming language version 1.5.1 book - Part 21 of 180
The Ring programming language version 1.5.1 book - Part 21 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202Mahmoud Samir Fayed
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data typeMegha V
 
Functional Programming in Swift
Functional Programming in SwiftFunctional Programming in Swift
Functional Programming in SwiftSaugat Gautam
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)riue
 
The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88Mahmoud Samir Fayed
 

What's hot (20)

The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181
 
List in Python
List in PythonList in Python
List in Python
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - ListsPython Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - Lists
 
Lists
ListsLists
Lists
 
The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
 
Map, Reduce and Filter in Swift
Map, Reduce and Filter in SwiftMap, Reduce and Filter in Swift
Map, Reduce and Filter in Swift
 
The Ring programming language version 1.5.1 book - Part 21 of 180
The Ring programming language version 1.5.1 book - Part 21 of 180The Ring programming language version 1.5.1 book - Part 21 of 180
The Ring programming language version 1.5.1 book - Part 21 of 180
 
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
 
Functional Programming in Swift
Functional Programming in SwiftFunctional Programming in Swift
Functional Programming in Swift
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
 
Python : Dictionaries
Python : DictionariesPython : Dictionaries
Python : Dictionaries
 

Similar to The Ring programming language version 1.5.3 book - Part 22 of 184

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
 
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
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdfAshaWankar1
 
Lists.pptx
Lists.pptxLists.pptx
Lists.pptxYagna15
 
List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptxChandanVatsa2
 
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdfGE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdfAsst.prof M.Gokilavani
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdfNehaSpillai1
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdfNehaSpillai1
 
The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212Mahmoud Samir Fayed
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methodsnarmadhakin
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptxSakith1
 
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
 

Similar to The Ring programming language version 1.5.3 book - Part 22 of 184 (20)

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
 
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
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 
Lists.pptx
Lists.pptxLists.pptx
Lists.pptx
 
List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptx
 
Module-2.pptx
Module-2.pptxModule-2.pptx
Module-2.pptx
 
Python lists
Python listsPython lists
Python lists
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
 
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdfGE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
GE3151 PSPP UNIT IV QUESTION BANK.docx.pdf
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdf
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdf
 
Python list
Python listPython list
Python list
 
Python data handling notes
Python data handling notesPython data handling notes
Python data handling notes
 
The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 
Python Lecture 8
Python Lecture 8Python Lecture 8
Python Lecture 8
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptx
 
Unit - 4.ppt
Unit - 4.pptUnit - 4.ppt
Unit - 4.ppt
 
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
 

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

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 pragmaticsAndrey Dotsenko
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
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
 
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
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
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
 
#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
 

Recently uploaded (20)

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
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
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
 
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
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
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...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
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
 
#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
 

The Ring programming language version 1.5.3 book - Part 22 of 184

  • 1. Ring Documentation, Release 1.5.3 Return [Expression] Tip: the Expression after the return command is optional and we can use the return command to end the function execution without returning any value. Note: if the function doesn’t return explicit value, it will return NULL (empty string = “” ). Example: load "stdlib.ring" if novalue() = NULL { print("the function doesn't return a valuen") } func novalue { } 24.8 Recursion The Ring programming language support Recursion and the function can call itself using different parameters. Example: load "stdlib.ring" print( fact(5) ) # output = 120 func fact(x) { if x = 0 { return 1 else return x * fact(x-1) } } 24.8. Recursion 185
  • 2. CHAPTER TWENTYFIVE PROGRAM STRUCTURE In this chapter we will learn about using many source code files in the same project. 25.1 Source Code File Sections Each source code file may contains the next sections (in the same order). Source Code File Sections Load Files Statements and Global Variables Functions Packages and Classes The application maybe one or more of files. 25.2 Using Many Source Code Files To include another source file in the project, just use the load command. Syntax: Load "filename.ring" Note: The Load command is executed directly by the compiler in the parsing stage Tip: if you don’t know the file name until the runtime, or you need to use functions to get the file path, just use eval(). Example: # File : Start.ring Load "sub.ring" sayhello("Mahmoud") # File : sub.ring func sayhello cName see "Hello " + cName + nl 186
  • 3. CHAPTER TWENTYSIX LISTS In this chapter we are going to learn how to deal with lists. 26.1 Create Lists We can create new lists by defining the list items inside square bracts. Example: aList = [1,2,3,4,5] Also we can create new lists using the : operator Example: aList = 1:5 aList2 = "a":"z" Example: aList = 5:1 aList2 = "z":"a" Also we can create lists using the list() function Syntax: list = list(size) Example aList = list(10) # aList contains 10 items Note: the list index start from 1 26.2 Add Items To add new items to the list, we can use the Add() function. Syntax: Add(List,Item) 187
  • 4. Ring Documentation, Release 1.5.3 Example: aList = ["one","two"] add(aList,"three") see aList Also we can do that using the + operator. Syntax: List + item Example: aList = 1:10 # create list contains numbers from 1 to 10 aList + 11 # add number 11 to the list see aList # print the list 26.3 Get List Size We can get the list size using the len() function Syntax: Len(List) Example: aList = 1:20 see len(aList) # print 20 26.4 Delete Item From List To delete an item from the list, we can use the del() function Syntax: del(list,index) Example: aList = ["one","two","other","three"] Del(aList,3) # delete item number three see aList # print one two three 26.5 Get List Item To get an item from the list, we uses the next syntax List[Index] Example: aList = ["Cairo","Riyadh"] see "Egypt : " + aList[1] + nl + "KSA : " + aList[2] + nl 26.3. Get List Size 188
  • 5. Ring Documentation, Release 1.5.3 26.6 Set List Item To set the value of an item inside the list, we can use the next syntax List[Index] = Expression Example: aList = list(3) # create list contains three items aList[1] = "one" aList[2] = "two" aList[3] = "three" see aList 26.7 Search To find an item inside the list we can use the find() function Syntax: Find(List,ItemValue) ---> Item Index Find(List,ItemValue,nColumn) ---> Search in nColumn, returns the Item Index Find(List,ItemValue,nColumn,cAttribute) ---> Item Index Example: aList = ["one","two","three","four","five"] see find(aList,"three") # print 3 Example: mylist = [["one",1], ["two",2], ["three",3]] see find(mylist,"two",1) + nl # print 2 see find(mylist,2,2) + nl # print 2 Also we can use the binarysearch() function to search in sorted list. Syntax: BinarySearch(List,ItemValue) ---> Item Index BinarySearch(List,ItemValue,nColumn) ---> Search in nColumn, returns the Item Index Example: aList = ["one","two","three","four","five"] aList = sort(aList) see binarysearch(aList,"three") Output: five four one three two 4 26.6. Set List Item 189
  • 6. Ring Documentation, Release 1.5.3 26.8 Sort We can sort the list using the sort() function. Syntax: Sort(List) ---> Sorted List Sort(List,nColumn) ---> Sorted List based on nColumn Sort(List,nColumn,cAttribute) ---> Sorted List based on Object Attribute Example: aList = [10,12,3,5,31,15] aList = sort(aList) see aList # print 3 5 10 12 15 31 We can sort list of strings Example: mylist = ["mahmoud","samir","ahmed","ibrahim","mohammed"] see mylist # print list before sorting mylist = sort(mylist) # sort list see "list after sort"+nl see mylist # print ahmed ibrahim mahmoud mohammed samir We can sort a list based on a specific column. Example: aList = [ ["mahmoud",15000] , ["ahmed", 14000 ] , ["samir", 16000 ] , ["mohammed", 12000 ] , ["ibrahim",11000 ] ] aList2 = sort(aList,1) see aList2 Output: ahmed 14000 ibrahim 11000 mahmoud 15000 mohammed 12000 samir 16000 26.9 Reverse We can reverse a list using the reverse() function. Syntax: 26.8. Sort 190
  • 7. Ring Documentation, Release 1.5.3 Reverse(List) ---> Reversed List Example: aList = [10,20,30,40,50] aList = reverse(aList) see aList # print 50 40 30 20 10 26.10 Insert Items To insert an item in the list we can use the insert() function. Syntax: Insert(List,Index,Item) The inserted item will be AFTER the Index Example: aList = ["A","B","D","E"] insert(aList,2,"C") # Inserts AFTER Index 2, "C" into Position 3 see aList # print A B C D E 26.11 Nested Lists The list may contain other lists Example: aList = [ 1 , [10,20,30] , 5 , [100,1000,5000] ] aList2 = [ "one","two", [3,4], [20,30], ["three", "four", "five",[100,200,300] ] ] see aList[2] # print 10 20 30 see aList[4][3] + nl # print 5000 see aList2[5][2] + nl # print four see aList2[5][4][3] # print 300 26.12 Copy Lists We can copy lists (including nested lists) using the Assignment operator. Example: 26.10. Insert Items 191
  • 8. Ring Documentation, Release 1.5.3 aList = [ "one","two", [3,4], [20,30], ["three", "four", "five",[100,200,300] ] ] aList2 = aList # Copy aList to aList2 aList2[5] = "other" # modify item number five see aList2[5] + nl # print other see aList[5] # print three four five 100 200 300 26.13 First-class lists Lists are first-class citizens where we can store lists in variables, pass lists to functions, and return lists from functions. Example: aList = duplicate( [1,2,3,4,5] ) see aList[10] + nl # print 5 see mylist() # print 10 20 30 40 50 func duplicate list nMax = len(list) for x = 1 to nMax list + list[x] next return list func mylist return [10,20,30,40,50] 26.14 Using Lists during definition We can use the list items while we are defining the list for the first time. Example: aList = [ [1,2,3,4,5] , aList[1] , aList[1] ] see aList # print 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 26.15 Passing Lists to Functions Lists are passed to functions by reference, This means that the called function will work on the same list and can modify it. Example: func main aList = [1,2,3,4,5] # create list, local in function main 26.13. First-class lists 192
  • 9. Ring Documentation, Release 1.5.3 myfunc(aList) # call function, pass list by reference see aList # print 1 2 3 4 5 6 7 8 9 10 func myfunc list list + [6,7,8,9,10] 26.16 Access List Items by String Index Instead of using numbers to determine the item index when we get item value or set item value, We can access items using string index if the item is a list contains two items and the first item is a string. Example: aList = [ ["one",1] , ["two",2] , ["three",3] ] see aList["one"] + nl + aList["two"] + nl + aList["three"] # print 1 2 3 This type of lists can be defined in a better syntax using the : and = operators. Example: aList = [ :one = 1 , :two = 2 , :three = 3 ] see aList["one"] + nl + aList["two"] + nl + aList["three"] + nl # print 1 2 3 see aList[1] # print one 1 Tip: using : before identifier (one word) means literal Note: using = inside list definition create a list of two items where the first item is the left side and the second item is the right side. We can add new items to the list using the string index Example: aList = [] aList["Egypt"] = "Cairo" aList["KSA"] = "Riyadh" see aList["Egypt"] + nl + # print Cairo aList["KSA"] + nl # print Riyadh 26.17 Passing Parameters Using List This type of lists is very good for passing parameters to functions Where the order of parameters will not be important (we can change the order). Also some parameters maybe optional. Example: 26.16. Access List Items by String Index 193
  • 10. Ring Documentation, Release 1.5.3 myconnect ( [ :server = "myserver.com" , :port = 80 , :username = "mahmoud" , :password = "password" ] ) func myconnect mypara # print connection details see "User Name : " + mypara[:username] + nl + "Password : " + mypara[:password] + nl + "Server : " + mypara[:server] + nl + "Port : " + mypara[:port] 26.18 Swap Items We can swap the list items using the Swap() function. Example: aList = [:one,:two,:four,:three] see aList see copy("*",50) + nl swap(aList,3,4) see aList Output one two four three ************************************************** one two three four 26.18. Swap Items 194