Skip to content

Commit 8a000cd

Browse files
committed
Обновлены примеры
1 parent 2a94fc1 commit 8a000cd

File tree

8 files changed

+27
-40
lines changed

8 files changed

+27
-40
lines changed

examples/basics/extended_identifier.own

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
`extended indetifier variable` = 9
2-
println `extended indetifier variable`
1+
`extended identifier variable` = 9
2+
println `extended identifier variable`
33

44
`(。◕‿◕。)` = 20
55
`ʕ•ᴥ•ʔ` = 30

examples/basics/operator_overloading.own

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use "std"
2-
use "types"
3-
use "math"
1+
use ["std", "types", "math"]
42

53
println "Operator overloading"
64
def `::`(v1, v2) = string(v1) + string(v2)
@@ -11,7 +9,7 @@ def `^`(v1, v2) = pow(v1[0], v2[0])
119
print "[2] ^ [7] = "
1210
println [2] ^ [7]
1311

14-
def `..`(a, b) = range(a, b - 1)
12+
def `..`(a, b) = range(a, b)
1513
def `**`(a, b) = int(pow(a, b))
1614
for y : 1 .. 10 {
1715
println sprintf("2 ^ %d = %d", y, 2 ** y)

examples/console/colors.own

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use "std"
2-
for b : range(8)
2+
3+
// header
4+
print " " * 4
5+
for b : range(9)
36
print sprintf(" 4%dm ", b)
47
println ""
5-
for f : range(30, 38) {
8+
9+
for f : range(30, 39) {
610
for s : ["", "1;"] {
711
print sprintf("%4sm", s+f)
812
print sprintf(" \u001B[%sm%s\u001B[0m", s+f, "gYw ")
@@ -12,15 +16,3 @@ for f : range(30, 38) {
1216
}
1317
}
1418

15-
/*use "functional"
16-
stream(range(30, 38))
17-
.flatMap(def(f) = [[f, ""], [f, "1;"]])
18-
.forEach(def(a) {
19-
extract(f, s) = a
20-
print sprintf("%4sm", s+f)
21-
print sprintf(" \u001B[%sm%s\u001B[0m", s+f, "gYw ")
22-
for b : range(8)
23-
print sprintf(" \u001B[4%s;%sm%s\u001B[0m", b, s+f, " gYw ")
24-
println ""
25-
})
26-
*/

examples/forms/complicatedForm.own

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ enterTextLabel = newLabel("Enter a text", SwingConstants.CENTER)
1313

1414
textField = newTextField()
1515
textField.addKeyListener(def(type, event) {
16-
lengthLabel.setText(length(textField.getText()))
16+
lengthLabel.setText(textField.getText().length)
1717
})
1818

1919
statusPanel = newPanel()

examples/forms/samobot_chat.own

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use "std"
2-
use "http"
3-
use "forms"
1+
use ["std", "http", "forms"]
42

53
chatHistory = newLabel("<html>Чат с самоботом<br>")
64
messageField = newTextField()
@@ -13,7 +11,7 @@ def onSend() {
1311
if (length(text) == 0) return 0
1412
messageField.setText("")
1513
chatHistory.setText(chatHistory.getText() + "<br><b>вы</b> > " + text)
16-
thread(::http, "http://annimon.com/json/bot.php", "POST", {"text": text}, def(answer) {
14+
thread(::http, "https://annimon.com/json/bot.php", "POST", {"text": text}, def(answer) {
1715
chatHistory.setText(chatHistory.getText() + "<br><b>бот</b> > " + answer)
1816
})
1917
}

examples/functions/calculator.own

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ def calculate(expression) {
2020

2121
def parseNumber() {
2222
buffer = ""
23-
while (pos < len && isDigit(charAt(expression, pos))) {
24-
buffer += toChar(charAt(expression, pos))
23+
while (pos < len && isDigit(expression.charAt(pos))) {
24+
buffer += toChar(expression.charAt(pos))
2525
pos++
2626
}
2727
return number(buffer)
2828
}
2929

3030
def parseOperation() {
31-
while (pos < len && !arrayKeyExists(toChar(charAt(expression, pos)), operations)) {
31+
while (pos < len && !arrayKeyExists(toChar(expression.charAt(pos)), operations)) {
3232
pos++
3333
}
34-
return operations[toChar(charAt(expression, pos++))]
34+
return operations[toChar(expression.charAt(pos++))]
3535
}
3636

3737
num1 = parseNumber()
@@ -43,4 +43,4 @@ def calculate(expression) {
4343
println calculate("2+2")
4444
println calculate("400*16")
4545
println calculate("400/160")
46-
println calculate("3>4")
46+
println calculate("3>4")

examples/functions/stream.own

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use "std"
2-
use "functional"
1+
use ["std", "functional"]
32

43
println "x, square(x), cube(x) for even numbers"
54
data = [1,2,3,4,5,6,7,8,9]
@@ -23,4 +22,4 @@ def reverse(container) {
2322
result[size - i - 1] = container[i]
2423
}
2524
return result
26-
}
25+
}

examples/network/github_timeline.own

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
use "std"
2-
use "http"
3-
use "json"
4-
use "functional"
1+
use ["std", "http", "json", "functional", "date"]
52

63
header = "* Prints current GitHub timeline *"
7-
println "*" * length(header)
4+
println "*" * header.length
85
println header
9-
println "*" * length(header)
6+
println "*" * header.length
107

118
// Executes in main thread
129
//http("https://api.github.com/events", def(r) {
@@ -19,7 +16,7 @@ thread(::http, "https://api.github.com/events", def(r) {
1916
})
2017

2118
def show_github_events(event) {
22-
println event.created_at
19+
println event.created_at.formatTzDate()
2320
println "User: https://github.com/" + event.actor.login
2421
println github_event_type(event)
2522
println "-" * 50
@@ -41,3 +38,6 @@ def github_event_type(event) {
4138
case type : type + " on " + repo
4239
}
4340
}
41+
42+
def formatTzDate(str) = formatDate(parseTzDate(str), newFormat("yyyy-MM-dd HH:mm:ss"))
43+
def parseTzDate(str) = parseDate(str, newFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"))

0 commit comments

Comments
 (0)