都達到同樣的事情 # let x = fun() -> begin print_endline "Hello"; 1 end;;
val x : unit -> int = <fun>
# x();;
Hello
- : int = 1
# let y = lazy begin print_endline "World"; 2 end;;
val y : int lazy_t = <l
我有以下代碼用於懶惰地計算python 3.5中的值。我也嘗試了@cached_propertydecorator,結果相同,所以我會用它來簡化。 class Foo:
@property
def expensive_object(self):
if not hasattr(self, "_expensive_object"):
print("