SlideShare a Scribd company logo
Ring Documentation, Release 1.9
translation to other languages like Arabic, French and so on.
Tip: The effect of LoadSyntax command is related to the current source code ïŹle only.
71.4 Using “()” around the function parameters
We can use () around the function parameters (optional).
Example:
hello()
sum(3,4)
func hello()
see "Hello" + nl
func sum(x,y)
see x+y+nl
Output:
Hello
7
Example:
myfunc = func x,y { see x + y + nl }
call myfunc (3,4)
myfunc2 = func (x,y) { see x+y+nl }
call myfunc(3,4)
Output:
7
7
71.5 Using Semi-colon after and between statements
In Ring we can use semi-colon after and between statements (optional).
Example:
# Using semi-colon is optional
see "Hello" + nl ; see "How are you?" + nl ; see "Welcome to Ring" + nl ;
one() ; two() ; three() ;
func one ; see "one" + nl ;
func two ; see "two" + nl ;
func three ; see "three" + nl ;
Output:
71.4. Using “()” around the function parameters 819
Ring Documentation, Release 1.9
Hello
How are you?
Welcome to Ring
one
two
three
71.6 Using $ and @ in the start of the variable name
You can use any unicode character in the variable name also we can use $ and @ in the name.
This feature may help, for example we can start global variables with $ and the object attributes with @.
In other languages like Ruby this is the rule, In the Ring language this is just an option without any force from the
Compiler.
example:
$global_variable = 5
new test { hello() }
class test
@instance_variable = 10
func hello
local_variable = 15
see "Global : " + $global_variable + nl +
"Instance : " + @instance_variable + nl +
"Local : " + local_variable + nl
Output:
Global : 5
Instance : 10
Local : 15
71.7 Using the ‘elseif’ keyword as ‘but’ in if statement
if you don’t like the ‘but’ keyword in if statement Then you can use the ‘elseif’ keyword.
Example:
give x
if x = 1 see "one"
elseif x=2 see "two"
elseif x=3 see "three"
elseif x=4 see "four"
else see "other"
ok
see nl
71.6. Using $ and @ in the start of the variable name 820
Ring Documentation, Release 1.9
71.8 Using the ‘else’ keyword as ‘other’ in switch statement
if you don’t like the ‘other’ keyword in switch statement Then you can use the ‘else’ keyword.
Also you can replace ‘else’ with ‘other’ in if statement.
i.e. ‘other’ keyword is the same as ‘else’ keyword.
Example:
x = 1
switch x
on 10
see "10" + nl
else
see "not 10" + nl
end
Output:
not 10
71.9 Using the ‘end’ keyword in different control structures
We can use the ‘end’ keyword to close different control structures
‱ If statement
‱ For loop
‱ Switch
‱ While
‱ Try-Catch
Example:
see "if statement.." + nl
x = 1
if x = 1
see "one" + nl
elseif x=2
see "two" + nl
elseif x=3
see "three" + nl
end
see "for loop.." + nl
for t = 1 to 10
see t
end
see nl
see "switch..." + nl
x = 1
switch x
on 1 see "one" + nl
on 2 see "two" + nl
end
71.8. Using the ‘else’ keyword as ‘other’ in switch statement 821
Ring Documentation, Release 1.9
see "try catch..." + nl
try
x = 1 / 0
catch
see "catching error" + nl
end
Output:
if statement..
one
for loop..
12345678910
switch...
one
try catch...
catching error
71.10 Using braces to start and end different control structures
We can use braces { } to start and end different control structures
‱ If statement
‱ For loop
‱ Switch
‱ While
‱ Try-Catch
Example:
see "if statement.." + nl
x = 1
if x = 1 {
see "one" + nl
elseif x=2
see "two" + nl
elseif x=3
see "three" + nl
}
see "for loop.." + nl
for t = 1 to 10 {
see t
}
see nl
see "switch..." + nl
x = 1
switch x {
on 1 see "one" + nl
on 2 see "two" + nl
}
see "try catch..." + nl
try {
71.10. Using braces to start and end different control structures 822
Ring Documentation, Release 1.9
x = 1 / 0
catch
see "catching error" + nl
}
Output:
if statement..
one
for loop..
12345678910
switch...
one
try catch...
catching error
71.11 Using ‘put’ and ‘get’ as ‘see’ and ‘give’
We can replace the ‘see’ keyword with the ‘put’ keyword.
Also we can replacew the ‘give’ keyword with the ‘get’ keyword.
Example:
put "Hello World" + nl
put "Enter Your Name ? " Get Name
Put "Hello " + Name
71.12 Using ‘case’ as ‘on’ in switch statements
We can replace the ‘on’ keyword with ‘case’ keyword in the switch statement.
Example (1) :
for x=1 to 10
switch x
case 1 put "one" + nl
case 2 put "two" + nl
case 3 put "thre" + nl
else put "else" + nl
end
end
Example (2) :
for x=1 to 10 {
switch x {
case 1 put "one" + nl
case 2 put "two" + nl
case 3 put "thre" + nl
else put "else" + nl
}
}
71.11. Using ‘put’ and ‘get’ as ‘see’ and ‘give’ 823
Ring Documentation, Release 1.9
71.13 Using ‘def’ as ‘func’ in functions/methods deïŹnition
We can use the ‘def’ keyword as the ‘func’ keyword to deïŹne functions and methods.
Example:
one() two()
def one put "one" + nl
def two put "two" + nl
71.14 Using braces { } in Packages/Classes/Functions
Example:
load "stdlib.ring"
import mypackage
new myclass {
myfunc()
}
package mypackage
{
class myclass
{
func myfunc
{
print("Hello, World!n")
}
}
}
71.15 Using ‘end’ keyword after Packages/Classes/Functions
Example:
import mypackage
new myclass {
myfunc()
}
package mypackage
class myclass
def myfunc
put "Hello, World!"
end
end
end
71.13. Using ‘def’ as ‘func’ in functions/methods deïŹnition 824
Ring Documentation, Release 1.9
71.16 Using ‘endpackage’/’endclass’/’endfunc’ keywords after Pack-
ages/Classes/Functions
Example:
import mypackage
new myclass { myfunc() }
package mypackage
class myclass
func myfunc
see "welcome" + nl
endfunc
endclass
endpackage
71.17 Ignore new lines after keywords
Starting from Ring 1.8 the compiler will ignore new lines after keywords that expect tokens after it
Example:
see
"
Hello, World!
"
test()
func
#======================#
Test
#======================#
?
"
Hello from the Test function
"
Output:
Hello, World!
Hello from the Test function
71.16. Using ‘endpackage’/’endclass’/’endfunc’ keywords after Packages/Classes/Functions 825
CHAPTER
SEVENTYTWO
INTRODUCTION TO THE TYPE HINTS LIBRARY
In this chapter we will learn about the Type Hints Library
72.1 Why Type Hints?
Using this library we can add the type information to the source code which will be very useful for tools like
‱ Code Editors
‱ Static-Analysis
Note: Ring is a dynamic language, No type checking will be done by the compiler.
72.2 Example
The next example will use the Type Hints library
load "typehints.ring"
see sum(3,4) + nl ;
see sayHello("Mahmoud");
int func sum(int x,int y) {
return x+y ;
}
string func sayHello(string name) {
return "Hello " + name ;
}
72.3 User Types
The Type Hints library is very powerful and will support user types (Classes) automatically
Example:
load "typehints.ring"
import mypackage
826
Ring Documentation, Release 1.9
test() { main([:one,:two,:three]) }
myclass func test() {
see "Testing User Types!" + nl
return new myclass
}
package mypackage {
public class myclass {
public static void func main(list args) {
see "welcome" + nl
see args
}
}
}
72.4 Using Types inside Code
Also you can use the types inside the code (not only the function prototype)
Example:
load "typehints.ring"
int sum = sum(3,4)
string msg = sayHello("Mahmoud")
see "Sum = " + sum + nl + msg + nl
int func sum(int x,int y) {
return x+y ;
}
string func sayHello(string name) {
return "Hello " + name ;
}
72.5 Rules
‱ To use the types in the function prototype you must use ‘(‘ and ‘)’ around parameters
‱ To use the types in the function code, You must set the variable value (Assignment).
The next types are deïŹned by the library
# Low Level Types
char
unsigned
signed
int
short
long
float
72.4. Using Types inside Code 827
Ring Documentation, Release 1.9
double
void
# High Level Types
string
list
number
object
# Other
public
static
abstract
protected
override
72.5. Rules 828

