SlideShare a Scribd company logo
Ring Documentation, Release 1.8
Using Lists during definition
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
Exit from more than one loop
for x = 1 to 10
for y = 1 to 10
see "x=" + x + " y=" + y + nl
if x = 3 and y = 5
exit 2 # exit from 2 loops
ok
next
next
3.5 Encourage Organization
The language encourage organization, Forget bad days using languages where the programmer start with function then
class then function and a strange mix between things!
Each source file follow the next structure
• Load Files
• Statements and Global Variables
• Functions
• Packages and Classes
This enable us to use Packages, Classes and Functions without the need to use a keyword to end these components.
We can write one line comments and multi-line comments The comment starts with # or // Multi-line comments are
written between /* and */
/*
Program Name : My first program using Ring
Date : 2015.05.08
*/
See "What is your name? " # print message on screen
give cName # get input from the user
see "Hello " + cName # say hello!
// See "Bye!"
3.6 Compact Syntax
The language is not line sensitive, you don’t need to write ; after statements, also you don’t need to press ENTER or
TAB, so we can write the next code
See "The First Message" See " Another message in the same line! " + nl
See "Enter your name?" Give Name See "Hello " + Name
The next code create a class called Point contains three attributes X,Y and Z. No keywords is used to end the pack-
age/class/function definition. Also, we can write the attributes names directly below the class name.
3.5. Encourage Organization 31
Ring Documentation, Release 1.8
Class Point X Y Z
We can use classes and functions before their definition, In this example we will create new object, set the object
attributes then print the object values.
o1 = New point o1.x=10 o1.y=20 o1.z=30 See O1 Class Point X Y Z
Instead of using the dot ‘.’ operator to access the object attributes and methods we can use braces { } to access the
object, then we can use the object attributes and methods.
o1 = New point { x=10 y=20 z=30 } See O1 Class Point X Y Z
Now we will call a method after accessing the object using { }
oPerson = new Person
{
Name = "Somebody"
Address = "Somewhere"
Phone = "0000000"
Print() # here we call the Print() method
}
Class Person Name Address Phone
Func Print
See "Name :" + name + nl +
"Address :" + Address + nl +
"Phone : " + phone + nl
When we use { } to access the object then write any attribute name, the language will check the class for any set-
ter/getter methods that will be called automatically.
New Number {
See one # Execute GetOne()
See two # Execute GetTwo()
See three # Execute GetThree()
}
Class Number one two three
Func GetOne
See "Number : One" + nl
return 1
Func GetTwo
See "Number : Two" + nl
return 2
Func GetThree
See "Number : Three" + nl
return 3
3.7 Define Natural Statements
After the object access using { } if the class contains a method called BraceEnd() it will be executed!
TimeForFun = new journey
# The first surprise!
TimeForFun {
Hello it is me # What a beatiful programming world!
}
# Our Class
Class journey
3.7. Define Natural Statements 32
Ring Documentation, Release 1.8
hello=0 it=0 is=0 me=0
func GetHello
See "Hello" + nl
func braceEnd
See "Goodbye!" + nl
We can execute code written in strings using the Eval() function
cCode = "See 'Code that will be executed later!' "
Eval(cCode) # execute the code to print the message
We can create a list then execute code generated from that list
aWords = ["hello","it","is","me"]
for word in aWords cCode=word+"=0" eval(cCode) next
We can read text files using the Read(cFileName) function and we can write files using the Write(cFileName,cString)
function.
See "Enter File Name:" Give cFileName See Read(cFileName) # Print the file content
The next example presents how to create a class that defines two instructions The first instruction is : I want window
The second instruction is : Window title = Expression Also keywords that can be ignored like the ‘the’ keyword
New App
{
I want window
The window title = "hello world"
}
Class App
# Attributes for the instruction I want window
i want window
nIwantwindow = 0
# Attributes for the instruction Window title
# Here we don't define the window attribute again
title
nWindowTitle = 0
# Keywords to ignore, just give them any value
the=0
func geti
if nIwantwindow = 0
nIwantwindow++
ok
func getwant
if nIwantwindow = 1
nIwantwindow++
ok
func getwindow
if nIwantwindow = 2
nIwantwindow= 0
see "Instruction : I want window" + nl
ok
if nWindowTitle = 0
nWindowTitle++
3.7. Define Natural Statements 33
Ring Documentation, Release 1.8
ok
func settitle cValue
if nWindowTitle = 1
nWindowTitle=0
see "Instruction : Window Title = " + cValue + nl
ok
To complete the previous example, use read() to get the content of a file that contains
I want window
The window title = "hello world"
Then use eval() to execute the content of that file!. Also, you can update the methods GetWindow() and SetTitle() to
create Real windows using the GUI Library
3.8 Define Declarative Languages
We learned how to use Natural statements to execute our code and using the same features we can use nested structures
to execute our code.
The next example from the Web library, generate HTML document using the Bootstrap library. No HTML code is
written directly in this example, we created a similar language (just as example) Then using this declarative language
that uses nested structures, we generated the HTML Document.. The idea in this example is that the GetDiv() and
GetH1() methods return an object that we can access using {} and after each object access the method BraceEnd() will
be executed to send the generated HTML to the parent object until we reach to the root where BraceEnd() will print
the output.
Load "weblib.ring"
Import System.Web
Func Main
BootStrapWebPage()
{
div
{
classname = :container
div
{
classname = :jumbotron
H1 { text("Bootstrap Page") }
}
div
{
classname = :row
for x = 1 to 3
div
{
classname = "col-sm-4"
H3 { html("Welcome to the Ring programming language") }
P { html("Using a scripting language is very fun!") }
}
next
}
}
}
3.8. Define Declarative Languages 34
Ring Documentation, Release 1.8
The classes that power the declarative interface looks like this
Class Link from ObjsBase
title link
Func braceend
cOutput = nl+GetTabs() + "<a href='" +
Link + "'> "+ Title + " </a> " + nl
Class Div from ObjsBase
Func braceend
cOutput += nl+'<div'
addattributes()
AddStyle()
getobjsdata()
cOutput += nl+"</div>" + nl
cOutput = TabMLString(cOutput)
3.9 Syntax Flexibility
Ring comes with many styles for writing your source code!
Also you can change the language keywords and operators and create your custom style!
3.10 Transparent Implementation
Ring comes with transparent implementation. We can know what is happening in each compiler stage and what is
going on during the run-time by the Virtual Machine Example : ring helloworld.ring -tokens -rules -ic
See "Hello, World!"
Output
==================================================================
Tokens - Generated by the Scanner
==================================================================
Keyword : SEE
Literal : Hello, World!
EndLine
==================================================================
==================================================================
Grammar Rules Used by The Parser
==================================================================
Rule : Program --> {Statement}
Line 1
Rule : Factor --> Literal
Rule : Range --> Factor
Rule : Term --> Range
Rule : Arithmetic --> Term
Rule : BitShift --> Arithmetic
Rule : BitAnd --> BitShift
3.9. Syntax Flexibility 35
Ring Documentation, Release 1.8
Rule : BitOrXOR --> BitAnd
Rule : Compare --> BitOrXOR
Rule : EqualOrNot --> Compare
Rule : LogicNot -> EqualOrNot
Rule : Expr --> LogicNot
Rule : Statement --> 'See' Expr
==================================================================
==================================================================
Byte Code - Before Execution by the VM
==================================================================
PC OPCode Data
1 FuncExE
2 PushC Hello, World!
3 Print
4 ReturnNull
==================================================================
Hello, World!
3.11 Visual Implementation
The Ring programming language is designed using the PWCT visual programming tool and you will find the visual
source of the language in the folder “visualsrc” - *.ssf files and the generated source code (In the C Language) in the
src folder and the include folder.
The next screen shot from the ring_vm.ssf file (Generate ring_vm.c and ring_vm.h)
3.11. Visual Implementation 36
Ring Documentation, Release 1.8
The next screen shot from the ring_list.ssf file (Generate ring_list.c and ring_list.h)
3.12 Smart Garbage Collector
Avoid memory problems :-
• Invalid Memory Access
• Memory leaks
• Uninitialized Memory Access
• Dangling pointer
Rules :-
• Global variables always stay in the memory, until you delete these variables using the assignment statement.
• Local variables always deleted after the end of the function.
• The programmer have full control on when to delete the variable from the memory using the Assignment state-
ment.
Example:
aList = [1,2,3,4,5]
aList = "nice"
After the second line directly, The list [1,2,3,4,5] will be deleted from the memory and we will have a string “nice”
• The programmer can call the function callgc() to force running the garbage collector.
• If we have a reference to a variable (when we pass objects and lists to functions), then deleting variables will be
based on reference counting, if no references everything will be deleted, but if we have a reference, the data will
stay in memory.
3.12. Smart Garbage Collector 37
Ring Documentation, Release 1.8
3.13 No Global Interpreter (VM) Lock - No GIL
When we use threads in Ring applications, We don’t have global interpreter (VM) lock (No GIL)
So threads can work in parallel and execute Ring instructions at the same time
This is better for threads and concurrency (More Faster!)
3.14 Fast Enough For Many Applications
Ring is designed to be a simple, small and flexible language in the first place, but also it is fast enough for many
applications.
Ring can do each of the next tasks in around 1 second using normal computers in the market during the last 5 years
1. Compiling 100,000 lines of code
2. Executing empty loop that count from 1 to 10,000,000
3. Executing 1000 search operation using linear search in a list contains 100,000 items, trying to find the last item
(The worst case)
4. Creating list contains 1,000,000 items then summing all of the list items
5. Adding 20,000 items to the ListWidget in GUI applications
6. Adding 5,000 nodes to the TreeWidget in GUI applications
7. Printing 10,000 messages to the terminal in Console applications
Also when we need more speed we can use C/C++ extensions!
3.13. No Global Interpreter (VM) Lock - No GIL 38
CHAPTER
FOUR
WHAT IS NEW IN RING 1.8?
In this chapter we will learn about the changes and new features in Ring 1.8 release.
4.1 List of changes and new features
Ring 1.8 comes with the next features!
• Better Performance
• Find in files Application
• String2Constant Application
• StopWatch Application
• More 3D Samples
• Compiling on Manjaro Linux
• Using This in the class region as Self
• Default value for object attributes is NULL
• The For Loops uses the local scope
• Merge binary characters
• FoxRing Library
• Better Form Designer
• Better Cards Game
• Better RingQt
• Better Code Generator For Extensions
• Better Ring Compiler and VM
• Notes to extensions creators
4.2 Better Performance
Ring 1.8 is faster than Ring 1.7
The performance gain is between 10% and 100% based on the application.
Check the 3D samples in this release to get an idea about the current performance.
39
Ring Documentation, Release 1.8
For more information check the Performance Tips chapter.
4.3 Find in files Application
Ring 1.8 comes with Find in files application
4.4 String2Constant Application
Ring 1.8 comes with String2Constant application
Using this tool we can convert the source code to be based on constants instead of string literals
Then we can store constants in separate source code files that we can translate to different languages
Where we can have special file for each language, like (English.ring, Arabic.ring and so on)
Using this simple tool, the Form Designer is translated to the Arabic language.
For more information check the Multi-language Applications chapter.
4.3. Find in files Application 40

