expression

Passing expression through functions

蹲街弑〆低调 提交于 2019-12-22 06:35:24
问题 I'm using data.table package and trying to write a function (shown below): require(data.table) # Function definition f = function(path, key) { table = data.table(read.delim(path, header=TRUE)) e = substitute(key) setkey(table, e) # <- Error in setkeyv(x, cols, verbose = verbose) : some columns are not in the data.table: e return(table) } # Usage f("table.csv", ID) Here I try to pass an expression to the function. Why this code doesn't work? I've already tried different combinations of

How is the value of a begin block determined?

半世苍凉 提交于 2019-12-22 06:33:43
问题 According to The Ruby Programming Language p.164. If a begin statement doesn't propagate an exception, then the value of the statement is the value of the last expression evaluated in the begin , rescue or else clauses. But I found this behavior consistent with the begin block together with else clause and ensure clause . Here is the example code: def fact (n) raise "bad argument" if n.to_i < 1 end value = begin fact (1) rescue RuntimeError => e p e.message else p "I am in the else statement"

The dreaded “parameter was not bound in the specified LINQ to Entities query expression” exception

旧城冷巷雨未停 提交于 2019-12-22 05:42:07
问题 I am trying to get an understanding of expressions. I am hitting the dreaded "parameter was not bound in the specified LINQ to Entities query expression" exception. I have seen Skeet answer this before as well as others online. However I just cannot "see" the problem. I am using Colin Meek's example http://blogs.msdn.com/b/meek/archive/2008/05/02/linq-to-entities-combining-predicates.aspx and Matt Warren's VisitorExpression class http://blogs.msdn.com/b/mattwar/archive/2007/07/31/linq

Python - Evaluate math expression within string [duplicate]

青春壹個敷衍的年華 提交于 2019-12-22 04:32:38
问题 This question already has answers here : Evaluating a mathematical expression in a string (11 answers) Closed 5 months ago . I have a question concerning evaluation of math expression within a string. For example my string is following: my_str='I have 6 * (2 + 3) apples' I am wondering how to evaluate this string and get the following result: 'I have 30 apples' Is the any way to do this? Thanks in advance. P.S. python's eval function does not help in this case. It raised an error, when trying

Entity framework mapping enum : The specified value is not an instance of type 'Edm.Int32' Parameter name: value

ぃ、小莉子 提交于 2019-12-22 04:17:08
问题 I'm trying to return the result of a entity framework query into my own dto class, at the same time as mapping my enum TradeType. I'm getting the following error The specified value is not an instance of type 'Edm.Int32' Parameter name: value Any idea how to fix or a workaround? Thanks public IEnumerable<Trade> GetLiveTrades(string routeName) { return _entities.Price.Where(p => p.StatusCode.Equals("A") && p.Period.PeriodYear <= DateTime.Now.Year+1 && p.Route.RouteCode.Equals(routeName)).

regular expression to add characters before and after numbers

我怕爱的太早我们不能终老 提交于 2019-12-22 03:48:25
问题 I have a list of numbers between square brackets, and I need to add words before and after the exact numbers (i.e. keep the same numbers). I use notepad++ to replace, but if you have a solution with other program please advise. Example: text [121] othertext moretext [16] othertextmore andtext [5940] othertextplus outcome: text xxxxxxxxx [121] xxxxxxxxx othertext moretext xxxxxxxxx [16] xxxxxxxxx othertextmore andtext xxxxxxxxx [5940] xxxxxxxxx othertextplus The numbers are of course \d+ but I

Expression tree for a member access of depth > 1

一个人想着一个人 提交于 2019-12-22 01:36:52
问题 public class Job { public string Name { get; set; } public int Salary { get; set; } } public class Employee { public string Name { get; set; } public Job Job { get; set; } } If I want to create an expression tree of a member access to Employee.Name this is what I do: var param = Expression.Parameter(type, "x"); var memberAccess = Expression.PropertyOrField(param, memberName); return Expression.Lambda<Func<TModel, TMember>>(memberAccess, param); What is the equivalent to this for a member

Get part of the url pathname via JavaScript regex

▼魔方 西西 提交于 2019-12-21 21:29:10
问题 I have following url: https://www.example.com/article/f/1/test+article And I need to get "1" part from the url via JavaScript (pure javascript). I know that I can get it with "location.pathname.replace()" but I'm not good with regex. UPDATE Just for clarification: "https://www.example.com/article/f/" never changes, it's constant. The only part of the url that can change is "1" (article id) and "test article" (article name). And I want to catch the article id. 回答1: location.pathname.match(/\

python multiple regular expressions

♀尐吖头ヾ 提交于 2019-12-21 20:55:33
问题 I need to apply multiple regular expressions on a string which I'm doing like this: regex = re.compile("...") regex2 = re.compile("...") regex3 = re.compile("...") regex4 = re.compile("...") if regex.match(string) == None and regex2.match(string) == None and regex3.match(string) == None and regex4.match(string) == None: I was wondering if there is another way to somehow merge or combine the single regular expressions or if I'm already doing it the 'right way'? 回答1: r_list = [re.compile("...")

What is this assignment construct called? And can you do it in Php?

醉酒当歌 提交于 2019-12-21 19:59:21
问题 I have often used the following construct in Javascript: var foo = other_var || "default_value"; In Javascript, if the left side is falsy, then the value on the right side is assigned. It is very handy, and saves writing longer and unnecessarily explicit ternary expressions. Is there a name for this sort of construct ? Bonus: Is there a trick to do this in Php without using a ternary operator? PS: another variant is to throw an error if you don't get a truthy value, instead of giving a