16.1
#!/usr/bin/lua
function loadwithprefix(prefix,main)
if type(main)=="function" then
local t={}
t[1]=prefix
for w in main do
t[#t+1]=w
end
return load(table.concat(t))
else
return load(prefix..main)
end
end
16.2
#!/usr/bin/lua
function multiload(...)
local main={}
local arg=table.pack(...)
for i=1,arg.n do
if arg[i]==nil then
error("invalide arg")
elseif type(arg[i])=="string" then
main[#main+1]=arg[i]
elseif type(arg[i])=="function" then
local result={}
for w in arg[i] do
result[#result+1]=w
end
main[#main+1]=table.concat(result)
end
end
str=table.concat(main)
return load(str)
end
16.3
#!/usr/bin/lua
function factory_stringgrep(n)
local result={}
result[#result+1]="local s=...;"
result[#result+1]='local r="";'
odd="r=r..s;"
even="s=s..s;"
if n>0 then
while n>1 do
if n%2~=0 then
result[#result+1]=odd
end
result[#result+1]=even
n=math.floor(n/2)
end
result[#result+1]=odd
end
result[#result+1]="return r"
return load(table.concat(result))
end
16.4
待完善