From: Jean-Hugues ROBERT Date: 2004-04-29T23:33:20+09:00 Subject: Re: Pointers in Ruby At 21:59 29/04/2004 +0900, you wrote: >Hi -- > >Jean-Hugues ROBERT writes: > > > Hi, > > > > I am coining a Pointer class in Ruby. Kind of a C pointer, more > > like a C++ smart pointer actually. Should work for any lvalue. > > > > Any previous art ? > >Well, there's the fact that all variables in Ruby are already >references :-) So you can do things like: > > e = ENV > e["USERNAME"] = "Ruby" > p ENV["USERNAME"] # "Ruby" > >Can you give an example of something you would need the extra layer >of reference for? > > >David > >-- >David A. Black >dblack@wobblini.net "Any problem in computer science can be solved with another level of indirection." - David Wheeler. See http://c2.com/cgi/wiki?ButlerLampson I need that Pointer class to implement a more complex one called LogicVariable. A logic variable potentially references a regular variable and provide addition behavior. Mainly a "match(a,b)" method. Match does Prolog style pattern matching. A LogicVariable can be either bound to some value, or free. When it is free it acts as a wild card and will be assigned whatever value matches in the other parameter of match. Example: def test() a = [[1],"z"] b = 0 logic_b = LogicVariable.new( ref{":b"}) logic_b.free! match( a, [[logic_v],Free]) p b # => 1 I need the pointer to assign b as a side effect of match(). lvalues are one of the few things that are not objects in Ruby (yet), which is why I needed a special class to manipulate them. Yours, Jean-Hugues ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17