-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.du
More file actions
138 lines (116 loc) · 2.77 KB
/
example.du
File metadata and controls
138 lines (116 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Example Duso script demonstrating syntax highlighting and features
// This file showcases the language features supported by the Zed extension
// Comments
/* Multi-line comment
This extension provides syntax highlighting
and LSP support for Duso scripts
*/
// Variables and types
name = "Duso" // inline comment not highlighting as a comment...
version = 0.22
active = true
numbers = [1, 2, 3, 4, 5]
config = {timeout = 30, retries = 3}
// String templates
greeting = "Hello, {{name}}!"
message = """
This is a multi-line string
with {{version}} and features
"""
// Basic control flow
if active then
print("Starting script...")
elseif version > 0.2 then
print("Legacy version")
else
print("Inactive")
end
// Loops
for item in numbers do
print("Item:", item)
end
for i = 0, 5 do
print("Index:", i)
end
while true do
input_value = input("Enter something: ")
if input_value == "quit" then
break
end
print("You said:", input_value)
end
// Functions
function calculate(a, b, operation)
if operation == "add" then
return a + b
elseif operation == "multiply" then
return a * b
else
throw("Unknown operation: " + operation)
end
end
result = calculate(5, 3, "add")
print("5 + 3 =", result)
// Ternary operator
status = version > 0.2 ? "stable" : "beta"
print("Status:", status)
// Error handling
try
file_content = load("data.json")
data = parse_json(file_content)
catch (error)
print("Error reading file:", error)
end
// Built-in functions
print("Math operations:")
print("abs(-10) =", abs(-10))
print("sqrt(16) =", sqrt(16))
print("max(3, 7) =", max(3, 7))
// Array operations
items = ["apple", "banana", "cherry"]
print("First item:", items[0])
print("Array length:", len(items))
mapped = map(items, function(item)
return upper(item)
end)
print("Uppercase items:", mapped)
// String operations
text = "duso language"
print("Upper:", upper(text))
print("Contains 'language':", contains(text, "language"))
print("Substring:", substr(text, 0, 4))
// Parallel execution (advanced)
results = parallel(
function()
return "First result"
end,
function()
return "Second result"
end,
function()
return "Third result"
end
)
print("Parallel results:", results)
// HTTP requests
response = fetch("https://api.example.com/data")
if response.status == 200 then
api_data = parse_json(response.body)
print("API Response:", api_data)
end
// Module imports
math_utils = require("math")
result = math_utils.complex_calculation()
// Object construction
person = {
name = "Alice",
age = 30,
skills = ["Duso", "Go", "Python"]
}
print("Person:", person.name, "Age:", person.age)
// Datastore (for concurrent access)
store = datastore()
store.set("key", "value")
stored = store.get("key")
print("Stored value:", stored)
print("\nScript completed!")