type-coercion

What is the difference between autoboxing and coercion? [closed]

拟墨画扇 提交于 2019-12-11 16:25:12
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I program in Java, C and Python. The rule for automatic coercions among arithmetic types have been augmented to handle the richer set of types Source: "The C Programming Language" But what does "coercion" mean?

Apps for Office 365 - Return selected text with styling and formatted

天大地大妈咪最大 提交于 2019-12-11 11:07:48
问题 I created an Add-In App for Office365 (Word, Excel and Powerpoint) and i want to get the selected text inside my app, with new lines and styling. I am using the following code to do that function getSelectedData(hasSelectionCallback, noSelectionCallback) { var type = Office.CoercionType.Text; Office.context.document.getSelectedDataAsync(type, { valueFormat: "formatted", filterType: "all" }, function (asyncResult) { var error = asyncResult.error; if (asyncResult.status === Office

Coercing ArrayRef[MyClass] from ArrayRef[HashRef]

无人久伴 提交于 2019-12-06 07:18:32
问题 In trying to answer How to instantiate Moose classes from a big hash, I think I have hit another place where I don't fully understand Moose type coercions. For some reason, the below code issues warnings: You cannot coerce an attribute (departments) unless its type (ArrayRef[Company::Department]) has a coercion at ./test.pl line 12. You cannot coerce an attribute (employees) unless its type (ArrayRef[Company::Person]) has a coercion at ./test.pl line 23. but then succeeds. #!/usr/bin/env perl

Coercing ArrayRef[MyClass] from ArrayRef[HashRef]

若如初见. 提交于 2019-12-04 14:14:01
In trying to answer How to instantiate Moose classes from a big hash , I think I have hit another place where I don't fully understand Moose type coercions. For some reason, the below code issues warnings: You cannot coerce an attribute (departments) unless its type (ArrayRef[Company::Department]) has a coercion at ./test.pl line 12. You cannot coerce an attribute (employees) unless its type (ArrayRef[Company::Person]) has a coercion at ./test.pl line 23. but then succeeds. #!/usr/bin/env perl use warnings; use strict; package Company; use Moose; use Moose::Util::TypeConstraints; has 'id' =>

Question about jQuery source == on window

南楼画角 提交于 2019-12-01 20:54:43
data: function( elem, name, data ) { if ( !jQuery.acceptData( elem ) ) { return; } elem = elem == window ? windowData : elem; Copied directly from the jQuery source. Why is it not safe to use elem === window ? Why does jQuery use type coercion on the window object? It would appear that in IE there's an issue with top top == window // true top === window // false Raynos See here for why checking againts the window object with === is unsafe in IE. I think the root cause is that IE is closely coupled with the Windows OS so you have various OS objects referenced through window and the equality

Why, in JavaScript, does '3 instanceof Number' == false, but '3..method()' will call Number.prototype.method?

六月ゝ 毕业季﹏ 提交于 2019-11-29 18:13:43
Given that a literal number not strictly an instance of Number, why can I call prototype methods of Number (or String, or Boolean) objects on the corresponding literal objects? Is this standard behavior across browsers? What exactly is happening when this occurs? I suspect it's coercing the literal into the corresponding type before calling the method, because when I inspect typeof this in the method, it's returning 'object' rather than 'number'. The literal is not coerced into an instance. What happens internally, is that an instance is created, the value is copied to the instance and the

Understanding JavaScript hoisting and truthy & falsy

邮差的信 提交于 2019-11-28 12:31:46
I've been reading about JavaScript hoisting sometime back. JavaScript Scoping and Hoisting by Ben Cherry Two words about “hoisting” by Dmitry Soshnikov and, some more about JavaScript type-coercion, truth & false test: Truth, Equality and JavaScript and some other resource And while practicing some, and found I m missing some important concept about the hoisting and a variable' truthy & falsy. 1: 'if' truth test with duplicate variable declaration var foo = 1; function bar() { if (!foo) { alert('inside if'); var foo = 10; } } bar(); o/p: inside if Doubt: 'foo' value being '1', if(!foo) should

How does PHP compare strings with comparison operators?

别等时光非礼了梦想. 提交于 2019-11-27 15:31:16
I'm comparing strings with comparison operators. I needs some short of explanations for the below two comparisons and their result. if('ai' > 'i') { echo 'Yes'; } else { echo 'No'; } output: No Why do these output this way? if('ia' > 'i') { echo 'Yes'; } else { echo 'No'; } Output: Yes Again, why? Maybe I forgot some basics, but I really need some explanation of these comparison examples to understand this output. coderabbi PHP will compare alpha strings using the greater than and less than comparison operators based upon alphabetical order. In the first example, ai comes before i in

How does PHP compare strings with comparison operators?

做~自己de王妃 提交于 2019-11-26 17:14:46
问题 I'm comparing strings with comparison operators. I needs some short of explanations for the below two comparisons and their result. if('ai' > 'i') { echo 'Yes'; } else { echo 'No'; } output: No Why do these output this way? if('ia' > 'i') { echo 'Yes'; } else { echo 'No'; } Output: Yes Again, why? Maybe I forgot some basics, but I really need some explanation of these comparison examples to understand this output. 回答1: PHP will compare alpha strings using the greater than and less than

How to flatten a list to a list without coercion?

徘徊边缘 提交于 2019-11-26 16:09:25
I am trying to achieve the functionality similar to unlist, with the exception that types are not coerced to a vector, but the list with preserved types is returned instead. For instance: flatten(list(NA, list("TRUE", list(FALSE), 0L)) should return list(NA, "TRUE", FALSE, 0L) instead of c(NA, "TRUE", "FALSE", "0") which would be returned by unlist(list(list(NA, list("TRUE", list(FALSE), 0L)) . As it is seen from the example above, the flattening should be recursive. Is there a function in standard R library which achieves this, or at least some other function which can be used to easily and