Ring 1.4 の変更履歴

Ring 1.4 公開版の新機能と変更点を学びます。

新機能と変更リスト

Ring 1.4 の新機能!

  • 変更: 基本拡張機能を Ring VM から分離
  • 自然言語ライブラリ
  • Ring ノートパッドへ新しいスタイルを追加
  • RingREPL
  • 数値とバイト間の変換
  • StdLib の改良
  • WebLib の改良
  • RingQt の改良
  • Qt クラスコンバーター

変更: 基本拡張機能を Ring VM から分離

Ring 1.4 では、このライブラリが Ring VM から分離されました。

  • RingODBC
  • RingMySQL
  • RingSQLite
  • RingOpenSSL
  • RingInternet

下記のライブラリは Load 命令で使用可能になります。

load "odbclib.ring"
# ODBC 関数
load "mysqllib.ring"
# MySQL 関数
load "sqlitelib.ring"
# SQLite 関数
load "openssllib.ring"
# OpenSSL 関数  (ハッシュとセキュリティ関数)
load "internetlib.ring"
# インターネット関数 ( Download() と SendEmail() )

上記のライブラリを全て使う場合、 stdlib.ring を指定することにより odbclib.ring, mysqllib.ring, sqlitelib.ring, opensslib.ring そして internetlib.ring ファイルを読み込みます。

load "stdlib.ring"

自然言語ライブラリ

Ring 1.4 では命令グループがある言語を手軽に定義するために、 自然言語ライブラリがあります。

例えば、テキストファイル program.txt に自然言語コードを記述します。

ファイル: 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.

実行結果:

Hello, Sir!


The Numbers!

1

2

3

4

5

I will count Again!

5

4

3

2

1

自然言語コードを実行するには、 start.ring を実行します。

start.ring には言語と命令が定義されています。

ファイル: 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")
}

これで MyLanguage 言語名は定義済みになり、言語命令用のフォルダが指定されます。

命令ごとに MyLanguage.Natural パッケージへ所属するクラスを定義します。

Hello および Count を命令として二つ定義します。

したがって、命令を定義するために CurrentDir()+”/../command” フォルダには二つのファイルが必要です。

ファイル: hello.ring

DefineNaturalCommand.SyntaxIsKeyword([
        :Package = "MyLanguage.Natural",
        :Keyword = :hello,
        :Function = func {
                See  "Hello, Sir!" + nl + nl
        }
])

ファイル: count.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)
        }
])

Ring ノートパッドへ新しいスタイルを追加

Ring ノートパッドへ表示 - スタイル - モダンスタイルの選択を追加しました。

スクリーンショット:

Ring ノートパッドの用法 - モダンスタイル

RingREPL

application フォルダには、 RingREPL (Read-Eval-Print-Loop) があります。

Ring ノートパッド (メニューバー - ツール) からも実行できます。

スクリーンショット:

RingREPL の用法

数値とバイト間の変換

Ring 1.4 では、数値とバイト間の変換をするために、下記の関数があります。

  • Int2Bytes()
  • Float2Bytes()
  • Double2Bytes()
  • Bytes2Int()
  • Bytes2Float()
  • Bytes2Double()

用例:

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

StdLib の改良

StdLib に関数を実装するために FSize() 関数を更新しました。

print() 関数でローカル変数を受け入れられるように更新しました。

load "stdlib.ring"

func main
        print("Enter your name : ")     ;
        Name = getString()              ;
        print( "Hello : #{Name} ")      ;
        return                          ;

WebLib の改良

WebLib を更新しました

  • エラーメッセージの実装
  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!
  • Template() 関数の改良 - 第二仮引数でオブジェクトの代わりに NULL を受け入れることができるようになりました。
html(template("main.rhtml",NULL))
  • “target”属性への対応のために Form クラスを更新
BootStrapWebPage()
{
        Title = "The Ring Programming Language"
        html(template("main.rhtml",NULL))
        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>`)
                                                }
                                        }
                                }

                        }
                }

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

RingQt の改良

この関数を RingQt へ追加

  • SetDialogIcon(cIconFile)
  • MsgInfo(cTitle,cMessage)
  • ConfirmMsg(cTitle,cMessage)
  • InputBox(cTitle,cMessage)
  • InputBoxInt(cTitle,cMessage)
  • InputBoxNum(cTitle,cMessage)
  • InputBoxPass(cTitle,cMessage)

このクラスを RingQt へ追加

  • QToolButton
  • QSerialPort
  • QSerialPortInfo

Qt クラスコンバーター

Ring 1.4 は Qt クラスを RingQt への移植するための補助ツールがあります。

ring/samples/tools/QtClassConverter にあります。

オンライン : https://github.com/ring-lang/ring/tree/master/samples/tools/QtClassConverter

スクリーンショット:

RingQt 移植補助用 Qt クラスコンバーター

Ring 1.4.1 の変更履歴

このような変更点が Ring 1.4.1 にあります。

  • ソースコードからのビルドに使用するスクリプトの改良
  • Ring ノートパッドの Modern Style の配色を改善
  • StdLib の改良
  • RingQt の改良
  • 新しいサンプル : Sixteen Puzzle

ソースコードからのビルドで使用するスクリプトの更新

Windows, Ubuntu Linux, Linux Mint および macOS で動作確認を行いました。

スクリーンショット:

Linux Mint で Ring を使用

Ring ノートパッドでは - モダンスタイルの配色を更新

スクリーンショット:

Ring ノートパッドの使用 - モダンスタイル

StdLib オブジェクトライブラリへ関数を実装しました。

  • TrimLeft()
  • TrimRight()
  • TrimAll()
  • EpochTime()

この関数はウィンドウの前面にダイアログを表示するために更新しました。

  • SetDialogIcon(cIconFile)
  • MsgInfo(cTitle,cMessage)
  • ConfirmMsg(cTitle,cMessage)
  • InputBox(cTitle,cMessage)
  • InputBoxInt(cTitle,cMessage)
  • InputBoxNum(cTitle,cMessage)
  • InputBoxPass(cTitle,cMessage)

Applications フォルダへ Sixteen Puzzle を追加しました。

スクリーンショット:

Sixteen Puzzle