lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, May 14, 2011 at 07:26:18PM +0200, Michael Rose wrote:
> jump chr = str:byte(i) in 0,255 do
>   "a".."z" do print("lower") break end
>   "A".."Z" do print("higher") break end
>   32,"_-:" do print("delimiter") break end
>   0 .. 31, 127 .. 255 do print("unprintable") break end
>   do print("other") end
> end

1. "a".."z" and 0 .. 31 already have meanings in Lua.
2. 0,255 and 0 .. 255 both seem to mean the range 0 to 255.
3. Comma already has a meaning in Lua.
4. "in" expects an iterator function in Lua.
5. Lua already has a way of writing ranges in a pattern.
6. This syntax is at least as verbose as doing it with if,then,elseif.

If all that "jump" is going to achieve is to make it easier to respond 
to different values of a character, I'll stick to Lua 5.2.

match = string.match
if match(chr,"[a-z]") then print("lower")
  elseif match(chr,"[A-Z]") then print("upper")
  elseif match(chr,"[\32_%-:]") then print("delimiter")
  elseif match(chr,"[\0-\31\127-\255]") then print("unprintable")
  else print("other")
end

Dirk