More Related Content

PDF
The Ring programming language version 1.5.1 book - Part 71 of 180
PDF
The Ring programming language version 1.5.2 book - Part 72 of 181
PDF
The Ring programming language version 1.10 book - Part 87 of 212
PDF
The Ring programming language version 1.3 book - Part 57 of 88
PDF
The Ring programming language version 1.8 book - Part 82 of 202
PDF
The Ring programming language version 1.7 book - Part 79 of 196
PDF
The Ring programming language version 1.5.3 book - Part 84 of 184
PDF
The Ring programming language version 1.2 book - Part 54 of 84
The Ring programming language version 1.5.1 book - Part 71 of 180
The Ring programming language version 1.5.2 book - Part 72 of 181
The Ring programming language version 1.10 book - Part 87 of 212
The Ring programming language version 1.3 book - Part 57 of 88
The Ring programming language version 1.8 book - Part 82 of 202
The Ring programming language version 1.7 book - Part 79 of 196
The Ring programming language version 1.5.3 book - Part 84 of 184
The Ring programming language version 1.2 book - Part 54 of 84

What's hot (20)

PDF
Lecture 4
PPTX
C++ Lambda and concurrency
PDF
PhpUnit - The most unknown Parts
PDF
C++ course start
PPTX
Groovy closures
PDF
Java Cheat Sheet
PPTX
Lexical environment in ecma 262 5
PDF
Generics and Inference
PDF
The Ring programming language version 1.8 book - Part 18 of 202
PDF
Ruby tricks2
PDF
The Ring programming language version 1.5.1 book - Part 74 of 180
PDF
The Ring programming language version 1.9 book - Part 20 of 210
PDF
The Ring programming language version 1.5.3 book - Part 14 of 184
KEY
Workshop unittesting
PPTX
Ensure code quality with vs2012
PDF
The Ring programming language version 1.5.1 book - Part 19 of 180
PDF
Deferred
PDF
Letswift Swift 3.0
PDF
G*ă«ăŠă‘ă‚‹ă‚œăƒ•ăƒˆă‚Šă‚§ă‚ąăƒ†ă‚čăƒˆăƒ»ă‚·ăƒŒă‚șンIII
PDF
The Ring programming language version 1.4 book - Part 5 of 30
Lecture 4
C++ Lambda and concurrency
PhpUnit - The most unknown Parts
C++ course start
Groovy closures
Java Cheat Sheet
Lexical environment in ecma 262 5
Generics and Inference
The Ring programming language version 1.8 book - Part 18 of 202
Ruby tricks2
The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.9 book - Part 20 of 210
The Ring programming language version 1.5.3 book - Part 14 of 184
Workshop unittesting
Ensure code quality with vs2012
The Ring programming language version 1.5.1 book - Part 19 of 180
Deferred
Letswift Swift 3.0
G*ă«ăŠă‘ă‚‹ă‚œăƒ•ăƒˆă‚Šă‚§ă‚ąăƒ†ă‚čăƒˆăƒ»ă‚·ăƒŒă‚șンIII
The Ring programming language version 1.4 book - Part 5 of 30
Ad

