Click here to Skip to main content
13,662,003 members
Click here to Skip to main content
Add your own
alternative version

Stats

3.6K views
15 downloads
Posted 28 Dec 2017
Licenced CPOL

Different styles for writing Hello World program in the Ring programming language

, 28 Dec 2017
Rate this:
Please Sign up or sign in to vote.
A quick look around the different styles in the Ring programming language!

 

Introduction

When we look at a new programming language, we start with the "Hello, World!" program. In Ring we can write this simple program with different styles that reflect the general scope of the language! The language documentation comes with three styles in the begining, In this article I will try to present all of the styles that we can use after learning the different aspects of the language!

Background

The Ring programming language is a dynamic programming language for Windows, Linux and macOS. Very similar to Python and Ruby, but brings a lot of features from BASIC too!, The new ideas in the language are related to domain-specific languages and using declarative and natural programming. It's free open source language.

Scripting

In Ring 1.0

(1)

see "Hello, World!"

(2) Using nl we can print new line!

see "Hello, World" + nl

(3) The language is not case-sensitive!

SEE "Hello, World!"

(4) Using nl we can print new line!

SEE "Hello, World" + nl

(5)

See "Hello, World!"

(6) Using nl we can print new line!

See "Hello, World" + nl

In Ring 1.1

(7)

put "Hello, World!"

(8)

put "Hello, World!" + nl

(9)

PUT "Hello, World!"

(10)

PUT "Hello, World!" + nl

(11)

Put "Hello, World!"

(12)

Put "Hello, World!" + nl

(13) Using the Standard Library "stdlib.ring"

load "stdlib.ring"
print("Hello, World!")

(14) Using the Standard Library "stdlib.ring" and \n for new lines!

load "stdlib.ring"
print("Hello, World!\n")

(15)

LOAD "stdlib.ring"
PRINT("Hello, World!")

(16)

LOAD "stdlib.ring"
PRINT("Hello, World!\n")

(17)

Load "stdlib.ring"
Print("Hello, World!")

(18)

Load "stdlib.ring"
Print("Hello, World!\n")

(19) In Ring 1.6 we can use ? as see <expr> + nl

? "Hello, World!"

(20) We can write multiline strings

? "
    Hello, World!
"

Procedural

We can use functions|procedures, the main function will be executed in the start of the program.

(1) First Style

func main
   see "Hello, World!"

(2) Second Style

def main
   put "Hello, World!"
end

(3) Third Style

load "stdlib.ring"
func main() {
    print("Hello, World!") 
}

Classes

We can define a class, then create an object for this class!

(1) First Style

new MyApp { main() }
class MyApp
   func main
      see "Hello, World!"

(2) Second Style

new MyApp { main() }
class MyApp
   def main
      put "Hello, World!"
   end 
end

(3) Third Style

load "stdlib.ring"
new MyApp { main() }
class MyApp {
   func main() {
       print("Hello, World!") 
   }
}

Web

The web library can be used from weblib.ring

We have the package System.web

This packages contains many classes that we can use for web development.

#!ring -cgi 
load "weblib.ring" 
import System.Web 
new page { 
	text("Hello, World!") 
}

Games

Games are based on Allegro and LibSDL

To use these libraries through the game engine, We have gameengine.ring

load "gameengine.ring" 
func main    
	oGame = new game {
    		title = "Hello, World!"    
	}

GUI (Desktop|Mobile) - using Qt

Desktop and mobile development are based on the Qt framework

To use this framework we will load the guilib.ring

load "guilib.ring" 
new qApp { 
	new qWidget() { 
		setwindowtitle("Hello World") 
		move(100,100) resize(400,400) 
		show() 
	}
	exec() 
} 

Natural

We can define new statments in the language, then use classes to implement our definition

The next example define Hello World as a new command!

new natural {
      Hello World
}
class natural 
         hello world
         func getHello ? "Hello"
         func getWorld ? "World!"

Points of Interest

Pros:

(1) Different styles that match programmers with different backgrounds

(2) The language could be used in different domains

Cons:

(1) All of these styles could be mixed in the same project!

(2) The language still new, A lot of libraries need more work!

History

Ring is a new programming language (just released in 2016)

The current version is Ring 1.6 (free open source - MIT License)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rubin Liu
Software Developer (Senior)
China China
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180810.1 | Last Updated 28 Dec 2017
Article Copyright 2017 by Rubin Liu
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid