Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't think any of the languages you mentioned support true pass-by-reference. (maybe C# and Java, but it's not common) I've heard what you're describing as "pass-by-value-reference" Go, however, supports pass-by-reference which allows you to write a function like this:

    func swap(x *int, y *int) {
       var temp int
       temp = *x    /* save the value at address x */
       *x = *y    /* put y into x */
       *y = temp    /* put temp into y */
    }


Sure, you can't have the same code for Python, for instance, even if it was using objects, but you can have the same effect using a hack by copying the __dict__ from one object to another. However, you are still passing the object to a function by reference because the function can mutate the object and the object that the callee passed will also be mutated the same way, i.e. mutable objects are passed by reference, and values are passed as values. Which is how python, javascript, Java and the rest work. Obviously, you don't get to change what the reference is pointing to in most of these languages, but you can change the value that is being pointed to.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: