Questions tagged [coercion]

Coercion, type conversion and typecasting are different ways of, implicitly or explicitly, changing an entity of one data type into another.

Coercion, type conversion and typecasting are different ways of, implicitly or explicitly, changing an entity of one data type into another.

398 questions
0
votes
4 answers

how to understand javascript coercion?

I was watching this talk, and on 16:34 there is a javascript coercion test: 5 - "4" // 1 5 + "4" // 54 +!{}[true] // 1 +[1] // 1 +[1, 2] // NaN 7 - "a" // NaN 7 / 0 // Infinity What is the exact logic behind those calculations?
Hyphen Wrex
  • 645
  • 5
  • 9
0
votes
1 answer

Detect a row that contain names

I need to detect if my first row of observations is a row of names. Always when I import the data are imported as character columns from the spreasheet (readxl package). By the structure of the data, a non-name row, always contain at least 8 numeric…
Cristóbal Alcázar
  • 1,153
  • 14
  • 26
0
votes
2 answers

When coercing types to booleans, is it better to use !!x or Boolean(x)

Simply put - I use if(!!something) frequently while totally aware of Boolean(something) but have never use it for reasons that I can't justify. Are there any reasons to use one over the other?
The Dembinski
  • 1,469
  • 1
  • 15
  • 24
0
votes
1 answer

cast child to parent to other child

I have two very similar classes (they share many variables) and I want to convert one into the other. Simplified like this: class ClassForJacksonDatabind { public boolean a; public int b; /* ... */ public float z; /* ...…
joelproko
  • 89
  • 7
0
votes
3 answers

How to make format clean and elegant after casting list to data.frame?

I have set of vector in the list. I want to cast my list to data.frame object for fast manipulation. There is already solution for casting list to data.frame in this site. However, I tried this solution, it works good but format is bit of mass, not…
jyson
  • 245
  • 1
  • 8
  • 27
0
votes
1 answer

Coerce a string to be an input into matrix function within a function

EDIT: For anyone interested, I completed my little project here and it can be seen at this link http://fdrennan.net/pages/myCurve.html Scroll down to "I think it's been generalized decently" to see the curve_fitter function. If you find it useful,…
0
votes
1 answer

no method for coercing this S4 class to a vector for utilization of mclust

I'm trying to use the mclust method on an .FCS format file (which is a flow cytometry format file) and I read this file into R as flowFrame object. install.packages("openCyto") # since the old version sefaulted my R session library( openCyto…
Anara
  • 51
  • 1
  • 2
  • 4
0
votes
1 answer

What is RFC 401's coerce_inner useful for?

I'm reading Rust's RFC 0401 and see this: coerce_inner(Foo<..., T, ...>) = Foo<..., coerce_inner(T), ...> where Foo is a struct and only the last field has type T and T is not part of the type of any other fields; coerce_inner((..., T)) = (...,…
盛安安
  • 1,110
  • 1
  • 8
  • 21
0
votes
3 answers

Why does Ruby need to force an Array into string by using "to_a" if it is clear it is a String addition?

For example: ruby-1.9.2-p0 > a = ['hello', 'world'] => ["hello", "world"] ruby-1.9.2-p0 > "foo" + a TypeError: can't convert Array into String from (irb):3:in `+' from (irb):3 from /Users/peter/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
0
votes
1 answer

Why can't I specify NamedArgs and item elements on cellFactory?

I have the following tableView in fxml
mrt181
  • 5,080
  • 8
  • 66
  • 86
0
votes
1 answer

coercion to interface with methods having multiple parameters

Let's say I've got such interface interface IFile { void writeFile(String name, byte[] bytes) byte[] readFile(String name) } How to do a coercion to that interface? Because so far that approach does not work and leads to compilation…
lapots
  • 12,553
  • 32
  • 121
  • 242
0
votes
2 answers

Issue with ; separated file, negative sign is misplaced, character to numeric conversion coercion

I want to convert all the misplaced -ve sign in data to prefix - sign and convert data to numeric. I have a data frame such as all these data is being read from a ; separated file, which has a wrong separation. I need to clean this data and convert…
Abhi
  • 21
  • 3
0
votes
1 answer

Javascript Objects: Using Arguments as object property

I was reimplementing a memoize function using the Arguments object. I am wondering why this would work. For example, passing in 2 arguments: var args = Array.prototype.slice.call(arguments); // input: 1,2 Then I would store the args array into an…
DSK
  • 13
  • 6
0
votes
0 answers

JavaScript closure compiler type coercion performance

Do compilers perform poorly with booleans converted to integers? /** * @type {boolean} */ var isFirstCall = true; handler(); handler(); handler(); function handler () { if (isFirstCall --> false) { // this runs once; isFirstCall and…
neaumusic
  • 10,027
  • 9
  • 55
  • 83
0
votes
1 answer

JavaScript postfix a boolean / one-shot flag for throttling an event

I want to use a flag once, then convert it to false no matter what, after the expression returns the truthiness: var isProceding = true; someObject.addEventListener("someEvent", doOnce); // event fires many times function doOnce () { if…
neaumusic
  • 10,027
  • 9
  • 55
  • 83