Category talk:LSL Types

From Second Life Wiki
Revision as of 07:31, 27 April 2012 by Dale Innis (Talk | contribs)

Jump to: navigation, search

Mutability

The section on mutability seems wrong, or at least needs more explanation if it isn't. Vectors and Rotations clearly appear to be mutable:

vector v = <1,3,3>;

v.x = 0;

Obviously, the following sequence has the same result:

vector v = <1,2,3>;
v = <0,v.y,v.z>;

These might be operationally equivalent. But it is less than clear that they are operationally the same (at least naively, one would expect the two versions to have a different machine implementation, with the first perhaps more efficient).

Yeah, even more obviously, lists are mutable. The person must have meant "basic types" or something... Dale Innis 20:46, 26 April 2012 (PDT)

You bring up a good point. The section is talking about a different type of mutability. What it is trying to say is that when a function is called the parameters are copies. You can manipulate and overwrite the parameters all you want and those changes will not be conveyed to the calling scope. So in that sense all variables are immutable. LSL may have pass by reference under the hood, but it does not enable mutability. In many languages you pass a list by reference to a sort function and that function sorts the list. The value of the list has changed as a result of calling the function. LSL does not have that capacity. In LSL anything you pass to a function will be unchanged by the function. Vectors & rotations are only sort of mutable (lists are not mutable at all), you can change their components. Coaching this in terms of mutability was a bad choice. Is there a better word for this? -- Strife (talk|contribs) 21:33, 26 April 2012 (PDT)
Ah, okay! That's not really what "mutable" means in programming languages.  :) The best way to say this is that all function parameters in LSL are passed by value rather than by reference. (To stress the fact that LSL has no pointer types, it would also be good to say that all parameters are passed by copy.) The fact that you can say for instance "myVector.z = 7" or "myList += [1,2,3]" means that vectors and lists are are mutable; but in some sense the fact that all function parameters are passed by copy makes that fact not matter nearly as much! Dale Innis 07:21, 27 April 2012 (PDT)
P.S. I've now convinced myself that, in this bizarre language of ours, lists are in fact *not* mutable. You can't say l[4] = 0, instead you have to say l = llListReplaceList(l,[0],4,4) or whatever it is. So you can't change an existing list, you can just calculate a new list and stick in in the existing variable. Craziness.  :) But vectors and rotations are still mutable, since you can access the .x etc elements to change an existing one. Dale Innis 08:31, 27 April 2012 (PDT)

LSL Wiki links needed

Template:LSL Unhelpful should be added to the LSL data-type pages. — Albert Zerundi 02:34, 21 May 2010 (UTC)

Good idea. -- Strife (talk|contribs) 21:35, 26 April 2012 (PDT)