From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2002-04-03T16:55:09+09:00 Subject: Re: seeking to understand... In article , David Alan Black wrote: >Hello -- > >On Wed, 3 Apr 2002, Phil Tomson wrote: > >> class MyDesign < RHDL::Design >> >> def initialize() >> a = Signal.new(1) #signals have a current value and history >> b = Signal.new(1) >> >> define_behavior { >> c.assign {a or b} >> } >> end >> end >> >> The line: c.assign {a + b} >> makes use of a closure (the '{a + b}' is a Proc object which is what Ruby >> calls closures). [As a side note: Signal defines an 'assign' method that >> takes either an immediate value or a proc.] I don't want to assign the >> immediate value of (a or b) to c, I want to assign the function {a or b} >> so that it can be calculated later with varying values for Signals a and >> b. Using a Proc (which, remember, is a closure) allows me to do that. >> The function {a or b} (NOTE: '{..}' are used to construct Procs) can then >> be evaluated later each time the values of a and b have been changed. > >OK... but, in this example, how would you call the proc with different >values for a and b? > Sharp eyes David. There is no way to change a and/or b in this example. I left out some stuff out in an attempt to make it simpler. In a more complete example a and b would be added to a @inputs hash that that has accessors and you change the values by using Design's step method: md = MyDesign.new() md.step({'A'=>0,'B'=>0}) .... md.step({'A'=>1,'B'=>1}) I still haven't included everything that goes on, but I hope that gives you an idea... Phil