Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: with ?

From: al:bri:xtra at: 4-Dec-2000 17:28

Anton wrote:
> You know how other languages have a statement like this: > > with (obj){ > name = "object 1" > size = 23 > } > > which is to access elements of the obj object, without having to use a
path notation like: obj/name obj/size etc. Does rebol have anything like this? Yes.
> Could a function be built into an object that accepts a block of code and
does it inside the object, therefore no longer needing to explicitly refer to obj/name, just name, etc ? Yes.
> For example, if the special function is called 'with, the call would be
something like:
> obj/with [name: "object 1" size: 23] > > The code then gets done inside the object. This should be equivalent to: > > obj/name: "object 1" > obj/size: 23 > > It's not urgent, just interesting. (My little attempt just now failed. ->
with: func [code][do code])
>> o: make object! [
[ reverse_add: func [a b][print b - a] [ Dialect: func [Dialect [block!]] [ [ do bind Dialect in self 'self [ ] [ ]
>> o/Dialect [reverse_add 5 9]
4 See: http://members.nbci.com/AndrewMartin/Rebol/Units/HTML.r for a practical example. Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/