function name = inline(expr)
while (1)
name = sprintf('__inline%d',rand(1)*100000);
if !exist(name), break;
endwhile
eval("function __return=", name, "(x)\n __return=", expr, "; endfunction");
endfunction
A more correct version would scan expr for the required variables.
A complete version, able to handle, e.g., g=inline('x^2'); g(3) == 9, will require a user defined type which overloads the () operator. The same underlying technique should work, though. Remember to 'clear name' for the destructor.