syntax

What does the “=>” in “rescue Exception => e” do?

左心房为你撑大大i 提交于 2021-01-27 16:42:15
问题 Given the example: def method_of_doom my_string = "I sense impending doom." my_string.ah_ha_i_called_a_nonexistent_method rescue NoMethodError => e: puts "PROBLEM: " + e.to_s rescue Exception: puts "Uhh...there's a problem with that there method." end On the line where it says: rescue NoMethodError => e: What is the '=>' doing? How is it different than this usage: module FighterValues BAMBOO_HEAD = { 'life' => 120, 'hit' => 9 } DEATH = { 'life' => 90, 'hit' => 13 } KOALA = { 'life' => 100,

Why does bash evaluate comparison of numbers lexicographically not numerically?

感情迁移 提交于 2021-01-27 13:32:49
问题 Could someone explain the following behavior of the " if " block of bash ? I use the following simple code check if the first_value is less than the second_value first_value=67 second_value=2 if [[ "${first_value}" < "${second_value}" ]]; then echo "Yes" else echo "No" fi The issue is If the second_value is 1,2,3,4,5,6,10,11,... the block will return "No" But if the second_value is 7,8,9 the block will return "Yes" (must be "No") The fix is to use " -lt " instead of " < " but I want to

When using `data.table`'s DT[ i , j, by], is it possible to set the column types before hand?

给你一囗甜甜゛ 提交于 2021-01-27 13:29:01
问题 I'm trying to calculating the correlation between two variables for multiple different groups (e.g. DT[, cor.test(var1, var2), group] ). This works great whenever I use cor.test(var1, var2, method = 'pearson') but throws an error when I use cor.test(var1, var2, method = 'spearman') . library(data.table) DT <- as.data.table(iris) # works perfectly DT[,cor.test(Sepal.Length,Sepal.Width, method = 'pearson'), Species] # Species statistic parameter p.value estimate null.value # 1: setosa 7.680738

redirect Javascript syntax errors and console.log to somewhere else

早过忘川 提交于 2021-01-27 13:26:53
问题 I'm trying to send whatever would normally appear in the javascript console to my own custom functions. I've tried the following window.console.error = window.console.debug = window.console.log window.console.log=mylog; function mylog(msg){ //send it somewhere just using alert as an example alert("log="+msg); } console.log("yo"); var x=y;//a syntax error Using the code above I only see the following alert "yo" In the console log I see "x is not defined" How do I redirect the syntax errors?

MySQL SELECT WHERE EQUALS syntax

大憨熊 提交于 2021-01-27 11:47:17
问题 I have a MySQL database table called Participant that looks something like this: (idParticipant) - (firstName) - (secondName) - (gender) - (dob) 118 John Dunne m 1944-04-01 117 Mary Delaney f 1955-05-03 116 Adam Bermingham m 1920-01-01 115 Eamonn Reilly m 1987-03-19 114 Aaron Duane m 1990-07-08 119 Sarah Calvin f 1977-07-17 When I use this query: SELECT * FROM `Participant` WHERE idParticipant = 118 OR 119; I think I should get the following result: 118 John Dunne m 1944-04-01 119 Sarah

MySQL SELECT WHERE EQUALS syntax

让人想犯罪 __ 提交于 2021-01-27 11:42:08
问题 I have a MySQL database table called Participant that looks something like this: (idParticipant) - (firstName) - (secondName) - (gender) - (dob) 118 John Dunne m 1944-04-01 117 Mary Delaney f 1955-05-03 116 Adam Bermingham m 1920-01-01 115 Eamonn Reilly m 1987-03-19 114 Aaron Duane m 1990-07-08 119 Sarah Calvin f 1977-07-17 When I use this query: SELECT * FROM `Participant` WHERE idParticipant = 118 OR 119; I think I should get the following result: 118 John Dunne m 1944-04-01 119 Sarah

Volatile variable in class: “expected unqualified-id before 'volatile'”?

。_饼干妹妹 提交于 2021-01-27 06:52:51
问题 I have two static volatile variables defined in my class ADC . The class is written as: (cropped to save space) #pragma once #include "../PeriodicProcess/PeriodicProcess.h" #include <stdint.h> #include <stdlib.h> class ADC { private: static inline unsigned char SPI_transfer(unsigned char data); void read(uint32_t tnow); static const unsigned char adc_cmd[9]; static volatile uint32_t _sum[8]; static volatile uint16_t _count[8]; public: ADC(); void raw(); void init(PeriodicProcess * scheduler);

Default parameter value undefined; is this a JavaScript Bug?

房东的猫 提交于 2021-01-27 06:46:25
问题 Below is a syntactically valid javascript program – only, it doesn't behave quite the way we're expecting. The title of the question should help your eyes zoom to The Problem Area const recur = (...args) => ({ type: recur, args }) const loop = f => { let acc = f () while (acc.type === recur) acc = f (...acc.args) return acc } const repeat = n => f => x => loop ((n = n, f = f, x = x) => // The Problem Area n === 0 ? x : recur (n - 1, f, f (x))) console.time ('loop/recur') console.log (repeat

Default parameter value undefined; is this a JavaScript Bug?

笑着哭i 提交于 2021-01-27 06:45:48
问题 Below is a syntactically valid javascript program – only, it doesn't behave quite the way we're expecting. The title of the question should help your eyes zoom to The Problem Area const recur = (...args) => ({ type: recur, args }) const loop = f => { let acc = f () while (acc.type === recur) acc = f (...acc.args) return acc } const repeat = n => f => x => loop ((n = n, f = f, x = x) => // The Problem Area n === 0 ? x : recur (n - 1, f, f (x))) console.time ('loop/recur') console.log (repeat

Name spaces in c++ and c

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-27 01:46:32
问题 Not that I would ever write the code like the following in my professional work, the following code is legal and compiles without warnings in c++ and c: #include <stdlib.h> typedef struct foo { int foo; } foo; foo * alloc_foo () { return (struct foo*) malloc(sizeof(foo)); } struct foo * alloc_struct_foo () { return (foo*) malloc(sizeof(struct foo)); } foo * make_foo1 (int val) { foo * foo = alloc_struct_foo (); foo->foo = 0; return foo; } struct foo * make_foo2 (int val) { struct foo * foo =