expression

Prolog Prefix Expression

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 05:53:13
问题 I'm able to get the sum from the prefix expression but whenever I add a list within a list the program doesn't run. expr(Z) --> num(Z). expr(Z) --> [+], num(X), expr(Y), {Z is X+Y}. expr(Z) --> [-], num(X), expr(Y), {Z is X-Y}. num(D) --> [D], {number(D)}. calculate(L, M) :- expr(M, L, []). This works: calculate([+, 2, -, 9, 8], X] but calculate([+, 2, [-, 9, 8]], X] gives false. What do I need in order for it to work list inside of list? 回答1: very simple: ... expr(Z) --> [L], {calculate(L, Z

what does variableFoo && functionBar() do in javascript?

心已入冬 提交于 2019-12-24 05:46:21
问题 I have come across some Javascript code recently that looks like this: var foo = 'blah'; bar = function(){ // append some content to the body } doStuff = function(){ if(somethingIsTrue){ // do something } else { // do something else } foo && bar(); } doStuff(); The foo && bar() expression logs to the console as 'undefined'. I get why it might call the bar function to run from inside the doStuff function but why is it used as a comparison expression with the foo variable? 回答1: It means call

How to assign properties generically using Expression.Assign selector with target type of object?

人走茶凉 提交于 2019-12-24 05:21:46
问题 I am trying to use an Expression selector to generically assign properties from one type of object to another where the properties are of various types. This is the code I have so far: var type1 = new Type1(); var type2 = new Type2(); ... var propMap = new List<Tuple<Expression<Func<Type1, object>>, Expression<Func<TradeStaticAttributesItemModel, object>>>> { new Tuple<Expression<Func<Type1, object>>, Expression<Func<Type2, object>>>(x => x.Prop1, x => x.Prop1), new Tuple<Expression<Func

Building Expression Tree Using a Parameter's Indexer

点点圈 提交于 2019-12-24 05:15:17
问题 Given a class that has a property that is a Dictionary public class Product { public Dictionary<string, string> Attributes { get { return attributes; } } private Dictionary<string, string> attributes = new Dictionary<string, string>(); } I want to be able to match products in a list of products based on criteria that are retrieved from a data store that are in the format of Brand == Tyco Color != Blue My current approach is to construct an expression from the filter, and then pass that

Extract data PHP string

此生再无相见时 提交于 2019-12-24 04:47:05
问题 I have used file_get_contents() to basically get the source code of a site into a single string variable. The source contains many rows that looks like this: <td align="center"><a href="somewebsite.com/something">12345</a></td> (and a lot of rows that don't look like that). I want to extract all the idnumbers (12345 above) and put them in an array. How can I do that? I assume I want to use some kind of regular expressions and then use the preg_match_all() function, but I'm not sure how... 回答1

SQL script to SSIS expression

≡放荡痞女 提交于 2019-12-24 04:32:26
问题 I have the below T-SQL line of query that I'm trying to translate into Visual studio SSIS expression into derived column task. So tableA has just [Work item /Submission no#] column, but I need to split them into two column like SubmissionCommon and SubmissionNumber in TableB when below case is executed. CASE WHEN ISNUMERIC(SUBSTRING([Work item /Submission no#], 4, 2)) = 1 THEN LEFT([Work item /Submission no#], 15) ELSE LEFT([Work item /Submission no#], 16) END AS SubmissionCommon, [Work item

How to create “inline if statement” with expressions in dynamic select for null checking

两盒软妹~` 提交于 2019-12-24 03:31:03
问题 How to create "inline if statement" with expressions in dynamic select for null checking I was wrote a dynamic linq select expression for a nested property of a object, but it throw an exception when it is null. so i want to check whether that property is null or not, that simple ! here is what i mean: X.Where(...) .Select(X => new Y{ ... Z = X.Titles == null ? "" : [Linq] ... }).FirstOrDefault(); here is what i wrote private static Expression GetLocalizedString(Expression stringExpression,

How to create “inline if statement” with expressions in dynamic select for null checking

£可爱£侵袭症+ 提交于 2019-12-24 03:30:03
问题 How to create "inline if statement" with expressions in dynamic select for null checking I was wrote a dynamic linq select expression for a nested property of a object, but it throw an exception when it is null. so i want to check whether that property is null or not, that simple ! here is what i mean: X.Where(...) .Select(X => new Y{ ... Z = X.Titles == null ? "" : [Linq] ... }).FirstOrDefault(); here is what i wrote private static Expression GetLocalizedString(Expression stringExpression,

Using Expression to 'Cast' Func<object, object> to Func<T, TRet>

淺唱寂寞╮ 提交于 2019-12-24 02:14:57
问题 I've written a little function that attempts to do the following dynamically: Func<object, object> fa = i => Convert.ChangeType(i, typeof (string)); Func<int, string> fb = o => (string) fa((int)o); The func is as follows: /// <summary> /// Converts <see cref="Func{object, object}" /> to <see cref="Func{T, TResult}" />. /// </summary> public static Delegate Convert(Func<object, object> func, Type argType, Type resultType) { Contract.Requires(func != null); Contract.Requires(resultType != null)

Calculate square of value using NSExpression?

匆匆过客 提交于 2019-12-24 01:39:20
问题 NSString *formul=@"3^2"; NSExpression *e = [NSExpression expressionWithFormat:formul]; int result = [[e expressionValueWithObject:nil context:nil] intValue]; NSLog(@"formule:%d", result); I am trying to calculate (a+b)^2. 回答1: Use ** instead of ^ NSString *formul=@"3 ** 2"; NSExpression *e = [NSExpression expressionWithFormat:formul]; int result = [[e expressionValueWithObject:nil context:nil] intValue]; NSLog(@"formule:%d", result); But beware Foundation's power function is left associative