aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/codes_from_doc_zh.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2025-05-23 12:22:21 +0800
committerLi Jin <dragon-fly@qq.com>2025-05-23 12:22:21 +0800
commitcf0a0f37bf07eb8e9435febe96e3adfe45004f91 (patch)
tree480cb978564d77ac088a505704e7df34863e8cb7 /spec/outputs/codes_from_doc_zh.lua
parent7bf2832d653027932fd845ba1462dd385ac32ab8 (diff)
downloadyuescript-cf0a0f37bf07eb8e9435febe96e3adfe45004f91.tar.gz
yuescript-cf0a0f37bf07eb8e9435febe96e3adfe45004f91.tar.bz2
yuescript-cf0a0f37bf07eb8e9435febe96e3adfe45004f91.zip
Added break with value to with syntax.
Diffstat (limited to 'spec/outputs/codes_from_doc_zh.lua')
-rw-r--r--spec/outputs/codes_from_doc_zh.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index 6349010..52204b7 100644
--- a/spec/outputs/codes_from_doc_zh.lua
+++ b/spec/outputs/codes_from_doc_zh.lua
@@ -694,6 +694,7 @@ local some_string = "这是一个字符串\n 并包括一个换行。"
694print("我有" .. tostring(math.random() * 100) .. "%的把握。") 694print("我有" .. tostring(math.random() * 100) .. "%的把握。")
695local integer = 1000000 695local integer = 1000000
696local hex = 0xEFBBBF 696local hex = 0xEFBBBF
697local binary = 19
697local my_function 698local my_function
698my_function = function() end 699my_function = function() end
699my_function() 700my_function()
@@ -2222,6 +2223,38 @@ local inventory = {
2222 } 2223 }
2223 } 2224 }
2224} 2225}
2226local map
2227map = function(arr, action)
2228 local _accum_0 = { }
2229 local _len_0 = 1
2230 for _index_0 = 1, #arr do
2231 local item = arr[_index_0]
2232 _accum_0[_len_0] = action(item)
2233 _len_0 = _len_0 + 1
2234 end
2235 return _accum_0
2236end
2237local filter
2238filter = function(arr, cond)
2239 local _accum_0 = { }
2240 local _len_0 = 1
2241 for _index_0 = 1, #arr do
2242 local item = arr[_index_0]
2243 if cond(item) then
2244 _accum_0[_len_0] = item
2245 _len_0 = _len_0 + 1
2246 end
2247 end
2248 return _accum_0
2249end
2250local reduce
2251reduce = function(arr, init, action)
2252 for _index_0 = 1, #arr do
2253 local item = arr[_index_0]
2254 init = action(init, item)
2255 end
2256 return init
2257end
2225print(reduce(filter(map({ 2258print(reduce(filter(map({
2226 1, 2259 1,
2227 2, 2260 2,