[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] A catcode patch
- From: Dirk Laurie <dpl@...>
- Date: Tue, 24 May 2011 15:44:35 +0200
>
> What kind of uses do you have in mind for dynamic catcodes?
>
None that could not be achieved by static catcodes, but different
people need different things and one does not wish to recompile
every time.
So, in no particular order, and just for a start:
1. The underscore is overworked.
2. Some interesting one-character function names.
-- get/set metatables
setcatcode('@','A')
function @(obj,mt)
if mt==nil then return getmetatable(obj) else setmetatable(obj,mt) end
end
-- function mimicking C-style ternary operator
setcatcode('?','A')
function ?(a,b,c)
if a then return b else return c end
end
-- address of tables, objects, files
setcatcode('&','A')
function &(obj)
obj = string.match(tostring(obj),"(0x.......)")
if obj then return obj end
error("No 8-digit hexadecimal address found")
end
-- lightweight functions
setcatcode("!","A")
function !(x,fx) return load(x.."=... return "..fx) end
3. Pander to nostalgia among Perl and Ruby apostates.
Dirk