Feature Overview
JOIN() Join strings with a delimiter.
- Joins the argument strings with the specified delimiter.
- This function consumes 25 Token.
?join('====','----','----','----','----\n') ?join(' ',unpack({'test','[join]','is','ok!\n\n'})) ?join('\fa◆\f6','c','o','m','p','l','e','t','e\n') ?join('\-e=\-e',unpack(split('----------------------------',''))) |
This function is included in the KNUTIL library.
release note
very nice!
here's a 4-token save: (25->21)
function join(d,s,...) return ... and s..d..join(d,...) or s or '' end |
Yes! That's a great option!
The difference between those two codes is not only the difference in tokens.
If the argument is nil, it will either "stop with an error" or "skip the join process".
You can choose the one that is appropriate for your project.
Thanks. @pancelor
I don't understand, can you give an example that behaves differently under the two implementations? this prints true 3 times
function join1(d,s,...) return not s and '' or not ... and s or s..d..join(d,...) end function join2(d,s,...) return ... and s..d..join(d,...) or s or '' end cls() ?join1()==join2() ?join1(" ")==join2(" ") ?join1(" ","hi")==join2(" ","hi") |
The difference is whether to output an error when nil is specified for the s
argument.
JOIN1: Type that ignores errors
JOIN2: The type that outputs errors
In case you are wondering, I have join()
mixed up in the join1() and join2() code you wrote...
ahh that makes sense, thanks. (oh! yep I typoed my join1 and join2 definitions, whoops)
[Please log in to post a comment]