The Ring programming language version 1.9 book - Part 17 of 210
1. Ring Documentation, Release 1.9
โข RingQt : Add QDateTime Class
โข RingQt : New methods added to QMenu and QCursor Classes
Example:
load "guilib.ring"
new qApp {
win = new qwidget() {
setwindowtitle("Context Menu")
resize(400,400)
myfilter = new qAllEvents(win) {
setContextmenuEvent("mymenu()")
}
installeventfilter(myfilter)
show()
}
exec()
}
func mymenu
new qMenu(win) {
8.21. What is new in Ring 1.5.3? 129
2. Ring Documentation, Release 1.9
oAction = new qAction(win) {
settext("new")
SetCLickevent("See :New")
}
addaction(oAction)
oAction = new qAction(win) {
settext("open")
SetCLickevent("See :Open")
}
addaction(oAction)
oAction = new qAction(win) {
settext("save")
SetCLickevent("See :Save")
}
addaction(oAction)
oAction = new qAction(win) {
settext("close")
SetCLickevent("See :Close")
}
addaction(oAction)
oCursor = new qCursor()
exec(oCursor.pos())
}
โข Compiler : Support using _ in numbers
Example:
x = 1_000_000
see type(x)+nl
see x+1+nl
Output:
NUMBER
100000001
โข Compiler : Support using f after numbers
Example:
x = 19.99f
see type(x) + nl
Output:
NUMBER
โข Google API Shortener Application
Screen Shots:
8.21. What is new in Ring 1.5.3? 130
3. Ring Documentation, Release 1.9
โข TicTacToe 3D Game
Screen Shot:
8.22 What is new in Ring 1.5.4?
โข CalmoSoft Fifteen Puzzle Game 3D
โข Ring Notepad - New Styles
8.22. What is new in Ring 1.5.4? 131
4. Ring Documentation, Release 1.9
โข Ring Notepad - Better Toolbar Style
โข Ring Notepad - View Modes
โข Ring Notepad - QPlainTextEdit - donโt set back color for the scroll bars
โข Ring Notepad - Style Fusion (White) - use Silver color for comments
โข Ring Notepad - Tab and Shift-Tab - Indent multiple lines
โข Form Designer - Better Toolbar Style
โข Form Designer - Nice backcolor for Window Flags and Menubar Designer
โข Form Designer - Default back color for controls
โข RingQt - Added grab() and windowHandle() methods to QWidget class
โข RingQt - Added new methods to QPixmap Class
โข RingQt - Added Classes :-
โ QScreen
โ QWindow
โ QGuiApplication
โ QTextBrowser
โข Code Generator for Extensions - Nonew Option - Support Parent Class
โข Ring VM - Internal Implementation - Pass state to Strings and Lists objects
โข Ring VM - Garbage Collector - Memory Pool for Small Objects
โข Ring VM - Better code for Saving/Restoring the State
8.22. What is new in Ring 1.5.4? 132
5. CHAPTER
NINE
WHAT IS NEW IN RING 1.4?
In this chapter we will learn about the changes and new features in Ring 1.4 release.
9.1 List of changes and new features
Ring 1.4 comes with many new features
โข Change: Basic Extensions are separated from RingVM
โข The Natural Library
โข New Style is added to Ring Notepad
โข RingREPL
โข Convert between Numbers and Bytes
โข Better StdLib
โข Better WebLib
โข Better RingQt
โข Qt Class Convertor
9.2 Change: Basic Extensions are separated from RingVM
In Ring 1.4 the next libraries are separated from RingVM
โข RingODBC
โข RingMySQL
โข RingSQLite
โข RingOpenSSL
โข RingInternet
To use these libraries, Use the Load command.
load "odbclib.ring"
# use ODBC Functions
load "mysqllib.ring"
# use MySQL Functions
133
6. Ring Documentation, Release 1.9
load "sqlitelib.ring"
# use SQLite Functions
load "openssllib.ring"
# use OpenSSL Functions ( Hash and Security functions)
load "internetlib.ring"
# use Internet Functions ( Download() and SendEmail() )
If you will use all of these libraries, You can just use stdlib.ring And the stdlib.ring will load odbclib.ring, mysqllib.ring,
sqlitelib.ring, opensslib.ring and internetlib.ring ๏ฌles.
load "stdlib.ring"
9.3 The Natural Library
Ring 1.4 comes with the Natural Library to quickly de๏ฌne a language that contains a group of commands.
We will write the natural code in a Text ๏ฌle, for example program.txt
File: program.txt
Welcome to the Ring programming language!
What you are reading now is not comments, I swear!
After many years of programming I decided to think different about
programming and solve the problems in a better way.
We are writing commands or code and the Ring language is reading
it to understand us! Sure, What you are seeing now is
just ***part of the code - Not the Complete Program***
You have to write little things before and after this
part to be able to run it!
It is the natural part of our code where we can write in English,
Arabic or any Natural Language Then we will tell the computer
through the Ring language what must happens! in a way that we can scale
for large frameworks and programs.
Just imagine what will happens to the world of programming once
we create many powerful frameworks using the Ring language that
uses this way (Natural Programming).
For example When we say Hello to the Machine, It can reply! and when we
say count from 1 to 5 it will understand us, Also if
we said count from 5 to 1 it will
understand us too! You can see the Output window!
This Goal is not new, but the Ring language comes
with an innovative solution to this problem.
Output:
Hello, Sir!
The Numbers!
9.3. The Natural Library 134
7. Ring Documentation, Release 1.9
1
2
3
4
5
I will count Again!
5
4
3
2
1
To execute the natural code, We have start.ring
In start.ring we de๏ฌne the language and the commands.
File: start.ring
load "stdlib.ring"
load "naturallib.ring"
New NaturalLanguage {
SetLanguageName(:MyLanguage)
SetCommandsPath(CurrentDir()+"/../command")
SetPackageName("MyLanguage.Natural")
UseCommand(:Hello)
UseCommand(:Count)
RunFile("program.txt")
}
We de๏ฌned a language called MyLanguage, We have folder for the language commands.
Each command will de๏ฌne a class that belong to the MyLanguage.Natural package.
We will de๏ฌne two commands, Hello and Count.
So we must have two ๏ฌles for de๏ฌning the commands in the CurrentDir()+โ/../commandโ folder
File: hello.ring
DefineNaturalCommand.SyntaxIsKeyword([
:Package = "MyLanguage.Natural",
:Keyword = :hello,
:Function = func {
See "Hello, Sir!" + nl + nl
}
])
File: count.ring
9.3. The Natural Library 135
8. Ring Documentation, Release 1.9
DefineNaturalCommand.SyntaxIsKeywordNumberNumber([
:Package = "MyLanguage.Natural",
:Keyword = :count,
:Function = func {
if not isattribute(self,:count_times) {
AddAttribute(self,:count_times)
Count_Times = 0
}
if Expr(1) > Expr(2) {
nStep = -1
else
nStep = 1
}
if Count_Times = 0 {
see nl+"The Numbers!" + nl
Count_Times++
else
see nl + "I will count Again!" +nl
}
for x = Expr(1) to Expr(2) step nStep {
see nl+x+nl
}
CommandReturn(fabs(Expr(1)-Expr(2))+1)
}
])
9.4 New Style is added to Ring Notepad
In Ring Notepad - From View - Styles - Select the (Modern) Style
Screen Shot:
9.4. New Style is added to Ring Notepad 136
9. Ring Documentation, Release 1.9
9.5 RingREPL
In the application folder, You will ๏ฌnd RingREPL (Read-Eval-Print-Loop)
Also you can run it from Ring Notepad (Menubar - Tools)
Screen Shot:
9.6 Convert between Numbers and Bytes
Ring 1.4 comes with the next functions to convert between Numbers and Bytes.
โข Int2Bytes()
โข Float2Bytes()
โข Double2Bytes()
โข Bytes2Int()
โข Bytes2Float()
9.5. RingREPL 137
10. Ring Documentation, Release 1.9
โข Bytes2Double()
Example:
see "Test Int2Bytes() and Bytes2Int() - Value : 77" + nl
r = Int2Bytes(77)
see "Int Size : " + len(r) + nl
see r + nl
see Bytes2Int(r) + nl
see "Test Float2Bytes() and Bytes2Float() - Value 77.12" + nl
r = Float2Bytes(77.12)
see "Float Size : " + len(r) + nl
see r + nl
see Bytes2Float(r) + nl
see "Test Double2Bytes() and Bytes2Double() - Value 9999977.12345" + nl
r = Double2Bytes(9999977.12345)
see "Double Size : " + len(r) + nl
see r + nl
decimals(5)
see Bytes2Double(r) + nl
9.7 Better StdLib
The StdLib is updated to include the next functions
โข FSize()
The print() function is updated to accept local variables.
load "stdlib.ring"
func main
print("Enter your name : ") ;
Name = getString() ;
print( "Hello : #{Name} ") ;
return ;
9.8 Better WebLib
The web library is updated
โข Provide better error message
1. Error (WebLib-1) : REQUEST_METHOD is empty ! - Run this script from the browser
2. Error (DataLib-1) : Canโt connect to the database server!
โข Better Template() function - can accept NULL instead of object as the second paramter.
html(template("main.rhtml",NULL))
โข The Form Class is updated to support the โtargetโ attribute.
BootStrapWebPage()
{
Title = "The Ring Programming Language"
html(template("main.rhtml",NULL))
9.7. Better StdLib 138