diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-05-23 12:22:21 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-05-23 12:22:21 +0800 |
| commit | cf0a0f37bf07eb8e9435febe96e3adfe45004f91 (patch) | |
| tree | 480cb978564d77ac088a505704e7df34863e8cb7 /spec/outputs/codes_from_doc_zh.lua | |
| parent | 7bf2832d653027932fd845ba1462dd385ac32ab8 (diff) | |
| download | yuescript-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.lua | 33 |
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 并包括一个换行。" | |||
| 694 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") | 694 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") |
| 695 | local integer = 1000000 | 695 | local integer = 1000000 |
| 696 | local hex = 0xEFBBBF | 696 | local hex = 0xEFBBBF |
| 697 | local binary = 19 | ||
| 697 | local my_function | 698 | local my_function |
| 698 | my_function = function() end | 699 | my_function = function() end |
| 699 | my_function() | 700 | my_function() |
| @@ -2222,6 +2223,38 @@ local inventory = { | |||
| 2222 | } | 2223 | } |
| 2223 | } | 2224 | } |
| 2224 | } | 2225 | } |
| 2226 | local map | ||
| 2227 | map = 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 | ||
| 2236 | end | ||
| 2237 | local filter | ||
| 2238 | filter = 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 | ||
| 2249 | end | ||
| 2250 | local reduce | ||
| 2251 | reduce = 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 | ||
| 2257 | end | ||
| 2225 | print(reduce(filter(map({ | 2258 | print(reduce(filter(map({ |
| 2226 | 1, | 2259 | 1, |
| 2227 | 2, | 2260 | 2, |
