@zep:
Any chance we could get the added value back from add(t,v)? I ask because it would simplify code a lot of the time. For example, I have a job manager I'm playing with that has a function like this:
function job_call( cor ) local job = { cor=cor, is_call=true } add( _jobs, job ) return job end |
If add(t,v) returned v, I could write it like this:
function job_call( cor ) return add( _jobs, { cor=cor, is_call=true } ) end |
Nicer, right? Cleaner, fewer tokens. I think that even lets the compiler implement it as a tailcall.
I know it's just a minor thing, but quality-of-life stuff like this can be really nice to have. (Kinda like built-in is_empty(t), cei(f), or sincos(a) would be, among others, wink, wink, nudge nudge.)
What do you say? I can't think of any way it would break backwards compatibility. Please? :)
This is wish-listed for a future update. I'm looking at breaking api future compatibility in 0.2.0, so it would likely be then (along with a bunch of other api tweaks).
To wrap a system function, you can store a reference to it and then call it inside the re-written version:
_add=add function add(c,i) _add(c,i) return i end a={1,2,3} b=add(a,"blah") foreach(a,print) print(b) |
That's great about the wishlist, thanks. :)
Turns out it doesn't work at the command line to replace add() with your own code. It keeps calling the original. Try setting add=nil on the command line... it will still work. But it works fine in source code. That's why my attempt to replace it failed while yours works, which is good.
Note to self: test concepts in source.
[Please log in to post a comment]