[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
>>> L1 = [10,20,30,40] >>> L2 = L1 >>>
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 44
Thread images: 7
File: 1462225660662.jpg (10 KB, 236x237) Image search: [Google]
1462225660662.jpg
10 KB, 236x237
>>> L1 = [10,20,30,40]
>>> L2 = L1
>>> L1[0] = 0
>>> L1
[0, 20, 30, 40]
>>> L2
[0, 20, 30, 40]
>>
>>54828500
Dumb frogposter
>>
File: 1463646097273.png (64 KB, 395x578) Image search: [Google]
1463646097273.png
64 KB, 395x578
>>54828850
dumb "dumb frogposter" poster
>>
>>54828500
I didn't think python could get any worse.
>>
>>54828500
dumb frogposter
>>
>>54828925
>hurr durr I'm retarded
>>
>>54828850
>>54828943
it's a toad
>>
>>54828500
L2 = list(L1)
#this was very difficult
>>
>>54829419
What the fuck is that backwards bullshit?
>>
>>54829749
You are clearly defining it to be a list based on L1. In L1 = L2, you are stating they must be the same.
>>
>>54828500
Oh boy, let's see this get to bump limit when a simple search could clear doubts and shitposts aside.
>>
>>54828500
default assignment operator in C++ defines the same stupid behavior
>>
>>54829794
No, that statement should assign L2 to L1's current values.
Except this shitty language, whatever it is, seems to turn L1 into a pointer or some backwards shit like that.
>>
>>54828500
This just not work like that
>>
>>54830656
>No, that statement should assign L2 to L1's current values.
Who said that? Retarded frogposter like you can't say what a language should do. Learn the language, fucking retard.
>>
>>54830656
>Except this shitty language, whatever it is, seems to turn L1 into a pointer or some backwards shit like that.
Idiot, it doesn't turn anything to a pointer. Both variables are references.
>>
It does my holy god
>>
arent arrays/lists normally pass by reference in most languages? that is why with shit like python you can send a list as an argument and you dont have to return it to use it with changes
>>
>>54830702
what's the point of "improve the readability" if you have to be an autist of the implementation details, just as in ANSI C bullshit
>>
>>54829794
>>> fag1 = "OP"
>>> fag2 = fag1
>>> fag1 = "you"
>>> fag1
'you'
>>> fag2
'OP'
>>
>>54830753
If were not a pajeet, you would understand. This is not an exotic behavior. A lot of other languages do this.
>>
>>54830778
doesn't compile
>>
File: k.png (20 KB, 566x172) Image search: [Google]
k.png
20 KB, 566x172
>>54830790
>>
>>54830753
in python you have to know what a reference is
in c
you have to deal with this
http://blog.regehr.org/archives/721

>>54830778
strings are immutable, lists are mutable
https://docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x
>>
>>54830882
that wasn't too fair Anon, the c progamming language also explains these things, but you don't expect this behavior on higher languages, that's why STL and Modern C++ (Python++) overload the default assigment operator for each class
>great trivia though, I got 62%
>>
>>54828925
>>54830636
>>54830656
>>54830753

This behavior is not stupid, you guys don't understand programming. Imagine a language that passed non primitive types by value, it would instantly become a bottleneck. Anytime you called a function with a list or other data structure as a parameter, all the contents of the list itself would have to be copied onto the call stack which would be horribly inefficient when dealing with lots of data. That's why pass by reference is a great thing.
>>
>>54831130
Plus, almost all languages have built in functions for copying the actual data itself of a data structure and not its reference. The semantics of the assignment operator are fine, as it should be obvious when a variable is a reference.
>>
>>54831130
>imagine a language that passed non primitive types by value
C++ does it, that's why you have and interface like >this

template <typename T>
foo(T &value)
{
....

the & operator avoid passing an object by value, every programmer must know what a reference is, but
the behaviour of that simply snippet is a fucking joke
>>
>>54830790

>compile
>>
>>54830656

an array is a pointer, faggot.

take an elementary computer science course
>>
>>54828500
>tfw no one can prove to me why meme language Python still exists.
>>
>>54831339
let L2 = JSON.parse....

gee its almost as if you called a function instead of assigning a reference
>>
>>54828500
>>>L2 = L1[:]
Try this and see the magic
>>
>>54831375
I made a deep copy of an object, which is presumably what OP wanted to do in the first place. The method I used to get there shouldn't really matter.

Given that he never really specified wtf he's trying to do in the first place, I'd say it's a fairly safe bet to just assume that's what he wanted, and show a simple, commonplace way to do it in a non-fucked-up language.
>>
>I'm pretending to be retarded again
>>
>>54831412
>json.parse(json.stringify) is better than list(L1)
whatever you say bucko
>>
What does it mean if I found this easy to understand?
>>
>>54831448
Satisfied, bitchass motherfucker? You got scoped vars as a free added bonus
>>
L1 = [10, 20, 30, 40]
L2 = [i for i in L1]
>>
File: Screenshot_2016-05-31-01-44-34.png (45 KB, 480x800) Image search: [Google]
Screenshot_2016-05-31-01-44-34.png
45 KB, 480x800
Is to izi
 
>>>L2 = L1[:]
>>
>>54831499
I could've just done
const L2 = [...L1]
>>
>what are reference types
This is exactly why people should learn C++ first.
>>
>>54831725
No, this is why people should learn before shitposting.
>>
>>54829794
Depends on language. Do you want to assignm a reference or a value. I prefer value, easier to work with
Thread replies: 44
Thread images: 7

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.