shallow-copy

Pass by value confusion in Scheme

末鹿安然 提交于 2019-12-13 02:27:45
问题 Consider the following procedure taken from SICP: (define (make-withdraw balance) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds"))) Suppose I say: (define x (make-withdraw 100)) make-withdraw returns a procedure ( (lambda (amount) ... ) ) inside a new environment called e2 (enclosing the binding for the variable balance ), and binds that procedure to x in the global frame. Now, say I call: (f x) where (define (f y) (y 25)) 1 . I

In python, is a function return a shallow or deep copy?

◇◆丶佛笑我妖孽 提交于 2019-12-12 10:46:29
问题 In python, if I have x = y any modification to x will also modify y, and I can do x = deepcopy(y) if I want to avoid modifying y while working on x Say, instead, that I have: myFunc(): return y def main(): x = myFunc() Is it still the case that modifying x will modify y, or since it is a return from another function it will be like a deepcopy? 回答1: It will be a shallow copy, as nothing has been explicitly copied. def foo(list): list[1] = 5 return list For example: >>> listOne = [1, 2] >>>

python lists copying is it deep copy or Shallow copy and how is it done?

耗尽温柔 提交于 2019-12-11 05:57:30
问题 How is Deep copy being done in python for lists? I am a little confused for copying of lists. Is it using shallow copy or deep copy? Also, what is the syntax for sublists? is it g=a[:] ? 回答1: The new list is a copy of references. g[0] and a[0] both reference the same object. Thus this is a shallow copy. You can see the copy module's deepcopy method for recursively copying containers, but this isn't a common operation in my experience. Stylistically, I prefer the more explicit g = list(a) to

Make a shallow copy in data.table

南楼画角 提交于 2019-12-10 13:54:01
问题 I read in an SO topic an answer from Matt Dowle about a shallow function to make shallow copies in data.table . However, I can't find the topic again. data.table does not have any exported function called shallow . There is an internal one but not documented. Can I use it safely? What is its behavior? What I would like to do is a memory efficient copy of a big table. Let DT be a big table with n columns and f a function which memory efficiently adds a column. Is something like that possible?

In c# does Array.ToArray() perform a DEEP copy?

不打扰是莪最后的温柔 提交于 2019-12-10 13:38:36
问题 This should be a pretty basic question, but I've been having a little trouble finding a definite answer. When you have an array of values and you use the .ToArray() method does it create a deep or shallow copy of the array? 回答1: No. You can easily verify this by writing a small program to test. 来源: https://stackoverflow.com/questions/10387415/in-c-sharp-does-array-toarray-perform-a-deep-copy

Can I write different copyCtor for const and non-const instances?

那年仲夏 提交于 2019-12-08 18:25:36
问题 I have the following problem: I have a class which should do this: Obj o; Obj o1(o), o1=o; // deep-copies const Obj c(o), c=o; // deep-copies const Obj c1(c), c1=c; // shallow-copies Obj o2(c), o2=c; // deep-copies How can I do this preferably without inheritance? (I mean I would do Const_obj inheriting from Obj otherwise.) EDIT: Using o.clone() directly is not an option because then I could easily introduce bugs by accidentally not cloning. EDIT: Finally, there is a proper, complete solution

Does setting one pointer to an object to nil affect the object or other pointers to it?

ぃ、小莉子 提交于 2019-12-08 12:04:02
问题 Although I know the main difference between Deep Copy and Shallow Copy but what I want to ask here is something practical. I have NSArray *firstArray = [NSArray arrayWithObjects:@"first", @"second",@"third", nil]; NSArray *secondArray = firstArray; secondArray = nil; NSLog(@"First Array : %@",firstArray); NSLog(@"Secon Array : %@",secondArray); Both the firstArray and secondArray has the same reference as seen by putting break point. Now my question is this, if both have same REFERENCE then

How to shallow copy app engine model instance to create new instance?

你说的曾经没有我的故事 提交于 2019-12-08 10:32:36
问题 I want to implement a simple VersionedModel base model class for my app engine app. I'm looking for a pattern that does not involve explicitly choosing fields to copy. I am trying out something like this, but it is to hacky for my taste and did not test it in the production environment yet. class VersionedModel(BaseModel): is_history_copy = db.BooleanProperty(default=False) version = db.IntegerProperty() created = db.DateTimeProperty(auto_now_add=True) edited = db.DateTimeProperty() user = db

Silverlight: How to Make a ShallowCopy of a UIElement

我怕爱的太早我们不能终老 提交于 2019-12-08 04:24:02
问题 I need to add a UIElement to two different canvases, but one UIElement can only be a child of ONE canvas, so I have to create a ShallowCopy (DeepCopy not needed) of the UIElement . I want to use MemberwiseClone , but it's protected, I cannot use it. I also want to define an extension method UIElement.ShallowCopy , but it sill still call MemberwiseClone , which is protected again. EDIT: Tried all the following, but all of them failed in Silverlight environment: // System.Runtime.Serialization

How can I create a deep copy of my list collection

喜欢而已 提交于 2019-12-07 10:10:47
问题 Suppose I have the following class: public class Author { public int ID {get; private set;} public string firstName {get; private set;} public string lastName {get; private set; } public Author(int id, string firstname, string lastname) { this.ID = ID; this.firstName = firstname; this.lastName = lastName; } public static Author Clone(Author clone) { Author copyAuth = new Author(clone.ID, clone.firstName, clone.lastName); return copyAuth; } } and public class Book { public string bookTitle