Similar to The Ring programming language version 1.9 book - Part 86 of 210 (20)

PDF
The Ring programming language version 1.6 book - Part 77 of 189
PDF
The Ring programming language version 1.5.4 book - Part 75 of 185
PDF
The Ring programming language version 1.5.3 book - Part 85 of 184
PDF
The Ring programming language version 1.9 book - Part 7 of 210
PDF
The Ring programming language version 1.5.2 book - Part 19 of 181
PDF
The Ring programming language version 1.5.2 book - Part 6 of 181
PDF
The Ring programming language version 1.8 book - Part 7 of 202
PDF
The Ring programming language version 1.10 book - Part 7 of 212
PDF
The Ring programming language version 1.5.1 book - Part 5 of 180
PDF
The Ring programming language version 1.10 book - Part 28 of 212
PDF
The Ring programming language version 1.5.4 book - Part 6 of 185
PDF
The Ring programming language version 1.7 book - Part 7 of 196
PDF
The Ring programming language version 1.5.4 book - Part 20 of 185
PDF
The Ring programming language version 1.7 book - Part 23 of 196
PDF
The Ring programming language version 1.5.3 book - Part 6 of 184
PDF
The Ring programming language version 1.5.3 book - Part 20 of 184
PDF
The Ring programming language version 1.9 book - Part 26 of 210
PDF
The Ring programming language version 1.3 book - Part 12 of 88
PDF
The Ring programming language version 1.5.1 book - Part 18 of 180
PDF
The Ring programming language version 1.5.1 book - Part 13 of 180
The Ring programming language version 1.6 book - Part 77 of 189
The Ring programming language version 1.5.4 book - Part 75 of 185
The Ring programming language version 1.5.3 book - Part 85 of 184
The Ring programming language version 1.9 book - Part 7 of 210
The Ring programming language version 1.5.2 book - Part 19 of 181
The Ring programming language version 1.5.2 book - Part 6 of 181
The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.10 book - Part 7 of 212
The Ring programming language version 1.5.1 book - Part 5 of 180
The Ring programming language version 1.10 book - Part 28 of 212
The Ring programming language version 1.5.4 book - Part 6 of 185
The Ring programming language version 1.7 book - Part 7 of 196
The Ring programming language version 1.5.4 book - Part 20 of 185
The Ring programming language version 1.7 book - Part 23 of 196
The Ring programming language version 1.5.3 book - Part 6 of 184
The Ring programming language version 1.5.3 book - Part 20 of 184
The Ring programming language version 1.9 book - Part 26 of 210
The Ring programming language version 1.3 book - Part 12 of 88
The Ring programming language version 1.5.1 book - Part 18 of 180
The Ring programming language version 1.5.1 book - Part 13 of 180
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
PDF
The Ring programming language version 1.10 book - Part 211 of 212
PDF
The Ring programming language version 1.10 book - Part 210 of 212
PDF
The Ring programming language version 1.10 book - Part 208 of 212
PDF
The Ring programming language version 1.10 book - Part 207 of 212
PDF
The Ring programming language version 1.10 book - Part 205 of 212
PDF
The Ring programming language version 1.10 book - Part 206 of 212
PDF
The Ring programming language version 1.10 book - Part 204 of 212
PDF
The Ring programming language version 1.10 book - Part 203 of 212
PDF
The Ring programming language version 1.10 book - Part 202 of 212
PDF
The Ring programming language version 1.10 book - Part 201 of 212
PDF
The Ring programming language version 1.10 book - Part 200 of 212
PDF
The Ring programming language version 1.10 book - Part 199 of 212
PDF
The Ring programming language version 1.10 book - Part 198 of 212
PDF
The Ring programming language version 1.10 book - Part 197 of 212
PDF
The Ring programming language version 1.10 book - Part 196 of 212
PDF
The Ring programming language version 1.10 book - Part 195 of 212
PDF
The Ring programming language version 1.10 book - Part 194 of 212
PDF
The Ring programming language version 1.10 book - Part 193 of 212
PDF
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 192 of 212

