ID:2646687
 
Resolved
splicetext() and list.Splice() have been added, which do a cut and an insertion at the same time. For instance, splicetext("banana", 3, 6, "laclav") becomes "balaclava". For text in particular this should be a benefit since it avoids multiple changes to the string tree (using the old method of copytext() + string + copytext()) in favor of a single change.
Applies to:DM Language
Status: Resolved (514.1543)

This issue has been resolved.
Like was discussed in the discord, it would be cool to have list.splice() and splicetext() added to the language.
Implemented for 514.
If you are going to open a feature request, can you actually fucking describe what the fucking feature request does.

What the fuck is a list splice? how the fuck does that work?
In response to MrStonedOne
I can but since they're functions that exist in other languages, which Lummox is already aware of, instead of things I'm making up, I don't need to. Also, google.
Can't this already be done via Cut/Copy/Insert, seems redundant since it can super easily be done in softcode.

proc/splice(LIST,INDEX,REMOVE)
var INSERT = args.Copy(4)
LIST = LIST:Copy(1,INDEX) + LIST:Copy(INDEX+REMOVE)
for(. in INSERT)
LIST:Insert(INDEX,.)
return LIST

mob/Login()
var list/l = list("Cat","Dog","Cookie")
var list/i = splice(l,1,1,"Pie")
for(. in i)
world << "[.]"


Come get your hands on a 514 feature before it's released lol
In response to Kozuma3
Just because you can do something with other means doesn't mean it becomes useless. Built in functions run way faster than something like your example. Also 5+ proc calls vs 1. Also, you're the first one to complain that there aren't things built in with the engine, having to use libraries etc.
In response to NSBR
NSBR wrote:
Built in functions run way faster than something like your example.

You're going to be using splice 1000 times a second or something?, 5 times in a second won't hurt nothing. Softcode isn't that poor

[edit] if anything just add the ability for procs to be defined for lists
In response to Kozuma3
Eh, as someone new to byond coding I can appreciate not having to code a workaround for something so simple, which will now also be in the reference. Why criticize small progress? I get that everyone wants big things done but damn, don't forget how far some QoL things can go, especially for new learners.
Just some noob insight, but inb4 you care enough to reply. *flies away bc dc*
In the world of programming "replacing two calls with one call" is 100% always worth it.
In response to Nadrew
Nadrew wrote:
In the world of programming "replacing two calls with one call" is 100% always worth it.

In the world of BYOND lol
No, in the world of computer science in general. It's 100% less processing, even when nanoseconds are involved.

If you ever have a chance to easily cut down the amount of calls something takes, you should take it.

Optimization normally only happens when needed (some people worry about it too early on though), but occasionally it jumps up and slaps you in the face.

This is true for anything, not BYOND, and not really just computers. If you can cut down the work something does in an obvious and trivial way, why not?
In announcements, Lummox explained why he's adding it for strings, and basically said "Why not add it for lists too?" Given that he's the one doing the work, I find that reasoning hard to argue with.
Lummox JR resolved issue with message:
splicetext() and list.Splice() have been added, which do a cut and an insertion at the same time. For instance, splicetext("banana", 3, 6, "laclav") becomes "balaclava". For text in particular this should be a benefit since it avoids multiple changes to the string tree (using the old method of copytext() + string + copytext()) in favor of a single change.