You are on page 1of 10

Ring Documentation, Release 1.

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 files.
load "stdlib.ring"

6.3 The Natural Library

Ring 1.4 comes with the Natural Library to quickly define a language that contains a group of commands.
We will write the natural code in a Text file, 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!

6.3. The Natural Library 65


Ring Documentation, Release 1.5

I will count Again!

To execute the natural code, We have start.ring


In start.ring we define 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 defined a language called MyLanguage, We have folder for the language commands.
Each command will define a class that belong to the MyLanguage.Natural package.
We will define two commands, Hello and Count.
So we must have two files for defining 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

6.3. The Natural Library 66


Ring Documentation, Release 1.5

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)
}
])

6.4 New Style is added to Ring Notepad

In Ring Notepad - From View - Styles - Select the (Modern) Style


Screen Shot:

6.4. New Style is added to Ring Notepad 67


Ring Documentation, Release 1.5

6.5 RingREPL

In the application folder, You will find RingREPL (Read-Eval-Print-Loop)


Also you can run it from Ring Notepad (Menubar - Tools)
Screen Shot:

6.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()

6.5. RingREPL 68
Ring Documentation, Release 1.5

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

6.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 ;

6.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) : Cant 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))

6.7. Better StdLib 69


Ring Documentation, Release 1.5

div {
classname = :container
div
{
id = "div3"
color = "black"
backgroundcolor = "white"
width = "100%"
form
{
method = "POST"
Action = website
Target = "codeoutput"
input { type="hidden" name="page" value=1 }
Table
{
style = stylewidth("100%") +
stylegradient(3)
TR
{

TD { align="center"
WIDTH="10%"
text("Code :")
}
TD {
html(`
<textarea name = "cCode"
rows="5"
style="width : 100%; ">
See "Hello, World!" + nl
</textarea>`)
}
}
}
Input { type = "submit"
classname="btn btn-primary btn-block"
value = "Execute" }
Table
{
style = stylewidth("100%") +
stylegradient(34)
TR
{

TD { align="center"
WIDTH="10%"
text("Output :")
}
TD {
html(`
<iframe name="codeoutput"
width="100%"
style="background-color:white;">
</iframe>`)
}
}
}

6.8. Better WebLib 70


Ring Documentation, Release 1.5

}
}

}
html(template("footer.rhtml",NULL))
}

6.9 Better RingQt

The next functions are added to RingQt


SetDialogIcon(cIconFile)
MsgInfo(cTitle,cMessage)
ConfirmMsg(cTitle,cMessage)
InputBox(cTitle,cMessage)
InputBoxInt(cTitle,cMessage)
InputBoxNum(cTitle,cMessage)
InputBoxPass(cTitle,cMessage)
The next classes are added to RingQt
QToolButton
QSerialPort
QSerialPortInfo

6.10 Qt Class Convertor

Ring 1.4 comes with a simple tool that help in porting Qt classes to RingQt.
You will find it in ring/samples/tools/QtClassConverter
Online : https://github.com/ring-lang/ring/tree/master/samples/tools/QtClassConverter
Screen Shot:

6.9. Better RingQt 71


Ring Documentation, Release 1.5

6.10. Qt Class Convertor 72


CHAPTER

SEVEN

WHAT IS NEW IN RING 1.3?

In this chapter we will learn about the changes and new features in Ring 1.3 release.

7.1 List of changes and new features

Ring 1.3 comes with many new features


Better RingQt
Better Ring Notepad
Ring mode for Emacs Editor
Better StdLib
Better Loop/Exit Command
New Functions
Return Self by Reference
Using < and : operators as from keyword
Embedding Ring in Ring without sharing the State
RingZip Library
Form Designer

7.2 Better RingQt

(1) Another version of QPixMap class is added (QPixMap2) which takes (int width,int height) during object init.
Example:
Load "guilib.ring"
New qapp
{
win1 = new qwidget()
{
setwindowtitle("Drawing using QPixMap")
setgeometry(100,100,500,500)
label1 = new qlabel(win1)
{
setgeometry(10,10,400,400)
settext("")

73
Ring Documentation, Release 1.5

}
imageStock = new qlabel(win1)
{
image = new qPixMap2(200,200)
color = new qcolor() {
setrgb(255,255,255,255)
}
pen = new qpen() {
setcolor(color)
setwidth(10)
}
new qpainter() {
begin(image)
setpen(pen)
drawline(0,0,200,200)
drawline(200,0,0,200)
endpaint()
}
setpixmap(image)
}
show()
}
exec()
}

Screen Shot:

7.2. Better RingQt 74

You might also like