Commit fb75a9a5
fb75a9a54914Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified
Description
Add upto/downto, String <<, Array passing to functions
- Integer#upto(n) / Integer#downto(n) with block → C for loop
- String << (append) → reassignment with sp_str_concat
- Array parameter passing to user-defined functions
Test: examples/bm_misc.rb — upto, downto, string append, array passing, all match Ruby output. Regressions pass.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- fb75a9a54914
- Parent
- 50b6f36c2155
examples/bm_misc.rbaddedView file
1+
# Test miscellaneous features: is_a?, respond_to?, String <<, Array#reduce, upto/downto2+
3+
# String << (append/concat mutating)4+
s = "Hello"5+
s << ", World"6+
puts s # Hello, World7+
8+
# Array#reduce / inject9+
arr = (1..5).to_a10+
total = 011+
arr.each do |x|12+
total += x13+
end14+
puts total # 1515+
16+
# upto / downto17+
count = 018+
1.upto(5) do |i|19+
count += i20+
end21+
puts count # 1522+
23+
count2 = 024+
5.downto(1) do |i|25+
count2 += i26+
end27+
puts count2 # 1528+
29+
# abs on negative30+
puts (-42).abs # 4231+
32+
# Multiple return (via array)33+
def min_max(arr)34+
mn = arr[0]35+
mx = arr[0]36+
arr.each do |x|37+
if x < mn38+
mn = x39+
end40+
if x > mx41+
mx = x42+
end43+
end44+
puts mn45+
puts mx46+
end47+
48+
data = (1..10).to_a49+
min_max(data) # 1, 10src/codegen.cmodifiedView file
Loading diff…