increment

How do I increment or decrement a number in Common Lisp?

回眸只為那壹抹淺笑 提交于 2019-11-30 02:58:46
What is the idiomatic Common Lisp way to increment/decrement numbers and/or numeric variables? Use the built-in "+" or "-" functions, or their shorthand "1+" or "1-", if you just want to use the result, without modifying the original number (the argument). If you do want to modify the original place (containing a number), then use the built-in "incf" or "decf" functions. Using the addition operator: (setf num 41) (+ 1 num) ; returns 42, does not modify num (+ num 1) ; returns 42, does not modify num (- num 1) ; returns 40, does not modify num (- 1 num) ; NOTE: returns -40, since a - b is not

Python: How can I increment a char?

天涯浪子 提交于 2019-11-29 20:13:37
I'm new to Python, coming from Java and C. How can I increment a char? In Java or C, chars and ints are practically interchangeable, and in certain loops, it's very useful to me to be able to do increment chars, and index arrays by chars. How can I do this in Python? It's bad enough not having a traditional for(;;) looper - is there any way I can achieve what I want to achieve without having to rethink my entire strategy? Any help appreciated. In Python 2.x, just use the ord and chr functions: >>> ord('c') 99 >>> ord('c') + 1 100 >>> chr(ord('c') + 1) 'd' >>> Python 3.x makes this more

Why doesn't a character increment in System.out.println()?

本秂侑毒 提交于 2019-11-29 18:55:27
char char1 = 'a'; System.out.println(char1); //prints char 1 System.out.println(char1+1); //prints char 1 System.out.println(char1++); //prints char 1 System.out.println(char1+=1); //prints incremented char1 char1 += 1; System.out.println(char1); //prints incremented char1 In the above, why doesn't (char1+1) or (char++) print the incremented character but theother two do? First, I'm assuming that because you say the increment in System.out.println works, that you have really specified: char char1 = 'a'; EDIT In response to the change of the question ( char1+1; => char1 += 1; ) I see the issue.

Difference between i = i++ and i = i + 1

两盒软妹~` 提交于 2019-11-29 18:36:53
https://www.hackerrank.com/challenges/compare-the-triplets var alice = bob = 0; if(a0 > b0){ alice = alice + 1; } else if (a0 < b0) { bob = bob + 1; } else if (a1 > b1) { alice = alice + 1; } else if (a1 < b1) { bob = bob + 1; } else if (a2 > b2) { alice = alice + 1; } else if (a2 < b2) { bob = bob + 1; } console.log(alice, bob); VS var alice = bob = 0; if(a0 > b0){ alice = alice++; console.log(alice); } else if (a0 < b0) { bob = bob++; } else if (a1 > b1) { alice = alice++; } else if (a1 < b1) { bob = bob++; } else if (a2 > b2) { alice = alice++; } else if (a2 < b2) { bob = bob++; } console

unexpected output in cout and printf [duplicate]

只愿长相守 提交于 2019-11-29 18:05:24
Possible Duplicate: Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…) For the code below: main() { int i = 1 ; cout << i << ++i << i++ ; } Why do I get the output as 331 instead of what was expected i.e 122 ? ( Same is the case even if I use printf instead of cout ?) << is a function, namely something like ostream& operator<<(ostream& lhs, RhsType rhs) . cout << a; is equivalent to operator<<(cout, a); The function returns lhs, that is return lhs , - so in the above examples cout is returned. So your example cout << i << ++i << i++ ; is equivalent to operator<<

How is that x=20;x= ++x + ++x + x++ ;final value of x in java is 65 [duplicate]

时光怂恿深爱的人放手 提交于 2019-11-29 17:55:30
This question already has an answer here: How do the post increment (i++) and pre increment (++i) operators work in Java? 14 answers How is this possible as post increment operator should increase x to 66? When I did the same for y= ++x + ++x + x++; it gave a value 65 for y and 23 for x. So let me know how is java compilers solving these expression. Let Java show you. javap -c MyClass shows you bytecode: public static void main(java.lang.String[]); Code: 0: bipush 20 2: istore_1 3: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream; 6: iinc 1, 1 9: iload_1 10: iinc 1, 1 13: iload

Why can I increment a char array position inside a function and not in main

心已入冬 提交于 2019-11-29 17:40:53
What's the difference between this function parameter stringLength(char string[]) to stringLength(char *string), shouldn't the first one not allow the incrementation(string = string +1) that has a comment on the code below? #include <stdio.h> #include <stdlib.h> #include <string.h> int stringLength(char string[]) { int length = 0; while(*string) { string = string + 1; // I can do it here length++; } return length; } int main(void){ char s[] = "HOUSE"; s = s + 1; // I can not do it here printf("%s\n", s); printf("%d\n", stringLength(s)); } That's because s is an array in main , but when you

Reliability of atomic counters in DynamoDB

让人想犯罪 __ 提交于 2019-11-29 16:08:01
问题 I was considering to use Amazon DynamoDB in my application, and I have a question regarding its atomic counters reliability. I'm building a distributed application that needs to concurrently , and consistently , increment/decrement a counter stored in a Dynamo's attribute. I was wondering how reliable the Dynamo's atomic counter is in an heavy concurrent environment, where the concurrency level is extremely high (let's say, for example, an average rate of 20k concurrent hits - to get the idea

Java Incremental operator query (++i and i++) [duplicate]

谁说我不能喝 提交于 2019-11-29 14:38:20
问题 This question already has an answer here: Is Java “pass-by-reference” or “pass-by-value”? 86 answers Java is NEVER pass-by-reference, right?…right? [duplicate] 6 answers I have the following code: public class Book { private static int sample1(int i) { return i++; } private static int sample2(int j) { return ++j; } public static void main(String[] arguments){ int i = 0; int j = 0; System.out.println(sample1(i++)); //0 System.out.println(sample1(++i)); //1 System.out.println(sample2(j++));//1

mysql_fetch_array while loop. How does it work?

元气小坏坏 提交于 2019-11-29 14:37:12
I have read about the function on php.net and that has still not answered my question. I know a beginners amount of C and I've just started using php. Normally in C if you were to do a while loop there needs to be some condition to advance the loop to a point where it will no longer be valid like so: while (x >= 10) { printf("..."; printf("x \n"; x++; } However in my php script that I'm using for a pm message system I have a while loop like this: while($row2 = mysql_fetch_array($query)) followed by: { echo "<table border=1>"; echo "<tr><td>"; echo "Message #: "; echo $row['id']; echo "</td><