由买买提看人间百态

topics

全部话题 - 话题: eval
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
m******r
发帖数: 1033
1
来自主题: Programming版 - eval (expr, envir=, enclose=) 求解答
问题看似极其简单, 是从?eval抄录而来,略作修改。
ev <- function() {
a <- expression(x+y)
list(eval = eval(a ) )
}
tst.ev <- function(a = 7) { x <- pi; y <- 1; ev() }
tst.ev() #-> aa : 7, eval : 4.14
上面这个运行不通,如果加上第二个参数,parent.frame() 就可以了。
按照eval的定义:
Usage
eval(expr, envir = parent.frame(),
enclos = if(is.list(envir) || is.pairlist(envir))
parent.frame() else baseenv())
我不理解的地方是:如果我只指定一个参数,按照eval定义, R应该会默认如下:
eval(a, envir=parent.frame(), enclos = parent.frame())
因为我没有指定envi... 阅读全帖
k*******3
发帖数: 1909
2
来自主题: Programming版 - perl eval and if
为什么一定要单引号呢?
eval后面不是也可以用block吗?
下面链接说两种方法应该都可以啊
http://bbs.chinaunix.net/archiver/tid-484028.html
[code]
eval { 程序段 };
if ($@) { DOIT}
[/code]
[code]
eval ( 作为执行的字串 );
if ($@) { DOIT}
[/code]
y****i
发帖数: 5690
3
来自主题: BuildingWeb版 - Javascript Eval() and IE
Hi, who can help me with this:
str1 = "fieldtype"+typeindex;
vtype = document.query_viewtable.eval(str1).value;
I need to do some dynamic type checking with javascript by this. It works
well with Netscape but doesn't work in IE.
The error message is like "the object doesn't have such property or method".
I think it's the problem of eval(). Cuase the errors disappear if I use
vtype = document.query_viewtable.fieldtype1.value;
Who can kindly give me a hint?
Than
v**********s
发帖数: 125
4
eval(['save ',fname_out,' traj_up']);
典型的eval save结合。
然后出现
??? Error using ==> save
Variable '11' not found.
所有地方的这种保存功能都用不了。奇怪。
d*******2
发帖数: 340
5
来自主题: Computation版 - 请教一个关于eval的问题
请问 eval ( 'load neumann.dat;', 'neumann=[ ];' );
和 eval ( 'load neumann.dat; neumann=[ ];' );
有什么区别?
注释语句说前面一句的目的是 create an empty NEUMANN array if no Neumann file
is found.
哪位给讲讲,先谢了!
o******6
发帖数: 538
6
来自主题: Statistics版 - [合集] How to do %eval(1.5+0.1) in macro.
☆─────────────────────────────────────☆
careerchange (Stupid) 于 (Thu Mar 19 11:19:58 2009) 提到:
In a macro, it seems that %eval(1+2) is fine, but
not %eval(1.5+0.1). How to get 1.6 from 1.5+0.1
in macro (not in data step)? Thanks.
☆─────────────────────────────────────☆
careerchange (Stupid) 于 (Thu Mar 19 11:26:35 2009) 提到:
An example is as following. The first call of %dat1 works.
How to make the second call work?
%macro dat1(num);
data one;
x=&num.;
run;
proc print data=one; run;
%m
i*****f
发帖数: 578
7
来自主题: _Python版 - safe eval()
eval lets you to evaluate a string as an expression. If the string comes
from untrusted users, there could be a potential risk. The following two
articles give some hints on designing a safe eval().
http://lybniz2.sourceforge.net/safeeval.html
http://code.activestate.com/recipes/496746/
m**********o
发帖数: 148
8
在此之前teaching还不错的,但是最近两学期,同样的课,eval变差了。
仔细想想,好像课程设置没什么改变,主要是把考试从原来客观题主观题结合改成全部
客观题,50道选择题,一题两份,有时候为了偷懒不重复题避免作弊,甚至一个班25道
题,一题4分。
原来主观题,不管答的对不对都给点分,客观题就没有商量了,学生的分数变低,每次
考试后我不得不curve,但是不是绝对分数低,他们还是不happy?因为每次考试curve
太麻烦,我又想了个办法,直接把grading scale调低。记得有个女生看到60多分的卷
子,在我办公室就哭了。最后她还是得了B+
我一再强调考试只是一部分。。。
各位有经验的老师,看看,我的这个考试设置是不是问题很大?谢谢
k*******3
发帖数: 1909
9
来自主题: Programming版 - perl eval and if
==========================TryTiny.pl CODE BEGIN====================
#!/usr/bin/perl
use warnings;
use strict;
eval
{
my $i = $foo;
};
if ($@)
{
print "There is an error caught!!!!";
}
==============================CODE END=============================
想用上面代码测试perl错误捕捉,bash下运行显示
Global symbol "$foo" requires explicit package name at TryTiny.pl line 8.
Execution of TryTiny.pl aborted due to compilation errors.
为什么没有捕捉到错误运行print "There is an error caught!!!!";这句呢?
Thanks!
j*****a
发帖数: 436
10
来自主题: Programming版 - perl eval and if
#!/usr/bin/perl
use warnings;
use strict;
eval 'my $i = $foo;';
if ($@)
{
print "There is an error caught!!!!";
}
j*****a
发帖数: 436
11
来自主题: Programming版 - perl eval and if
eval block is used for run-time error, but your code is a compiler error.
k*******3
发帖数: 1909
12
来自主题: Programming版 - perl eval and if
Many thanks!
那eval 字符串能catch run time error吗?
r********d
发帖数: 23
13
save(fname_out,'traj_up')不就完了,用什么eval
f*****c
发帖数: 3257
14
来自主题: Programming版 - 包子求助matlab编程问题
一直不熟悉matlab语言,特别是循环问题,最近终于碰到大麻烦了,10个包子求助!
我用如下的代码,对38个国家的货币回报分别跟10个跨国公司的季度回报做资产组合,
但是写完这个代码,matlab居然停不下来了,请问各位大神,这是怎么回事?
----------------------------------
for y=1:38
%currency equity return
eval(['su',num2str(y),'=r',num2str(y),'-cost']); % net currency return
eval(['rr',num2str(y),'=zeros(q,s)']); % construct the whole currency return
matrix for (s+1) leverage
for i=1:s
for j=1:q
eval(['rr',num2str(y),'(j,i)=(su',num2str(y),'(j)-(fai(j,i)*leverage
(i)))/(1-leverage(i))']);
... 阅读全帖
p*****2
发帖数: 21240
15
来自主题: Programming版 - 感觉是时候认真看看vert.x了
真是出师不利呀。
vertx run server.js
Failed in deploying verticle
javax.script.ScriptException: Error: Cannot find module vertx in at
line number 125 at column number 6
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(
NashornScriptEngine.java:586)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(
NashornScriptEngine.java:570)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(
NashornScriptEngine.java:525)
at jdk.nashorn.api.scripting.Nashor... 阅读全帖
I**********s
发帖数: 441
16
最喜欢 wwwyhx的解法: recursive descent.
我也写了个, 用的是建造AST, 再evaluate AST. 应该相当完整了: 数字之前可以有+-
号, 中间可以有一个小数点. 数字和运算符号之间可以有空格. 可以使用+,-,*,/,^,以
及括号. 可以检测错误输入并报出错误位置. 就是比较长, 不适合面试用. 供大家参考.
#include
#include // for pow()
using namespace std;
struct Node {
double val;
char op;
int op_prec; // precedence of operator
int type; // 0 - operand, 1 - operator
Node * left;
Node * right;
Node(double _val, char _op, int _type) : val(_val), op(_op),
type(_type), lef... 阅读全帖
I**********s
发帖数: 441
17
最喜欢 wwwyhx的解法: recursive descent.
我也写了个, 用的是建造AST, 再evaluate AST. 应该相当完整了: 数字之前可以有+-
号, 中间可以有一个小数点. 数字和运算符号之间可以有空格. 可以使用+,-,*,/,^,以
及括号. 可以检测错误输入并报出错误位置. 就是比较长, 不适合面试用. 供大家参考.
#include
#include // for pow()
using namespace std;
struct Node {
double val;
char op;
int op_prec; // precedence of operator
int type; // 0 - operand, 1 - operator
Node * left;
Node * right;
Node(double _val, char _op, int _type) : val(_val), op(_op),
type(_type), lef... 阅读全帖
y****e
发帖数: 1012
18
ava.io.FileNotFoundException: cache.csv (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:212)
at java.io.FileWriter.(FileWriter.java:107)
at edu.uiuc.cs.datacenterplacement.location.DataCache.addValue(
DataCache.java:98)
at edu.uiuc.cs.datacenterplacement.location.CoordinatesManager.
searchLocationPostalCode(CoordinatesManager.java:73)
at sun.reflect.GeneratedMethodAc... 阅读全帖
z**********i
发帖数: 88
19
%LET B=428;
%LET B_F_A=%EVAL(%SYSFUNC(ROUND(&B.*.75*.95,1)));
%LET B_F_O=%EVAL(%SYSFUNC(ROUND(&B.*.75*.05,1)));
%LET B_O_A=%EVAL(%SYSFUNC(ROUND(&B.*.25*.95,1)));
%LET B_O_O=%EVAL(%SYSFUNC(ROUND(&B.*.25*.05,1)));
%LET C=22;
%LET C_F_A=%EVAL(%SYSFUNC(ROUND(&C.*.75*.95,1)));
%LET C_F_O=%EVAL(%SYSFUNC(ROUND(&C.*.75*.05,1)));
%LET C_O_A=%EVAL(%SYSFUNC(ROUND(&C.*.25*.95,1)));
%LET C_O_O=%EVAL(%SYSFUNC(ROUND(&C.*.25*.05,1)));
%PUT
&B_F_A &B_F_O &B_O_A &B_O_O &C_F_A &C_F_O &C_O_A &C_O_O;
DATA SIZE;
ARRA... 阅读全帖
w*****5
发帖数: 515
20
来自主题: Statistics版 - SAS macro question
晚上看了一点书,分析并总结一下。。不对的地方请大牛指出。
1)%if 其实调用了%eval()来判断表达式
2)%if &intercept le &thres_intp_l相当于%eval( &intercept le &thres_intp_l)
,这个不会出错,因为两个都是字符型,不会自动转换,但是比较结果可能不对。
3)%sysevalf(&intercept le &thres_intp_l)可以得出正确结果,因为%sysevalf(
expression)的结果是1或者0,因此%eval(1)=1, %eval(0)=0
4) 另外3个答案:
%if %sysevalf(&intercept+1) le %sysevalf(&thres+1) 对
%if %sysevalf(&intercept+0) le %sysevalf(&thres+0) 出错
%if %sysevalf(&intercept) le %sysevalf(&thres) 出错
这个比较有意思。因为%if()其实是调用了%eval()
因此,从结果中可以看出,%eval(a》b).如果 a和b是flo... 阅读全帖
s******r
发帖数: 1524
21
data score;
do score=1 to 88;
output;
end;
run;
%macro subgrp(set=,var=, grp=);
proc sort data=&set;by &var;run;
data _null_;set &set end=eof;
if eof then call symput ('total',_n_);
run;
%let step=%eval(&total/&grp);
%if %eval(&step*&grp) < &total %then %let step=%eval(&step+1);
%do i =0 %to %eval(&grp-1);
%let first_obs=%eval(&i*&step+1);
%let obs=%eval(&first_obs+&step -1);
data &set&i;set &set(firstobs=&first_obs obs=&obs);run;
%end;
%mend;
%subgrp(set=score,var=score, grp=5);
bz pls.
g****g
发帖数: 1828
22
来自主题: Linux版 - bash script真难看懂
这个我都快读晕了。
#!/bin/bash
# Light weight option parser for bash
#
abstract=""
usage="Usage: \${0##*/} [options] [arg1] [arg2] ..."
function Abstract()
{
abstract=$@
}
function Usage()
{
usage=$@
}
function Option()
{
eval "options=\"$options $1,$2,$3\""
eval "main_help=\"$main_help \t -$1,--$2\n\""
eval "main_help=\"$main_help \t $4\n\n\""
}
function OptionWithArgument()
{
ARGUMENT=`echo $3 | tr a-z A-Z`
eval "options_warg=\"$options_warg $1,$2,$3\""
eval "main_help=\"$main_help \t -$1 $ARGUMENT, --
w******p
发帖数: 166
23
I think lazy eval is okay, but it shouldn't be the default, whoever want to
have lazy eval just do their own thunks, and with any language that supports
pointer/reference.
By making it the default really confuses people about performance, and
invents problem that wasn't there before.
However, lazy eval seems essential for Haskell because it wants to be "pure"
, in that the function parameter evaluation orders doesn't matter for
deterministic calculations, and at the same time save duplicated eva... 阅读全帖
d****n
发帖数: 397
24
来自主题: JobHunting版 - 这个是不是leetcode的bug?
class Solution {
public:
int evalRPN(vector &tokens) {
int n;
n=tokens.size();
return eval(tokens,0,n-1);
}

int eval(vector& tokens, int i, int j) {
int k,l,n,v1,v2,v,np,nn;
n=j-i+1;
np=0;
nn=0;
if(n==1) return stringtovalue(tokens[i]);
else {
for(l=j-1;l>=i;l--) {
if(tokens[l]=="+"||tokens[l]=="-"||tokens[l]=="*"||tokens[l]
=="/") np++;
else nn+... 阅读全帖
l*********a
发帖数: 42
25
import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.eval.DataModelBuilder;
import org.apache.mahout.cf.taste.eval.RecommenderBuilder;
import org.apache.mahout.cf.taste.eval.RecommenderEvaluator;
import org.apache.mahout.cf.taste.impl.common.FastByIDMap;
import org.apache.mahout.cf.taste.impl.eval.
AverageAbsoluteDifferenceRecommenderEvaluator;
import org.apache.mahout.cf.taste.impl.model.GenericBooleanPrefDataModel;
import org.apache.mahout.cf.taste.impl.mo... 阅读全帖
z****s
发帖数: 192
26
我不是什么大牛,更不是什么“Big Cow”(大母牛?:))。俺只是一个Linux业余爱好
者而已。你问的问题我碰巧以前遇到过。相关命令也刚好经常用。
eval就是"evaluate"的意思。“dircolors ~/.dircolors”只是显示color定义,你的
当前Shell并没有真正执行它。但”eval `dircolors ~/.dircolors`“则是执行了“
dircolors ~/.dircolors”所显示的东东。这和你把“dircolors ~/.dircolors”显示
的东东贴到你的command line些再执行(hit return)是等价的。上次回复建议你把那
一行命令放到你的bashrc (suppose you are using bash as the login shell.)文件
里,这样你下次不用每次敲那行命令了。
关于eval可以参见以下链接。里面有个很好的十分简洁的例子。
http://www.unix.com/man-page/posix/1posix/eval/
h*****f
发帖数: 248
27
来自主题: Programming版 - Re: L 电面 (转载)
【 以下文字转载自 JobHunting 讨论区 】
发信人: henrysf (Henry), 信区: JobHunting
标 题: Re: L 电面
发信站: BBS 未名空间站 (Thu Oct 18 01:46:20 2012, 美东)
我写了以下的code, 之后就被拒了, 回信是说别的candidate写得比较好, 我还没看出
问题.
Additional requirements:
- The only operators you need to implement are +, -, *, and /.
However, your implementation should make it relatively easy to
add more operators.
- The calculator should accept floating point numbers and output
floating point numbers (i.e. when the input is 2 3 / the result
is 0.66667).
- ... 阅读全帖
l*********s
发帖数: 5409
28
来自主题: Statistics版 - Weird SAS macro bugs, 包子重谢!
I am having some very weird bug while trying to write a macro that can
expend the short hand notion like var1--var11 used in SAS.
The "shorthand" macro works fine on its own, but fails to work when called
by the "formula" macro. The error message seems to say that "the set
statement in the data step is not valid or not in proper order", what's
going on?
Many thanks!
////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////... 阅读全帖
M******a
发帖数: 6723
29
来自主题: Military2版 - 关于长波台和远程雷达的耗电量
http://www.sonicbbs.cc/index.php?threads/3793284/
本帖由 一级把总 于 2012-03-24 发布。版面名称:军事普及
一级把总
一级把总
上士
据说这两类都是耗电大户,能顶一个城市的电量。请问具体能达到多大?

一级把总, 2012-03-24
#1
独孤女侠
独孤女侠
少校
不太可能
反导警戒雷达也就峰值功率大几百千瓦的样子.
http://baike.baidu.com/view/7923665.htm

独孤女侠, 2012-03-24
#2
一级把总
一级把总
上士
金灿荣:我听说这样一个知识,长波台是很耗电的,一个非常好的长波台大消
耗量相当于半个宁波市。
尹卓:差不多。
尹卓,著名军事专家,少将军衔,海军专家委主任,总装科技委兼职委员、中
国国际战略学会研究员,《军情连连看》嘉宾... 阅读全帖
f******n
发帖数: 176
30
来自主题: Faculty版 - Just got evaluation back, so frustrated!
After you calm down, remember after, you go back and read your evaluation,
in the beginning of my career, i got not good eval, i was mad too, because i
thought i cared so much and worked so much, but later, actually one year
later, when i read it again, i DO found my own problem. There are outliers
there for students eval, but a good portion of it makes sense.
The thing is we thought we did so much and got such a bad eval. From the
students' point of view, they paid their tuition to learn from y
l***i
发帖数: 1309
31
来自主题: JobHunting版 - 问一道fb的面试题目
use two stack, one for operands and one for operator.
when you have a new operand, push into stack.
when you have a new operator, pop operator and operands already in stack,
eval, and push result into operand stack. Keep pop and eval until the
operator at top of stack is of lower precedence. In the end, pop and eval
until stack is empty. The result of expr is in operand stack
o*******4
发帖数: 313
32
来自主题: JobHunting版 - 问一个机器学习的问题
Split data 3 ways: train, eval, validation. Train & tune your model using
the validation set, and only use eval for evaluation, never tune parameters
on the eval set.
s**x
发帖数: 7506
33
来自主题: JobHunting版 - zenefits店面 -已挂了
Class Division : public Expression
{
Int eval() { return exp1->eval() / exp2->eval();}
Expression* exp1;
Expression *exp2;
}
d********9
发帖数: 38
34
用string形式给一个含有x,y,+,-,*,/,(, )以及double型数字的表达式,比如:
y = (2*x) + 3
要求写一个程序输出x的表达式: x = (y-3)/2;
其中x可能出现多次,比如:y = (x+5)/3 + x*4;
PS: 限制是y是linear in terms of x;
面试当时想的是先简化表达式,将所有含x的terms合并,然后parse这个string生成一
个以y为root的eval tree,然后找到x所在的node,将这个eval tree改造成以这个node
为root的eval tree,然后重建表达式,这样结果就会是x=ay-b之类的形式,不过
interviewer当时
不置可否,我当时也没写出来具体code,求大家帮忙看看有没有什么简明的解法。谢了。
d********9
发帖数: 38
35
我更新了下原帖:
面试当时想的是先简化表达式,将所有含x的terms合并,然后parse这个string生成一
个以y为root的eval tree,然后找到x所在的node,将这个eval tree改造成以这个node
为root的eval tree,然后重建表达式,这样结果就会是x=ay-b之类的形式,不过
interviewer当时
不置可否,我当时也没写出来具体code,求大家帮忙看看有没有什么简明的解法。
w******y
发帖数: 4871
36
来自主题: NextGeneration版 - 求点正能量,感觉娃要被劝退了
去Evaluate一下吧,psych eval, autism eval, general Peds developmental eval.

555
G********r
发帖数: 3161
37
你这就是典型的站着说话不腰疼。等你有个ASD的娃,你一定要坚持你家娃没病啊,不
要占用大家的资源,然后再来发表这个言论。
你怎么知道很多去Eval的孩子没问题?你有统计数据?你给我个数好了,全美多少孩子
去做了Eval,若干年后发现多少比例全正常?你再给我个数,有多少当初没有问题的孩
子去做了Eval被Label了,接受干预若干年后变成不正常的?你以为作家长的都是白痴
,自己的孩子明明没病偏要去找病?
M****o
发帖数: 13571
38
来自主题: Parenting版 - 特殊教育的一些事实和分析
是吗?但似乎必须得有legal guardian的签字才可以进行eval吧?我的意思是说,虽然
别人可以给家长指出也许小孩需要eval或推荐eval,但没家长最终签字,还是啥也不能
进行吧?
a****g
发帖数: 3027
39
来自主题: Parenting版 - 特殊教育的一些事实和分析
当时上过一个课程,讲到了任何人都可以推荐去做eval. 实际中,如果没有父母的同
意,我也认为不可能的。
所以前面讲了,父母最重要。

然: 别人可以给家长指出也许小孩需要eval或推荐eval,但没家长最终签字,还是啥也
不能: 进行吧?
M****o
发帖数: 13571
40
分享下我家的经验吧。
我娃快到三岁时,本州政府的ECI service说三岁后就不能再给服务了,但他们很负责
地帮我们联系了当地的小学做了speech eval,eval的结果是说娃符合去小学上Pre-K,
但他的程度不需要每天都去,于是安排他一周去三次,每次是三个小时。我第一次带娃
去学校时,看到有至少一男一女两个明显有down syndrome的小娃娃也在门口等着进去
上课。他们都穿的整整齐齐的,背着小书包,都很可爱的。:) (有点跑题了哈 :p)。
我开始觉得三岁的小娃就背着书包去上学了,挺好玩的,不过想到这不仅仅可以在语言
发展上帮助到娃,还可以帮他尽早适应比较正式的学校生活,觉得挺好的。这个公立小
学还挺正规的,对这些Pre-K的小娃也要求dress code。另外老师发的资料里有很详尽
的教学纲领、目标和进程,看的出来老师很负责尽心。每个星期都有每个星期的教学计
划,每个月有report card,上面有详细的对娃表现的评估,以及下一个阶段的goal。
在上Pre-K的同时,我们也带娃也去了这边很好的一个儿童医院的rehab center做私人
的therapy。他接受了P... 阅读全帖
m********r
发帖数: 811
41
abstract=""
usage="Usage: \${0##*/} [options] [arg1] [arg2] ..."
function Abstract()
{
abstract=$@
}
function Usage()
{
usage=$@
}
function Option()
{
eval "options=\"$options $1,$2,$3\""
eval "main_help=\"$main_help \t -$1,--$2\n\""
eval "main_help=\"$main_help \t $4\n\n\""
}
g****g
发帖数: 1828
42
来自主题: Programming版 - bash script真难看懂
【 以下文字转载自 Linux 讨论区 】
发信人: gengwg ( 注意:修改邮件后,需重新激活帐号.), 信区: Linux
标 题: bash script真难看懂
发信站: BBS 未名空间站 (Wed Jun 9 11:49:38 2010, 美东)
这个我都快读晕了。
#!/bin/bash
# Light weight option parser for bash
#
abstract=""
usage="Usage: \${0##*/} [options] [arg1] [arg2] ..."
function Abstract()
{
abstract=$@
}
function Usage()
{
usage=$@
}
function Option()
{
eval "options=\"$options $1,$2,$3\""
eval "main_help=\"$main_help \t -$1,--$2\n\""
eval "main_help=\"$main_help \t $4\n\n\""
}
function OptionWithArgume
b***e
发帖数: 1419
43
Lisp's expressiveness power is the strongest among the programming languages
. It is so close to lambda calculus such that everything and anything can
be encoded. JS is almost like that, where the only counter part that is not
found is the powerful macro system. "eval" is in fact very weak as
compared to macros. Not everything can be serialized and put in a string
that fits eval. If you turn to the help of variables in eval, then you lose
static binding. Not even mentioning the possibility... 阅读全帖
c*******9
发帖数: 9032
44
Macro虽强,但不是Lisp的最突出特征,很多语言都有很强的macro系统。lisp还是强在
s表达式的扩展性,也让eval在lisp中更有用。和macro比哪个更有用不好说,但楖念上
lisp的eval更完美。code生成code生成code用eval也能做到吧。

languages
not
lose
g.
K****n
发帖数: 5970
45
看,这就是google这个网站全部的源代码:
大哥大嫂过年好!
content="text/html; charset=UTF-8">Google