Hello
How are you?
Welcome to Ring
one
two
three
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
class test
@instance_variable = 10
func hello
local_variable = 15
Output:
Global : 5
Instance : 10
Local : 15
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
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
switch x
on 1 see "one" + nl
on 2 see "two" + nl
end
Output:
if statement..
one
for loop..
12345678910
switch...
one
try catch...
catching error
switch x {
on 1 see "one" + nl
on 2 see "two" + nl
}
61.10. Using braces to start and end different control structures 687
Ring Documentation, Release 1.5.2
x = 1 / 0
catch
see "catching error" + nl
}
Output:
if statement..
one
for loop..
12345678910
switch...
one
try catch...
catching error
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
}
}
We can use the ‘def’ keyword as the ‘func’ keyword to define functions and methods.
Example:
one() two()
Example:
load "stdlib.ring"
import mypackage
new myclass {
myfunc()
}
package mypackage
{
class myclass
{
func myfunc
{
print("Hello, World!\n")
}
}
}
Example:
import mypackage
new myclass {
myfunc()
}
package mypackage
class myclass
def myfunc
put "Hello, World!"
end
end
end
Example:
import mypackage
package mypackage
class myclass
func myfunc
see "welcome" + nl
endfunc
endclass
endpackage
SIXTYTWO
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.
62.2 Example
see sum(3,4) + nl ;
see sayHello("Mahmoud");
The Type Hints library is very powerful and will support user types (Classes) automatically
Example:
load "typehints.ring"
import mypackage
691
Ring Documentation, Release 1.5.2
test() { main([:one,:two,:three]) }
package mypackage {
public class myclass {
public static void func main(list args) {
see "welcome" + nl
see args
}
}
}
Also you can use the types inside the code (not only the function prototype)
Example:
load "typehints.ring"
62.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 defined by the library
# Low Level Types
char
unsigned
signed
int
short
long
float
double
void
# Other
public
static
abstract
protected
override
SIXTYTHREE
Step 1:
Copy c:\ring\bin folder to be for example c:\myapp
Step 2:
Rename c:\myapp\ring.exe to c:\myapp\myapp.exe
Step 3:
Create a file c:\myapp\ring.ring
And write
Load "myapp.ring"
When you run myapp.exe the file ring.ring will be executed automatically
So your file myapp.ring will be called and executed
Or just rename myapp.ring to ring.ring
It’s a fast way to distribute applications.
Step 1:
Execute the next command
ring myapp.ring -go
This will generate one object file (myapp.ringo) from the project files (*.ring)
Step 2:
Rename myapp.ringo to ring.ringo
When you run the executable file (ring.exe) or (myapp.exe) the file ring.ringo will be executed.
694