相关疑难解决方法(0)

如何将动作传递给 javascript 函数

我可以解释我的问题,但证明它可能更容易......

如果您查看http://jsfiddle.net/XxT2B/,您会看到我的问题。我无法弄清楚如何将操作传递给函数。你会明白我的意思。

请注意,根据调用函数的内容,操作可能会有所不同。该动作可能是按时发出警报,然后是不同的内容。

这是我的代码...

function abc(action)
{
    //Do a bunch of stuff first and then do the action sent to this function
    alert('This function is named "abc"');

    //This is the part I do not know how to do.
    //The action might be an alert or something totally different so I can't just pass text
    //I need to know how to execute the action passed.
    action;
}

abc('alert("I like pizza")');
Run Code Online (Sandbox Code Playgroud)

javascript

2
推荐指数
1
解决办法
1942
查看次数

在clojure中,如何从地图绑定?

鉴于地图:

(def myMap {"a" 1 "b" 2 "c" 3 "d" 4 "e" 5 "f" 6})
Run Code Online (Sandbox Code Playgroud)

我希望用于let将每个键绑定到每个值.最简洁的方法是什么?

clojure

2
推荐指数
1
解决办法
100
查看次数

为什么在 lisp 中将代码视为数据很有用

我现在学习 emacs lisp,我想知道为什么将代码视为数据可能有用。这种方法有什么好处。我看到了一种解释,因为这是对数据和代码之间存在明确分离的传统冯诺依曼架构的替代方案。我想了解这个决定的含义,明白了。

提前致谢,尼克。

lisp emacs macros eval homoiconicity

2
推荐指数
1
解决办法
282
查看次数

如何从对象引用中读取插槽而不评估指针

我想从另一个对象内部的指针获取属性的值,但是在不评估引用的情况下访问它会使我出错

When attempting to read the slot's value (slot-value), the slot
POS is missing from the object *NODE-1*.
Run Code Online (Sandbox Code Playgroud)

这是一段模拟错误的代码:

(defclass node ()
  ((pos 
    :initarg :pos
    :initform '(0 0)
    :accessor pos)))

(defclass edge ()
  ((vertices
    :initarg :vertices
    :accessor vertices)))

(defparameter *node-1* (make-instance 'node))
(defparameter *node-2* (make-instance 'node :pos '(100 100)))
(defparameter *edge-1* (make-instance 'edge :vertices '(*node-1* *node-2*)))
Run Code Online (Sandbox Code Playgroud)

之后,评估此表达式将引发错误

(slot-value (car (slot-value *edge-1* 'vertices)) 'pos)
Run Code Online (Sandbox Code Playgroud)

但是这个有预期的行为

(slot-value (eval (car (slot-value *edge-1* 'vertices))) 'pos)
Run Code Online (Sandbox Code Playgroud)

我已经知道它eval可用于丑陋的骇客,这就是为什么我试图找到一种巧妙的方式来做我需要的事情的原因。

lisp evaluation symbols list common-lisp

2
推荐指数
1
解决办法
61
查看次数

Python不会eval()代码

我有以下eval()的东西:

c = Customer()
eval("c.name = row.value('customer', '{c}')".format(c=column_name), { 'c': c, 'row': row})
Run Code Online (Sandbox Code Playgroud)

当我尝试运行时,我得到了这个:

Traceback (most recent call last):
  File "./import.py", line 19, in <module>
    c = Customer.save_from_row(row)
  File "/home/jason/projects/mcifdjango/mcif/models/customer.py", line 43, in save_from_row
    eval("c.name = row.value('customer', '{c}')".format(c=column_name), { 'c': c, 'row': row})
  File "<string>", line 1
    c.name = row.value('customer', 'name')
           ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

编辑:因为看起来我没有充分解释我的问题的背景,这就是我最终做的事情,如果有人好奇的话:

@classmethod
def save_from_row(cls, row):
    c = cls()
    map(lambda column_name: setattr(c, column_name, row.value('customer', column_name)), c.distinguishing_column_names())
    return c.upsert()
Run Code Online (Sandbox Code Playgroud)

在我发现之前,我setattr()分别设置了几个不同的属性c.

python

1
推荐指数
1
解决办法
356
查看次数