---559023410-1251336619-1132154331	365
Content-Type: MULTIPART/MIXED; BOUNDARY="-559023410-1251336619-1132154331=:9365"

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

---559023410-1251336619-1132154331	365
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN
Content-Transfer-Encoding: QUOTED-PRINTABLE

On Thu, 17 Nov 2005, Robert Klemme wrote:

> Hugh Sasse wrote:
> > On Wed, 16 Nov 2005, Brian Schröäer wrote:
> >
> >> On 16/11/05, Hugh Sasse <hgs / dmu.ac.uk> wrote:
> >>> Any idea how to create or simulate a static variable in ruby?
> >>>
> >>> I want to create a variable to hold state between calls of a method,
> >>> but have the state disappear when the method goes out of scope.
> >>> I could create it in some external object but then I'd need to query
> >>> the scoping rules, and know where i was.
> >>>
> >>> I'm trying to do an instance_eval on a string containing a method
> >>>    such as do_this x,y,z {block}
> >>> and I want to evaluate the block, or not, as a function of some
> >>> state against which x,y,z are compared.  The code will be called
> >>> several times, but I only want the state intialized the first time
> >>> the scope
> >>> is entered.
> >>>
> >>> And, just to make matters worse, there could be several independent
> >>> calls to this method within the scope, each with its own separate
> >>> state.
> >>>
> >>> Maybe there's another way to do this?
> >>>
> >>>         Thank you
> >>>         Hugh
> >>>
> >>>
> >>
> >> I advise that you state your basic problem, as this seems to be a
> >> problem with an ugly workaround. You can probably restructure your
> >> problem such that this is no longer needed.
> >
> > I thought the paragraph about instance_eval explained it :-).
> >
> > Essentially, I have become fed up with lousy diagnostics from sed,
> > and have been trying to re-implement (enough of) it in Ruby, so I
> > hae some chance of getting the code to work. Thus I'd use code like:
> >
> >    within 10, 30 {
> >      sub(/this/, 'that')
> >      sub(/thingy/, 'the other')
> >      # Example of munging something akin to C comments
> >      within /^\s+\/\*/, /\*\/\s*$/ {
> >        rot13 # or something
> >      }
> >    }
> >
> > So I need to keep track of which patterns have matched, and clear
> > them when the scope (surrounding block) is gone.
> 
> Let's see whether I understand this correctly: you want your method
> "within" to create something that can be later thrown against the current
> line of the input and execute the given block only if the condition
> matches?  Wouldn't it be easier to just call within for each line of the
> input?

all the statements in the input language which I'm processing with
instance_eval (for now) would be called for each line of the input.
So when each one that must hold state is called for the first time
it must clear the state, for future calls to that function on that
source line, but later input lines, it must not "cold start" the
state. 

For within(), I'm trying to model sed's '/this/, /that/ { do_this}'
And I could have several withins in the same chunk of input
language.  

> 
> Kind regards
> 
>     robert
> 
        Thank you,
        Hugh
> 
> 

---559023410-1251336619-1132154331	365--
---559023410-1251336619-1132154331	365--