More Related Content

PDF
The Ring programming language version 1.3 book - Part 5 of 88
PDF
The Ring programming language version 1.5.2 book - Part 6 of 181
PDF
The Ring programming language version 1.9 book - Part 7 of 210
PDF
The Ring programming language version 1.5.3 book - Part 6 of 184
PDF
The Ring programming language version 1.7 book - Part 7 of 196
PDF
C# Starter L02-Classes and Objects
PPT
OOP Core Concept
PPTX
Java Foundations: Objects and Classes
The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.5.2 book - Part 6 of 181
The Ring programming language version 1.9 book - Part 7 of 210
The Ring programming language version 1.5.3 book - Part 6 of 184
The Ring programming language version 1.7 book - Part 7 of 196
C# Starter L02-Classes and Objects
OOP Core Concept
Java Foundations: Objects and Classes

What's hot (18)

PDF
Object calisthenics
PDF
C# Starter L04-Collections
PPTX
Closer look at classes
PDF
The Ring programming language version 1.3 book - Part 83 of 88
ODT
Java practical
PDF
C# Starter L03-Utilities
PPS
Class method
DOCX
Java programming lab_manual_by_rohit_jaiswar
PPTX
16. Java stacks and queues
PDF
The Ring programming language version 1.3 book - Part 82 of 88
PPT
Introduction to csharp
PPT
Introduction to csharp
PDF
Introduction To Csharp
PDF
Java Day-6
PPTX
15. Streams Files and Directories
PPTX
Class object method constructors in java
PDF
Java Day-7
PPTX
Java Foundations: Lists, ArrayList<T>
Object calisthenics
C# Starter L04-Collections
Closer look at classes
The Ring programming language version 1.3 book - Part 83 of 88
Java practical
C# Starter L03-Utilities
Class method
Java programming lab_manual_by_rohit_jaiswar
16. Java stacks and queues
The Ring programming language version 1.3 book - Part 82 of 88
Introduction to csharp
Introduction to csharp
Introduction To Csharp
Java Day-6
15. Streams Files and Directories
Class object method constructors in java
Java Day-7
Java Foundations: Lists, ArrayList<T>
Ad

