Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Changes
Page history
Updated Home (markdown)
authored
Feb 11, 2019
by
Daniel Șuteu
Show whitespace changes
Inline
Side-by-side
Home.md
View page @
3e772007
...
@@ -748,8 +748,8 @@ say $^SIDEF # prints the path to sidef executable
...
@@ -748,8 +748,8 @@ say $^SIDEF # prints the path to sidef executable
This constants look like variables, but are actually file-handles.
This constants look like variables, but are actually file-handles.
```ruby
```ruby
STDERR.
print
("Some error!")
STDERR.
say
("Some error!")
STDOUT.
print
("Some output...")
STDOUT.
say
("Some output...")
STDIN.readline() # reads a line from the standard input
STDIN.readline() # reads a line from the standard input
```
```
...
@@ -759,7 +759,7 @@ Here is the implementation of a very basic `cat`-like program:
...
@@ -759,7 +759,7 @@ Here is the implementation of a very basic `cat`-like program:
```ruby
```ruby
ARGF.each { |line|
ARGF.each { |line|
print
line
say
line
}
}
```
```
...
@@ -1041,7 +1041,7 @@ func factorial (n) {
...
@@ -1041,7 +1041,7 @@ func factorial (n) {
say factorial(5); # prints: 120
say factorial(5); # prints: 120
```
```
Anonymous function
s
:
Anonymous
recursion can be achieved by using the `
__FUNC__
` keyword, which refers to the current
function:
```ruby
```ruby
func recmap(repeat, seed, transform, callback) {
func recmap(repeat, seed, transform, callback) {
...
@@ -1054,6 +1054,21 @@ func recmap(repeat, seed, transform, callback) {
...
@@ -1054,6 +1054,21 @@ func recmap(repeat, seed, transform, callback) {
recmap(6, "0", func(s) { s + s.tr('01', '10') }, func(s) { say s })
recmap(6, "0", func(s) { s + s.tr('01', '10') }, func(s) { say s })
```
```
Additionally, the `
__BLOCK__
` keyword can be used for referring to the current block:
```ruby
func fib(n) {
return NaN if (n < 0)
{|n|
n < 2 ? n
: (__BLOCK__(n-1) + __BLOCK__(n-2))
}(n)
}
say fib(12) #=> 144
```
Storing functions in variables:
Storing functions in variables:
```ruby
```ruby
...
...
...
...