假设我有这样的情况:
;; Capture whatever the print word pointed to into a variable
outer-print: :print
foo: context [
;; within foo, override print and implement in terms of outer-print
print: func [value] [
outer-print "About to print"
outer-print value
outer-print "Done printing"
]
]
我可以这样做,或者如果我想从外部上下文中获得不止一件事,我可以明确地捕获它:
;; Capture current context into something called outer
outer: self
foo: context [
;; within foo, override print and implement in terms of outer/print
print: func [value] [
outer/print "About to print"
outer/print value
outer/print "Done printing"
]
]
这是正确的成语,还是有更好的方法?在某些情况下,这可能无法满足我的期望吗?