_ Rubyã§é 延è©ä¾¡ - delay, force, lazy æ£æ ¼è©ä¾¡ã®è¨èªã§æ示çã«é 延è©ä¾¡ãè¡ãæ¹æ³ã¨ãã¦ãSchemeã®delay/forceãããã Rubyã§å®è£ ããã¨ãããªæãã class Promise NULL = Object.new def initialize(&block) @value = NULL @block = block end def self.delay(&block) new(&block) end def force if @value == NULL @value = @block.call else @value end end end count = 0 x = Promise.delay { count += 1; 1 + 2 } p x.force #=> 3 p x.force #=> 3 p count #=> 1 ã¡ã¢åãã¦ã
{{#tags}}- {{label}}
{{/tags}}