OSDN Git Service

【更新内容】
[ring-lang-081/ring.git] / docs / en / source / whatisnew4.txt
1 .. index:: 
2         single: What is new in Ring 1.4?; Introduction
3
4 ========================
5 What is new in Ring 1.4?
6 ========================
7
8 In this chapter we will learn about the changes and new features in Ring 1.4 release.
9
10 .. index:: 
11         pair: What is new in Ring 1.4?; List of changes and new features
12
13 List of changes and new features
14 ================================
15
16 Ring 1.4  comes with many new features 
17
18 * Change: Basic Extensions are separated from RingVM
19 * The Natural Library
20 * New Style is added to Ring Notepad
21 * RingREPL
22 * Convert between Numbers and Bytes
23 * Better StdLib
24 * Better WebLib
25 * Better RingQt
26 * Qt Class Convertor
27
28 .. index:: 
29         pair: What is new in Ring 1.4?; Change: Basic Extensions are separated from RingVM
30
31 Change: Basic Extensions are separated from RingVM
32 ==================================================
33
34 In Ring 1.4 the next libraries are separated from RingVM
35
36 * RingODBC
37 * RingMySQL
38 * RingSQLite
39 * RingOpenSSL
40 * RingInternet
41
42 To use these libraries, Use the Load command.
43
44 .. code-block:: none
45
46         load "odbclib.ring"
47         # use ODBC Functions
48
49 .. code-block:: none
50
51         load "mysqllib.ring"
52         # use MySQL Functions
53
54 .. code-block:: none
55
56         load "sqlitelib.ring"
57         # use SQLite Functions
58
59 .. code-block:: none
60
61         load "openssllib.ring"
62         # use OpenSSL Functions  ( Hash and Security functions)
63
64 .. code-block:: none
65
66         load "internetlib.ring"
67         # use Internet Functions ( Download() and SendEmail() )
68
69 If you will use all of these libraries, You can just use stdlib.ring
70 And the stdlib.ring will load odbclib.ring, mysqllib.ring, sqlitelib.ring,
71 opensslib.ring and internetlib.ring files.
72
73 .. code-block:: none
74
75         load "stdlib.ring"
76
77 .. index:: 
78         pair: What is new in Ring 1.4?; The Natural Library
79
80 The Natural Library
81 ===================
82
83 Ring 1.4 comes with the Natural Library to quickly define a language that contains
84 a group of commands.
85
86 We will write the natural code in a Text file, for example program.txt
87
88 File: program.txt
89
90 .. code-block:: none
91
92         Welcome to the Ring programming language!
93         What you are reading now is not comments, I swear!
94
95         After many years of programming I decided to think different about
96         programming and solve the problems in a better way. 
97
98         We are writing commands or code and the Ring language is reading
99         it to understand us! Sure, What you are seeing now is
100         just ***part of the code - Not the Complete Program***
101         You have to write little things before and after this 
102         part to be able to run it!
103
104         It is the natural part of our code where we can write in English, 
105         Arabic or any Natural Language Then we will tell the computer 
106         through the Ring language what must happens! in a way that we can scale 
107         for large frameworks and programs.
108
109         Just imagine what will happens to the world of programming once
110         we create many powerful frameworks using the Ring language that
111         uses this way (Natural Programming).
112
113         For example When we say Hello to the Machine, It can reply! and when we
114         say count from 1 to 5 it will understand us, Also if 
115         we said count from 5 to 1 it will
116         understand us too! You can see the Output window!
117
118         This Goal is not new, but the Ring language comes
119         with an innovative solution to this problem.    
120
121 Output:
122
123 .. code-block:: none
124
125         Hello, Sir!
126
127
128         The Numbers!
129
130         1
131
132         2
133
134         3
135
136         4
137
138         5
139
140         I will count Again!
141
142         5
143
144         4
145
146         3
147
148         2
149
150         1
151
152
153 To execute the natural code, We have start.ring
154
155 In start.ring we define the language and the commands.
156
157 File: start.ring
158
159 .. code-block:: ring
160
161         load "stdlib.ring"
162         load "naturallib.ring"
163
164         New NaturalLanguage {
165                 SetLanguageName(:MyLanguage)
166                 SetCommandsPath(CurrentDir()+"/../command")
167                 SetPackageName("MyLanguage.Natural")
168                 UseCommand(:Hello)
169                 UseCommand(:Count)
170                 RunFile("program.txt")
171         }
172
173
174 We defined a language called MyLanguage, We have folder for the language commands.
175
176 Each command will define a class that belong to the MyLanguage.Natural package.
177
178 We will define two commands, Hello and Count.
179
180 So we must have two files for defining the commands in the CurrentDir()+"/../command" folder
181
182 File: hello.ring
183
184 .. code-block:: ring
185
186         DefineNaturalCommand.SyntaxIsKeyword([
187                 :Package = "MyLanguage.Natural",
188                 :Keyword = :hello, 
189                 :Function = func {
190                         See  "Hello, Sir!" + nl + nl
191                 }
192         ])
193
194 File: count.ring
195
196 .. code-block:: ring
197
198         DefineNaturalCommand.SyntaxIsKeywordNumberNumber([
199                 :Package = "MyLanguage.Natural",
200                 :Keyword = :count, 
201                 :Function = func {
202                         if not isattribute(self,:count_times) {
203                                 AddAttribute(self,:count_times)
204                                 Count_Times = 0
205                         }
206                         if Expr(1) > Expr(2) { 
207                                 nStep = -1 
208                         else 
209                                 nStep = 1
210                         }
211                         if Count_Times = 0 { 
212                                 see nl+"The Numbers!" + nl 
213                                 Count_Times++
214                         else 
215                                 see nl + "I will count Again!" +nl 
216                         }
217                         for x = Expr(1) to Expr(2) step nStep {
218                                 see nl+x+nl 
219                         }
220                         CommandReturn(fabs(Expr(1)-Expr(2))+1)                          
221                 }
222         ])
223
224
225
226 .. index:: 
227         pair: What is new in Ring 1.4?; New Style to Ring Notepad
228
229 New Style is added to Ring Notepad
230 ==================================
231
232 In Ring Notepad - From View - Styles - Select the (Modern) Style
233
234 Screen Shot:
235
236 .. image:: rnotemodernstyle.png
237         :alt: Using Ring Notepad - Modern Style
238
239 .. index:: 
240         pair: What is new in Ring 1.4?; RingREPL
241
242 RingREPL
243 ========
244
245 In the application folder, You will find RingREPL (Read-Eval-Print-Loop)
246
247 Also you can run it from Ring Notepad (Menubar - Tools)
248
249 Screen Shot:
250
251 .. image:: ringrepl.png
252         :alt: Using RingREPL
253
254 .. index:: 
255         pair: What is new in Ring 1.4?; Convert between Numbers and Bytes
256
257 Convert between Numbers and Bytes
258 =================================
259
260 Ring 1.4 comes with the next functions to convert between Numbers and Bytes.
261
262 * Int2Bytes()
263 * Float2Bytes()
264 * Double2Bytes()
265 * Bytes2Int()
266 * Bytes2Float()
267 * Bytes2Double()
268
269 Example:
270
271 .. code-block:: ring
272
273         see "Test Int2Bytes() and Bytes2Int() - Value : 77" + nl
274         r = Int2Bytes(77)
275         see "Int Size : " + len(r) + nl
276         see r + nl
277         see Bytes2Int(r) + nl
278         see "Test Float2Bytes() and Bytes2Float() - Value 77.12" + nl
279         r = Float2Bytes(77.12)
280         see "Float Size : " + len(r) + nl
281         see r + nl
282         see Bytes2Float(r) + nl
283         see "Test Double2Bytes() and Bytes2Double() - Value 9999977.12345" + nl
284         r = Double2Bytes(9999977.12345)
285         see "Double Size : " + len(r) + nl
286         see r + nl
287         decimals(5)
288         see Bytes2Double(r) + nl
289
290
291 .. index:: 
292         pair: What is new in Ring 1.4?; Better StdLib
293
294 Better StdLib
295 =============
296
297 The StdLib is updated to include the next functions
298
299 * FSize()
300
301 The print() function is updated to accept local variables.
302
303 .. code-block:: ring
304
305         load "stdlib.ring" 
306
307         func main 
308                 print("Enter your name : ")     ;
309                 Name = getString()              ;
310                 print( "Hello : #{Name} ")      ;
311                 return                          ;
312
313
314 .. index:: 
315         pair: What is new in Ring 1.4?; Better WebLib
316
317 Better WebLib
318 =============
319
320 The web library is updated 
321
322 * Provide better error message
323
324 (1) Error (WebLib-1) : REQUEST_METHOD is empty ! - Run this script from the browser
325
326 (2) Error (DataLib-1) : Can't connect to the database server!
327
328 * Better Template() function - can accept NULL instead of object as the second paramter.
329
330 .. code-block:: ring
331
332         html(template("main.rhtml",NULL))
333
334 * The Form Class is updated to support the "target" attribute.
335
336 .. code-block:: ring
337
338         BootStrapWebPage() 
339         {
340                 Title = "The Ring Programming Language"
341                 html(template("main.rhtml",NULL))
342                 div {
343                         classname = :container
344                         div
345                         {
346                                 id = "div3"
347                                 color = "black"
348                                 backgroundcolor = "white"
349                                 width = "100%"
350                                 form
351                                 {
352                                         method = "POST"
353                                         Action = website  
354                                         Target = "codeoutput"
355                                         input { type="hidden" name="page" value=1 }
356                                         Table
357                                         { 
358                                                 style = stylewidth("100%") +
359                                                         stylegradient(3)                        
360                                                 TR
361                                                 {
362                                         
363                                                         TD { align="center" 
364                                                                 WIDTH="10%"
365                                                                  text("Code :") 
366                                                         }
367                                                         TD {
368                                                                 html(`
369                                                                 <textarea name = "cCode" 
370                                                                 rows="5" 
371                                                                 style="width : 100%; ">
372                                                                 See "Hello, World!" + nl
373                                                                 </textarea>`)
374                                                         }
375                                                 }
376                                         }
377                                         Input { type = "submit" 
378                                                 classname="btn btn-primary btn-block" 
379                                                         value = "Execute" }
380                                         Table
381                                         { 
382                                                 style = stylewidth("100%") +
383                                                         stylegradient(34)                       
384                                                 TR
385                                                 {
386                                         
387                                                         TD { align="center"
388                                                                 WIDTH="10%" 
389                                                                 text("Output :") 
390                                                         }
391                                                         TD {
392                                                         html(`
393                                                         <iframe name="codeoutput" 
394                                                         width="100%" 
395                                                         style="background-color:white;">
396                                                         </iframe>`)
397                                                         }
398                                                 }
399                                         }
400
401                                 }
402                         }
403
404                 }
405                 html(template("footer.rhtml",NULL))
406         }
407
408
409 .. index:: 
410         pair: What is new in Ring 1.4?; Better RingQt
411
412 Better RingQt
413 =============
414
415 The next functions are added to RingQt
416
417 * SetDialogIcon(cIconFile)
418 * MsgInfo(cTitle,cMessage)
419 * ConfirmMsg(cTitle,cMessage)
420 * InputBox(cTitle,cMessage)
421 * InputBoxInt(cTitle,cMessage)
422 * InputBoxNum(cTitle,cMessage)
423 * InputBoxPass(cTitle,cMessage)
424
425 The next classes are added to RingQt
426
427 * QToolButton
428 * QSerialPort
429 * QSerialPortInfo
430
431 .. index:: 
432         pair: What is new in Ring 1.4?; Qt Class Convertor
433
434 Qt Class Convertor
435 ==================
436
437 Ring 1.4 comes with a simple tool that help in porting Qt classes to RingQt.
438
439 You will find it in ring/samples/tools/QtClassConverter
440
441 Online : https://github.com/ring-lang/ring/tree/master/samples/tools/QtClassConverter
442
443 Screen Shot: 
444
445 .. image:: qtclassconvertor.png
446         :alt: Qt Class convertor to RingQt
447
448 .. index:: 
449         pair: What is new in Ring 1.4?; What is new in Ring 1.4.1?
450
451
452 What is new in Ring 1.4.1?
453 ==========================
454
455 Ring 1.4.1  comes with the next changes
456
457 * Better Scripts for Building from Source Code
458 * Better Colors for the Modern Style in Ring Notepad
459 * Better StdLib
460 * Better RingQt
461 * New Sample : Sixteen Puzzle
462
463 The scripts are updated for building from source code.
464
465 Tested using Windows, Ubuntu Linux, Linux Mint and MacOS X.
466
467 Screen Shot:
468
469 .. image:: linuxmint.png
470         :alt: Using Ring - Linux Mint
471
472 In Ring Notepad - the (Modern) Style colors are updated
473
474 Screen Shot:
475
476 .. image:: rnotemodernstyle2.png
477         :alt: Using Ring Notepad - Modern Style
478
479 The StdLib is updated to include the next functions
480
481 * TrimLeft()
482 * TrimRight()
483 * TrimAll()
484 * EpochTime()
485
486 The next functions are updated to display the dialogs on the top of other windows.
487
488 * SetDialogIcon(cIconFile)
489 * MsgInfo(cTitle,cMessage)
490 * ConfirmMsg(cTitle,cMessage)
491 * InputBox(cTitle,cMessage)
492 * InputBoxInt(cTitle,cMessage)
493 * InputBoxNum(cTitle,cMessage)
494 * InputBoxPass(cTitle,cMessage)
495
496 The Sixteen Puzzle is added to the Applications folder.
497
498 Screen Shot:
499
500 .. image:: sixteenpuzzle.jpg
501         :alt: Sixteen Puzzle