【发布时间】:2016-10-15 10:11:31
【问题描述】:
在这个简短的序列中,用户创建了一个函数userfunc(),但随后想要更新第一个定义来做一些不同的事情。但是programfunc() 已经编译了第一个版本,并继续使用它。
userfunc(str, n) = str ^ n
userfunc("hello", 3)
"hellohellohello"
# program makes use of the user's function
programfunc(func, a, b) = func(a, b)
programfunc(userfunc, "hello", 3)
"hellohellohello"
# now the user redefines the function
userfunc(str, n) = str ^ (n * n)
# userfunc("hello", 3) give "hellohellohellohellohellohellohellohellohello"
# but program still makes use of the first userfunc()
programfunc(userfunc, "hello", 3)
"hellohellohello"
那么如何定义programfunc(),使其始终使用传递给它的函数的最新定义?
【问题讨论】:
-
@GnimucK。啊,这是 2011 年的 #265。固定为 0.6?