1
如何定義返回最大值閉包的函數?返回最大值閉包的函數
我具體的例子: 我有以下形式的列表:
myList : [a = 1, c = 33, d = c+7];
我想exctract基礎上等號之前的部分元素。
這裏是我的嘗試:
find_a (e) := first(e) = a;
temp1 : sublist(myList ,'find_a);
map('second, temp1);
//output is "1"
這個工作,我打算。
由於真正的名單是更長的時間,我不想複製粘貼代碼, 我現在想用這樣的:
SearchElement(ElementName) := block(
[res],
res : lambda([x],first(x) = ElementName),
return (res)
);
GetByKey(list_,key_) := block(
[res , finder:SearchElement(key_)],
res : map('second, sublist(list_,'finder),
return (res)
);
GetByKey(myList, a);
// should return "1"
但已經是第一個部分不工作:
SearchElement(a);
// output:
lambda([x],first(x)=ElementName)
// expected output:
lambda([x],first(x)=a)
它是如何與Lisp的? – Ankur
maxima在內部使用lisp – Onur