我有一段代码给了我一个'表达结果未使用'警告.我不知道我做错了什么.请帮忙!
if(task.typeForThis.typeID == @"DivisionAT"){
probsPerDayLabel.hidden = NO;
whatToDoLabel.hidden = YES;
//int ppdi = task.probsPerDay;
//NSString *ppd = [NSString stringWithFormat: @"%i", ppdi];
probsPerDayLabel.text = @"Do %i problems today.",task.probsPerDay; //Right here
}
Run Code Online (Sandbox Code Playgroud) 我正在寻找用于评估波兰语前缀表示法中的表达式的递归解决方案,但没有找到,但是我找到了伪代码,我想将它转换为C++,但这很难.我写了大写字母,我不知道该怎么做.请纠正我,我是java家伙,对我来说C++是一团糟,但无法帮助它.
int preEval(stack<string> stos){
string el = "";
if(stos.empty()){
return 0;
}else if(stos.top() IS VALUE){
string el = stos.top();
stos.pop();
return atoi(el.c_str());
}else if(stos.top() IS OPERATOR){
int x = preEval(stos);
int y = preEval(stos);
return x OPERATOR y;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编辑
当我的表达式像/ 10 5应该堆栈假设有元素(从顶部)/ 10 5,或5 10 /?只是问,因为如果我想要它/ 10 5我必须以某种方式向后读取字符串.
可能重复:
优雅的链接'或'用于Ruby中相同变量的测试
answer="this" or answer = "that" 很罗嗦
我希望能够使用更像的表达式,answer =("this" or that")但我知道我不能使用该表达式作为or完成,然后将(true或false)结果与answer进行比较,这不是我想要的.更像是=〜[a/c],但我需要插值.
我只想要一个字段来允许所有类型的数字:整数,小数,负数......以及所述类型的所有组合.不需要逗号.
这是我与它斗争的最近3天:
/^[\.\-\d]*?$[1-9][\.\-\d]*?$/
Run Code Online (Sandbox Code Playgroud)
这不允许整数!我不明白哪里出了问题,有人可以解释一下如何做到这一点吗?
我有一个包含字母和数字的字符串列表.我想搜索这些数字并让它们归还给我.做这个的最好方式是什么?我是Python的新手,我查看了正则表达式,现在我正在学习它们,但我不知道在使用它们之前我的正则表达式是否足够好.
我是明确构建LINQ表达式的新手,我试图通过使用Aggregate和Expression.AndAlso来弄清楚如何将IEnumerable >>组合成单个Expression>.
我觉得我越来越近了,但我显然错过了一些东西.
public static Expression<Func<T, bool>> CombineExpressions<T>(
IEnumerable<Expression<Func<T, bool>>> expressions)
{
if (expressions == null || expressions.Count() == 0)
{
return t => true;
}
var combined = expressions
.Cast<Expression>()
.Aggregate((a, b) => Expression.AndAlso(a, b));
ParameterExpression pe = Expression.Parameter(typeof(T), "x");
return Expression.Lambda<Func<T, bool>>(combined, pe);
}
Run Code Online (Sandbox Code Playgroud)
当我调用此方法时,我得到以下异常:
System.ArgumentException:
Expression of type 'System.Func`2[SomeEntity,System.Boolean]'
cannot be used for return type 'System.Boolean'
Run Code Online (Sandbox Code Playgroud)
请帮忙!
以下功能适用于Chrome,FF和IE11.但是我不能让它在IE 10上工作.当我尝试拆分返回的字符串时,split返回undefined.
这是我的功能:
var now = new Date(), timezoneOffset;
timezoneOffset = now.toString().split('GMT')[1];
timezoneOffset = timezoneOffset.split(' ')[0];
timezoneOffset = timezoneOffset.substr(0, 3) + ':' + timezoneOffset.substr(3, 2);
return timezoneOffset;
Run Code Online (Sandbox Code Playgroud)
所以返回的值是:(根据您的位置,它可能会有所不同)
在小提琴上,您可以timezoneOffset = now.toString().split('GMT')[1];在IE10上看到错误后发出警报
是否可以通过以下方法获取TModelfrom 的实例Expression?
public void FooBar<TModel, TProperty> MyMethod(
Expression<Func<TModel, TProperty>> expression)
where TModel : ViewModel
{
ViewModel model = ???;
}
Run Code Online (Sandbox Code Playgroud) 请考虑方法:
private void FastMethod(string param)
{
}
private void SlowMethod<T>(Expression<Func<T>> expression)
{
}
Run Code Online (Sandbox Code Playgroud)
并进行以下测试:
[TestMethod]
public void Test()
{
var stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i < 1000000; i++)
{
this.FastMethod("TestContext");
}
TestContext.WriteLine("Fast time: " + stopwatch.ElapsedMilliseconds);
stopwatch.Restart();
for (int i = 0; i < 1000000; i++)
{
this.SlowMethod(() => this.TestContext);
}
TestContext.WriteLine("Slow time: " + stopwatch.ElapsedMilliseconds);
}
Run Code Online (Sandbox Code Playgroud)
输出是:
快速时间:4
慢时间:2249
http://i.imgur.com/eYcBfZX.png
我知道这是每100万个电话,所以这看起来可能不是一个严重的性能问题.
但是我希望有一些基于属性设置器中的表达式的逻辑,它们将会经常调用+我只是好奇.
这里有优化空间吗?(我无法摆脱Expression方法参数,基本上我需要做一些语法树解析.有趣的是解析本身足够快).
假设 - 派对商店希望根据其数据库中的条件选择人员.
数据库名称"BirthDays"字段:日,月,年
搜索实例的每个考虑因素都需要动态"where":
下面显然不起作用,因为它只考虑一个搜索实例,当有3或甚至10时:
query.Where(o => o.Day == 3 && o.Month == 4 && o.Year == 1997);
Run Code Online (Sandbox Code Playgroud)
我试着看看Expression和ParameterExpression,但无法绕过它.
[注] @Luaan是目前为止最接近的一个,加上"||" 不会解决#1.
expression ×10
c# ×4
lambda ×3
regex ×2
c++ ×1
evaluation ×1
function ×1
generics ×1
ios ×1
javascript ×1
jquery ×1
linq ×1
list ×1
objective-c ×1
parsing ×1
performance ×1
python ×1
ruby ×1