Similar to The Ring programming language version 1.8 book - Part 7 of 202 (20)

PDF
The Ring programming language version 1.5.1 book - Part 5 of 180
PDF
The Ring programming language version 1.5.4 book - Part 6 of 185
PDF
The Ring programming language version 1.2 book - Part 5 of 84
PDF
The Ring programming language version 1.6 book - Part 7 of 189
PDF
The Ring programming language version 1.10 book - Part 7 of 212
PDF
The Ring programming language version 1.10 book - Part 100 of 212
PDF
The Ring programming language version 1.7 book - Part 90 of 196
PDF
The Ring programming language version 1.4.1 book - Part 29 of 31
PDF
The Ring programming language version 1.10 book - Part 22 of 212
PDF
The Ring programming language version 1.5.1 book - Part 13 of 180
PDF
The Ring programming language version 1.7 book - Part 92 of 196
PDF
The Ring programming language version 1.5.4 book - Part 180 of 185
PDF
The Ring programming language version 1.5.2 book - Part 176 of 181
PDF
The Ring programming language version 1.7 book - Part 14 of 196
PDF
The Ring programming language version 1.5.2 book - Part 14 of 181
PDF
The Ring programming language version 1.4 book - Part 11 of 30
PDF
The Ring programming language version 1.5.3 book - Part 187 of 194
PDF
The Ring programming language version 1.6 book - Part 41 of 189
PDF
The Ring programming language version 1.7 book - Part 17 of 196
PDF
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5.1 book - Part 5 of 180
The Ring programming language version 1.5.4 book - Part 6 of 185
The Ring programming language version 1.2 book - Part 5 of 84
The Ring programming language version 1.6 book - Part 7 of 189
The Ring programming language version 1.10 book - Part 7 of 212
The Ring programming language version 1.10 book - Part 100 of 212
The Ring programming language version 1.7 book - Part 90 of 196
The Ring programming language version 1.4.1 book - Part 29 of 31
The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.5.1 book - Part 13 of 180
The Ring programming language version 1.7 book - Part 92 of 196
The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.2 book - Part 176 of 181
The Ring programming language version 1.7 book - Part 14 of 196
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.4 book - Part 11 of 30
The Ring programming language version 1.5.3 book - Part 187 of 194
The Ring programming language version 1.6 book - Part 41 of 189
The Ring programming language version 1.7 book - Part 17 of 196
The Ring programming language version 1.5 book - Part 3 of 31
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
PDF
The Ring programming language version 1.10 book - Part 211 of 212
PDF
The Ring programming language version 1.10 book - Part 210 of 212
PDF
The Ring programming language version 1.10 book - Part 208 of 212
PDF
The Ring programming language version 1.10 book - Part 207 of 212
PDF
The Ring programming language version 1.10 book - Part 205 of 212
PDF
The Ring programming language version 1.10 book - Part 206 of 212
PDF
The Ring programming language version 1.10 book - Part 204 of 212
PDF
The Ring programming language version 1.10 book - Part 203 of 212
PDF
The Ring programming language version 1.10 book - Part 202 of 212
PDF
The Ring programming language version 1.10 book - Part 201 of 212
PDF
The Ring programming language version 1.10 book - Part 200 of 212
PDF
The Ring programming language version 1.10 book - Part 199 of 212
PDF
The Ring programming language version 1.10 book - Part 198 of 212
PDF
The Ring programming language version 1.10 book - Part 197 of 212
PDF
The Ring programming language version 1.10 book - Part 196 of 212
PDF
The Ring programming language version 1.10 book - Part 195 of 212
PDF
The Ring programming language version 1.10 book - Part 194 of 212
PDF
The Ring programming language version 1.10 book - Part 193 of 212
PDF
The Ring programming language version 1.10 book - Part 192 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 210 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 205 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 203 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 200 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 197 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 194 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