Recently uploaded (20)

PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
AI in Product Development-omnex systems
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
Digital Strategies for Manufacturing Companies
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Transform Your Business with a Software ERP System
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Adobe Illustrator 28.6 Crack My Vision of Vector Design
How to Choose the Right IT Partner for Your Business in Malaysia
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
AI in Product Development-omnex systems
CHAPTER 2 - PM Management and IT Context
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
VVF-Customer-Presentation2025-Ver1.9.pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
How Creative Agencies Leverage Project Management Software.pdf
ai tools demonstartion for schools and inter college
Digital Strategies for Manufacturing Companies
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Softaken Excel to vCard Converter Software.pdf
Transform Your Business with a Software ERP System
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025

The Ring programming language version 1.9 book - Part 86 of 210

  • 1. Ring Documentation, Release 1.9 translation to other languages like Arabic, French and so on. Tip: The effect of LoadSyntax command is related to the current source code ïŹle only. 71.4 Using “()” around the function parameters We can use () around the function parameters (optional). Example: hello() sum(3,4) func hello() see "Hello" + nl func sum(x,y) see x+y+nl Output: Hello 7 Example: myfunc = func x,y { see x + y + nl } call myfunc (3,4) myfunc2 = func (x,y) { see x+y+nl } call myfunc(3,4) Output: 7 7 71.5 Using Semi-colon after and between statements In Ring we can use semi-colon after and between statements (optional). Example: # Using semi-colon is optional see "Hello" + nl ; see "How are you?" + nl ; see "Welcome to Ring" + nl ; one() ; two() ; three() ; func one ; see "one" + nl ; func two ; see "two" + nl ; func three ; see "three" + nl ; Output: 71.4. Using “()” around the function parameters 819
  • 2. Ring Documentation, Release 1.9 Hello How are you? Welcome to Ring one two three 71.6 Using $ and @ in the start of the variable name You can use any unicode character in the variable name also we can use $ and @ in the name. This feature may help, for example we can start global variables with $ and the object attributes with @. In other languages like Ruby this is the rule, In the Ring language this is just an option without any force from the Compiler. example: $global_variable = 5 new test { hello() } class test @instance_variable = 10 func hello local_variable = 15 see "Global : " + $global_variable + nl + "Instance : " + @instance_variable + nl + "Local : " + local_variable + nl Output: Global : 5 Instance : 10 Local : 15 71.7 Using the ‘elseif’ keyword as ‘but’ in if statement if you don’t like the ‘but’ keyword in if statement Then you can use the ‘elseif’ keyword. Example: give x if x = 1 see "one" elseif x=2 see "two" elseif x=3 see "three" elseif x=4 see "four" else see "other" ok see nl 71.6. Using $ and @ in the start of the variable name 820
  • 3. Ring Documentation, Release 1.9 71.8 Using the ‘else’ keyword as ‘other’ in switch statement if you don’t like the ‘other’ keyword in switch statement Then you can use the ‘else’ keyword. Also you can replace ‘else’ with ‘other’ in if statement. i.e. ‘other’ keyword is the same as ‘else’ keyword. Example: x = 1 switch x on 10 see "10" + nl else see "not 10" + nl end Output: not 10 71.9 Using the ‘end’ keyword in different control structures We can use the ‘end’ keyword to close different control structures ‱ If statement ‱ For loop ‱ Switch ‱ While ‱ Try-Catch Example: see "if statement.." + nl x = 1 if x = 1 see "one" + nl elseif x=2 see "two" + nl elseif x=3 see "three" + nl end see "for loop.." + nl for t = 1 to 10 see t end see nl see "switch..." + nl x = 1 switch x on 1 see "one" + nl on 2 see "two" + nl end 71.8. Using the ‘else’ keyword as ‘other’ in switch statement 821
  • 4. Ring Documentation, Release 1.9 see "try catch..." + nl try x = 1 / 0 catch see "catching error" + nl end Output: if statement.. one for loop.. 12345678910 switch... one try catch... catching error 71.10 Using braces to start and end different control structures We can use braces { } to start and end different control structures ‱ If statement ‱ For loop ‱ Switch ‱ While ‱ Try-Catch Example: see "if statement.." + nl x = 1 if x = 1 { see "one" + nl elseif x=2 see "two" + nl elseif x=3 see "three" + nl } see "for loop.." + nl for t = 1 to 10 { see t } see nl see "switch..." + nl x = 1 switch x { on 1 see "one" + nl on 2 see "two" + nl } see "try catch..." + nl try { 71.10. Using braces to start and end different control structures 822
  • 5. Ring Documentation, Release 1.9 x = 1 / 0 catch see "catching error" + nl } Output: if statement.. one for loop.. 12345678910 switch... one try catch... catching error 71.11 Using ‘put’ and ‘get’ as ‘see’ and ‘give’ We can replace the ‘see’ keyword with the ‘put’ keyword. Also we can replacew the ‘give’ keyword with the ‘get’ keyword. Example: put "Hello World" + nl put "Enter Your Name ? " Get Name Put "Hello " + Name 71.12 Using ‘case’ as ‘on’ in switch statements We can replace the ‘on’ keyword with ‘case’ keyword in the switch statement. Example (1) : for x=1 to 10 switch x case 1 put "one" + nl case 2 put "two" + nl case 3 put "thre" + nl else put "else" + nl end end Example (2) : for x=1 to 10 { switch x { case 1 put "one" + nl case 2 put "two" + nl case 3 put "thre" + nl else put "else" + nl } } 71.11. Using ‘put’ and ‘get’ as ‘see’ and ‘give’ 823
  • 6. Ring Documentation, Release 1.9 71.13 Using ‘def’ as ‘func’ in functions/methods deïŹnition We can use the ‘def’ keyword as the ‘func’ keyword to deïŹne functions and methods. Example: one() two() def one put "one" + nl def two put "two" + nl 71.14 Using braces { } in Packages/Classes/Functions Example: load "stdlib.ring" import mypackage new myclass { myfunc() } package mypackage { class myclass { func myfunc { print("Hello, World!n") } } } 71.15 Using ‘end’ keyword after Packages/Classes/Functions Example: import mypackage new myclass { myfunc() } package mypackage class myclass def myfunc put "Hello, World!" end end end 71.13. Using ‘def’ as ‘func’ in functions/methods deïŹnition 824
  • 7. Ring Documentation, Release 1.9 71.16 Using ‘endpackage’/’endclass’/’endfunc’ keywords after Pack- ages/Classes/Functions Example: import mypackage new myclass { myfunc() } package mypackage class myclass func myfunc see "welcome" + nl endfunc endclass endpackage 71.17 Ignore new lines after keywords Starting from Ring 1.8 the compiler will ignore new lines after keywords that expect tokens after it Example: see " Hello, World! " test() func #======================# Test #======================# ? " Hello from the Test function " Output: Hello, World! Hello from the Test function 71.16. Using ‘endpackage’/’endclass’/’endfunc’ keywords after Packages/Classes/Functions 825
  • 8. CHAPTER SEVENTYTWO INTRODUCTION TO THE TYPE HINTS LIBRARY In this chapter we will learn about the Type Hints Library 72.1 Why Type Hints? Using this library we can add the type information to the source code which will be very useful for tools like ‱ Code Editors ‱ Static-Analysis Note: Ring is a dynamic language, No type checking will be done by the compiler. 72.2 Example The next example will use the Type Hints library load "typehints.ring" see sum(3,4) + nl ; see sayHello("Mahmoud"); int func sum(int x,int y) { return x+y ; } string func sayHello(string name) { return "Hello " + name ; } 72.3 User Types The Type Hints library is very powerful and will support user types (Classes) automatically Example: load "typehints.ring" import mypackage 826
  • 9. Ring Documentation, Release 1.9 test() { main([:one,:two,:three]) } myclass func test() { see "Testing User Types!" + nl return new myclass } package mypackage { public class myclass { public static void func main(list args) { see "welcome" + nl see args } } } 72.4 Using Types inside Code Also you can use the types inside the code (not only the function prototype) Example: load "typehints.ring" int sum = sum(3,4) string msg = sayHello("Mahmoud") see "Sum = " + sum + nl + msg + nl int func sum(int x,int y) { return x+y ; } string func sayHello(string name) { return "Hello " + name ; } 72.5 Rules ‱ To use the types in the function prototype you must use ‘(‘ and ‘)’ around parameters ‱ To use the types in the function code, You must set the variable value (Assignment). The next types are deïŹned by the library # Low Level Types char unsigned signed int short long float 72.4. Using Types inside Code 827
  • 10. Ring Documentation, Release 1.9 double void # High Level Types string list number object # Other public static abstract protected override 72.5. Rules 828