assignment

Javascript AND operator with assignment

Hi there, I know that in Javascript you can do: var oneOrTheOther = someOtherVar || "these are not the droids you are looking for...move along"; where the variable oneOrTheOther will take on the value of the first expression if it is not null, undefined, or false. In which case it gets assigned to the value of the second statement. ...

Can a JavaScript object property refer to another property of the same object?

I recently tried to create an object like this: var carousel = { $slider: $('#carousel1 .slider'), panes: carousel.$slider.children().length }; My intentions were to improve jQuery's selector performance by caching the results of $('#carousel1 .slider') in an object property, and to keep the code concise and relatively...

Delphi: Assigning to global record - global record doesn't change

In a delphi unit, I have a global record called 'Context': interface type TContext = record ... end; var context: TContext; I also have a initialization procedure in this unit, taking a context: interface procedure Init(AContext: TContext); Inside the Init procedure, I try to assign the given context to ...

Types for which "is" keyword may be equivalent to equality operator in Python

For some types in Python, the is operator seems to be equivalent to the == operator. For example: >>> 1 is 1 True >>> "a spoon" is "a spoon" True >>> (1 == 1) is (2 == 2) True However, this is not always the case: >>> [] == [] True >>> [] is [] False This makes sense for immutable types such as lists. However, immutable types suc...

Javascript still not working

I still can not get my coding to run. When I try to run the coding, a blank page shows up. Specifically, what do I need to do in order to get this simple coding to function? All I need is someone to look this over or test it and tell me what I need to get my coding to work. <html> <body> <script language="JavaScript"> <!-- var classCtr;...

What is happening in this Python program?

I'd like to know what is getting assigned to what in line 8. # Iterators class Fibs: def __init__(self): self.a = 0 self.b = 1 def next(self): self.a, self.b = self.b, self.a+self.b # <--- here return self.a def __iter__(self): return self fibs = Fibs() for f in fibs: if f > 100...

Hybrid Inheritance Example

Can anyone suggest any real life example of Hybrid inheritance? ...

AS3: Copying a Loader from one object to another

I have two classes, call them A and B. They both contain a Loader object. In class A I load content into the Loader object. public class A { var loader:Loader; public function A():void { loader = new Loader(); this.addChild(loader); loader.load(...); } } public class B() { var loader:Loader;...

C++ Copy through assignment problem

Howdy, I seem to be having trouble with the following function: void OtherClass::copy_this( int index, MyClass &class_obj) { if(index < MAX_index) class_obj = array_of_MyClass[index]; } OtherClass maintains an array of MyClass objects, and I would like this function to copy a selected object out of the array into the prov...

Yielding until all needed values are yielded, is there way to make slice to become lazy

Is there way to stop yielding when generator did not finish values and all needed results have been read? I mean that generator is giving values without ever doing StopIteration. For example, this never stops: (REVISED) from random import randint def devtrue(): while True: yield True answers=[False for _ in range(randint(1...

Java constructor final variable assignment

public class User { private final String _first_name; private final String _last_name; private final String _org_ID; private final TimeZone _time_zone; private final InternetAddress _email; private final Date _last_login; private final Date _creation_date; public User( final String org_I...

Which object did send a "release" message to my property ?

Hi everyone ! There's something i don't seem to get about properties and memory management with iOS ! In my AppDelegate, i want a NSString * property : - i've declared it this way in the .h file : @property (nonatomic, copy) NSString *myString; - and synthetized it in the .m One of my method use the property like this : myString = ...

Would it be very unpythonic to use this setitem function to overcome the list comprehension limitation?

>>> a=range(5) >>> [a[i] for i in range(0,len(a),2)] ## list comprehension for side effects [0, 2, 4] >>> a [0, 1, 2, 3, 4] >>> [a[i]=3 for i in range(0,len(a),2)] ## try to do assignment SyntaxError: invalid syntax >>> def setitem(listtochange,n,value): ## function to overcome limitation listtochange[n]=value return value >>> ...

scroll bar and slider resizing

I'm doing a homework assignment where I need to display an image and then allow the user to resize the image witha JSlider. I have the image displaying, but Im not sure how I could use a slider to change the size. As I understand sliders, there are 3 parameters that control the default value, the max slider value, and the min slider valu...

Pythonic way to assign an instance of a subclass to a variable when a specific string is presented to the constructor of the parent class.

I want to be able to create an instance of a parent class X, with a string "Q" as an extra argument. This string is to be a name being an identifier for a subclass Q of the parent class X. I want the instance of the parent class to become (or be replaced with) an instance of the subclass. I am aware that this is probably a classic pro...

In JavaScript, is chained assignment okay?

Am not new to JS or its syntax, but sometimes, the semantics of the language has me stumped at times. At work today, a colleague mentioned this: var a = b = []; is not the same as var a = [], b = []; or var a = []; var b = []; since the first version actually assigns the reference to an empty array to a and b. I couldn't quite a...

Assign zero to float in C

I've got in the habit of using float f = 0.; //with a trailing period when assigning a zero value to a float in C. Should I be using float f = 0.f; //with an explicit float size or just stop messing about and use float f = 0; //with no trailing anything? Where did I pick up that habit and why? Is any version more right or wrong than a...

Why does C++ support memberwise assignment of arrays within structs, but not generally?

I understand that memberwise assignment of arrays is not supported, such that the following will not work: int num1[3] = {1,2,3}; int num2[3]; num2 = num1; // "error: invalid array assignment" I just accepted this as fact, figuring that the aim of the language is to provide an open-ended framework, and let the user decide how to imple...

bash line concatenation during variable interpolation

$ cat isbndb.sample | wc -l 13 $ var=$(cat isbndb.sample); echo $var | wc -l 1 Why is the newline character missing when I assign the string to the variable? How can I keep the newline character from being converted into a space? I am using bash. ...

How to assign a value to a variable when writing the value takes multiple lines (python)

I have a variable x to which I want to assign a very long string. Since the string is pretty long I split it into 10 substrings. I would like to do something like this: x = 'a very long string - part 1'+ 'a very long string - part 2'+ 'a very long string - part 3'+ ... 'a very long string - part 10' But tur...