Update Documentation - Natural Library - Demo Program.
@@ -25,3 +25,103 @@ next methods :-
* RunFile(cFileName)
* RunString(cString)
+.. index::
+ pair: Using the Natural Library; Natural Library - Demo Program
+
+Natural Library - Demo Program
+==============================
+
+We will write the natural code in a Text file, for example program.txt
+
+.. code-block:: none
+
+ 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.
+
+
+To execute the natural code, We have start.ring
+
+In start.ring we define the language and the commands.
+
+.. code-block:: 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
+
+Hello.ring
+
+.. code-block:: ring
+
+ DefineNaturalCommand.SyntaxIsKeyword([
+ :Package = "MyLanguage.Natural",
+ :Keyword = :hello,
+ :Function = func {
+ See "Hello, Sire!" + nl + nl
+ }
+ ])
+
+Count.ring
+
+.. code-block:: ring
+
+ 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)
+ }
+ ])