Recently uploaded (20)

PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
ai tools demonstartion for schools and inter college
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
history of c programming in notes for students .pptx
PDF
AI in Product Development-omnex systems
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Introduction to Artificial Intelligence
PDF
Digital Strategies for Manufacturing Companies
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Odoo Companies in India – Driving Business Transformation.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
ai tools demonstartion for schools and inter college
Odoo POS Development Services by CandidRoot Solutions
Wondershare Filmora 15 Crack With Activation Key [2025
How to Migrate SBCGlobal Email to Yahoo Easily
CHAPTER 2 - PM Management and IT Context
Upgrade and Innovation Strategies for SAP ERP Customers
history of c programming in notes for students .pptx
AI in Product Development-omnex systems
Softaken Excel to vCard Converter Software.pdf
L1 - Introduction to python Backend.pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Introduction to Artificial Intelligence
Digital Strategies for Manufacturing Companies
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PTS Company Brochure 2025 (1).pdf.......
Operating system designcfffgfgggggggvggggggggg
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...

The Ring programming language version 1.8 book - Part 7 of 202

  • 1. Ring Documentation, Release 1.8 Using Lists during definition 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 Exit from more than one loop for x = 1 to 10 for y = 1 to 10 see "x=" + x + " y=" + y + nl if x = 3 and y = 5 exit 2 # exit from 2 loops ok next next 3.5 Encourage Organization The language encourage organization, Forget bad days using languages where the programmer start with function then class then function and a strange mix between things! Each source file follow the next structure • Load Files • Statements and Global Variables • Functions • Packages and Classes This enable us to use Packages, Classes and Functions without the need to use a keyword to end these components. We can write one line comments and multi-line comments The comment starts with # or // Multi-line comments are written between /* and */ /* Program Name : My first program using Ring Date : 2015.05.08 */ See "What is your name? " # print message on screen give cName # get input from the user see "Hello " + cName # say hello! // See "Bye!" 3.6 Compact Syntax The language is not line sensitive, you don’t need to write ; after statements, also you don’t need to press ENTER or TAB, so we can write the next code See "The First Message" See " Another message in the same line! " + nl See "Enter your name?" Give Name See "Hello " + Name The next code create a class called Point contains three attributes X,Y and Z. No keywords is used to end the pack- age/class/function definition. Also, we can write the attributes names directly below the class name. 3.5. Encourage Organization 31
  • 2. Ring Documentation, Release 1.8 Class Point X Y Z We can use classes and functions before their definition, In this example we will create new object, set the object attributes then print the object values. o1 = New point o1.x=10 o1.y=20 o1.z=30 See O1 Class Point X Y Z Instead of using the dot ‘.’ operator to access the object attributes and methods we can use braces { } to access the object, then we can use the object attributes and methods. o1 = New point { x=10 y=20 z=30 } See O1 Class Point X Y Z Now we will call a method after accessing the object using { } oPerson = new Person { Name = "Somebody" Address = "Somewhere" Phone = "0000000" Print() # here we call the Print() method } Class Person Name Address Phone Func Print See "Name :" + name + nl + "Address :" + Address + nl + "Phone : " + phone + nl When we use { } to access the object then write any attribute name, the language will check the class for any set- ter/getter methods that will be called automatically. New Number { See one # Execute GetOne() See two # Execute GetTwo() See three # Execute GetThree() } Class Number one two three Func GetOne See "Number : One" + nl return 1 Func GetTwo See "Number : Two" + nl return 2 Func GetThree See "Number : Three" + nl return 3 3.7 Define Natural Statements After the object access using { } if the class contains a method called BraceEnd() it will be executed! TimeForFun = new journey # The first surprise! TimeForFun { Hello it is me # What a beatiful programming world! } # Our Class Class journey 3.7. Define Natural Statements 32
  • 3. Ring Documentation, Release 1.8 hello=0 it=0 is=0 me=0 func GetHello See "Hello" + nl func braceEnd See "Goodbye!" + nl We can execute code written in strings using the Eval() function cCode = "See 'Code that will be executed later!' " Eval(cCode) # execute the code to print the message We can create a list then execute code generated from that list aWords = ["hello","it","is","me"] for word in aWords cCode=word+"=0" eval(cCode) next We can read text files using the Read(cFileName) function and we can write files using the Write(cFileName,cString) function. See "Enter File Name:" Give cFileName See Read(cFileName) # Print the file content The next example presents how to create a class that defines two instructions The first instruction is : I want window The second instruction is : Window title = Expression Also keywords that can be ignored like the ‘the’ keyword New App { I want window The window title = "hello world" } Class App # Attributes for the instruction I want window i want window nIwantwindow = 0 # Attributes for the instruction Window title # Here we don't define the window attribute again title nWindowTitle = 0 # Keywords to ignore, just give them any value the=0 func geti if nIwantwindow = 0 nIwantwindow++ ok func getwant if nIwantwindow = 1 nIwantwindow++ ok func getwindow if nIwantwindow = 2 nIwantwindow= 0 see "Instruction : I want window" + nl ok if nWindowTitle = 0 nWindowTitle++ 3.7. Define Natural Statements 33
  • 4. Ring Documentation, Release 1.8 ok func settitle cValue if nWindowTitle = 1 nWindowTitle=0 see "Instruction : Window Title = " + cValue + nl ok To complete the previous example, use read() to get the content of a file that contains I want window The window title = "hello world" Then use eval() to execute the content of that file!. Also, you can update the methods GetWindow() and SetTitle() to create Real windows using the GUI Library 3.8 Define Declarative Languages We learned how to use Natural statements to execute our code and using the same features we can use nested structures to execute our code. The next example from the Web library, generate HTML document using the Bootstrap library. No HTML code is written directly in this example, we created a similar language (just as example) Then using this declarative language that uses nested structures, we generated the HTML Document.. The idea in this example is that the GetDiv() and GetH1() methods return an object that we can access using {} and after each object access the method BraceEnd() will be executed to send the generated HTML to the parent object until we reach to the root where BraceEnd() will print the output. Load "weblib.ring" Import System.Web Func Main BootStrapWebPage() { div { classname = :container div { classname = :jumbotron H1 { text("Bootstrap Page") } } div { classname = :row for x = 1 to 3 div { classname = "col-sm-4" H3 { html("Welcome to the Ring programming language") } P { html("Using a scripting language is very fun!") } } next } } } 3.8. Define Declarative Languages 34
  • 5. Ring Documentation, Release 1.8 The classes that power the declarative interface looks like this Class Link from ObjsBase title link Func braceend cOutput = nl+GetTabs() + "<a href='" + Link + "'> "+ Title + " </a> " + nl Class Div from ObjsBase Func braceend cOutput += nl+'<div' addattributes() AddStyle() getobjsdata() cOutput += nl+"</div>" + nl cOutput = TabMLString(cOutput) 3.9 Syntax Flexibility Ring comes with many styles for writing your source code! Also you can change the language keywords and operators and create your custom style! 3.10 Transparent Implementation Ring comes with transparent implementation. We can know what is happening in each compiler stage and what is going on during the run-time by the Virtual Machine Example : ring helloworld.ring -tokens -rules -ic See "Hello, World!" Output ================================================================== Tokens - Generated by the Scanner ================================================================== Keyword : SEE Literal : Hello, World! EndLine ================================================================== ================================================================== Grammar Rules Used by The Parser ================================================================== Rule : Program --> {Statement} Line 1 Rule : Factor --> Literal Rule : Range --> Factor Rule : Term --> Range Rule : Arithmetic --> Term Rule : BitShift --> Arithmetic Rule : BitAnd --> BitShift 3.9. Syntax Flexibility 35
  • 6. Ring Documentation, Release 1.8 Rule : BitOrXOR --> BitAnd Rule : Compare --> BitOrXOR Rule : EqualOrNot --> Compare Rule : LogicNot -> EqualOrNot Rule : Expr --> LogicNot Rule : Statement --> 'See' Expr ================================================================== ================================================================== Byte Code - Before Execution by the VM ================================================================== PC OPCode Data 1 FuncExE 2 PushC Hello, World! 3 Print 4 ReturnNull ================================================================== Hello, World! 3.11 Visual Implementation The Ring programming language is designed using the PWCT visual programming tool and you will find the visual source of the language in the folder “visualsrc” - *.ssf files and the generated source code (In the C Language) in the src folder and the include folder. The next screen shot from the ring_vm.ssf file (Generate ring_vm.c and ring_vm.h) 3.11. Visual Implementation 36
  • 7. Ring Documentation, Release 1.8 The next screen shot from the ring_list.ssf file (Generate ring_list.c and ring_list.h) 3.12 Smart Garbage Collector Avoid memory problems :- • Invalid Memory Access • Memory leaks • Uninitialized Memory Access • Dangling pointer Rules :- • Global variables always stay in the memory, until you delete these variables using the assignment statement. • Local variables always deleted after the end of the function. • The programmer have full control on when to delete the variable from the memory using the Assignment state- ment. Example: aList = [1,2,3,4,5] aList = "nice" After the second line directly, The list [1,2,3,4,5] will be deleted from the memory and we will have a string “nice” • The programmer can call the function callgc() to force running the garbage collector. • If we have a reference to a variable (when we pass objects and lists to functions), then deleting variables will be based on reference counting, if no references everything will be deleted, but if we have a reference, the data will stay in memory. 3.12. Smart Garbage Collector 37
  • 8. Ring Documentation, Release 1.8 3.13 No Global Interpreter (VM) Lock - No GIL When we use threads in Ring applications, We don’t have global interpreter (VM) lock (No GIL) So threads can work in parallel and execute Ring instructions at the same time This is better for threads and concurrency (More Faster!) 3.14 Fast Enough For Many Applications Ring is designed to be a simple, small and flexible language in the first place, but also it is fast enough for many applications. Ring can do each of the next tasks in around 1 second using normal computers in the market during the last 5 years 1. Compiling 100,000 lines of code 2. Executing empty loop that count from 1 to 10,000,000 3. Executing 1000 search operation using linear search in a list contains 100,000 items, trying to find the last item (The worst case) 4. Creating list contains 1,000,000 items then summing all of the list items 5. Adding 20,000 items to the ListWidget in GUI applications 6. Adding 5,000 nodes to the TreeWidget in GUI applications 7. Printing 10,000 messages to the terminal in Console applications Also when we need more speed we can use C/C++ extensions! 3.13. No Global Interpreter (VM) Lock - No GIL 38
  • 9. CHAPTER FOUR WHAT IS NEW IN RING 1.8? In this chapter we will learn about the changes and new features in Ring 1.8 release. 4.1 List of changes and new features Ring 1.8 comes with the next features! • Better Performance • Find in files Application • String2Constant Application • StopWatch Application • More 3D Samples • Compiling on Manjaro Linux • Using This in the class region as Self • Default value for object attributes is NULL • The For Loops uses the local scope • Merge binary characters • FoxRing Library • Better Form Designer • Better Cards Game • Better RingQt • Better Code Generator For Extensions • Better Ring Compiler and VM • Notes to extensions creators 4.2 Better Performance Ring 1.8 is faster than Ring 1.7 The performance gain is between 10% and 100% based on the application. Check the 3D samples in this release to get an idea about the current performance. 39
  • 10. Ring Documentation, Release 1.8 For more information check the Performance Tips chapter. 4.3 Find in files Application Ring 1.8 comes with Find in files application 4.4 String2Constant Application Ring 1.8 comes with String2Constant application Using this tool we can convert the source code to be based on constants instead of string literals Then we can store constants in separate source code files that we can translate to different languages Where we can have special file for each language, like (English.ring, Arabic.ring and so on) Using this simple tool, the Form Designer is translated to the Arabic language. For more information check the Multi-language Applications chapter. 4.3. Find in files Application 40