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

[REBOL] Re: ROUND function (like TRUNC, FLOOR, etc...)

From: joel:neely:fedex at: 23-Feb-2002 11:06

Hi, Gabriele, Gabriele Santilli wrote:
> At 16.31 21/02/02, Joel wrote: > > >I can think of at least two simple ways: > > > > >> use [counter] [ > [...] > > This does not give you a direct reference to the context... > > The differences are very minor, but IMHO they justify the > choice of MAKE OBJECT! versus USE for CONTEXT... > > So, if you were to write a mezzanine to create a context, > which would you choose? Objects look like the most obvious > choice IMHO... >
Well, perhaps I understood the original question. I took create a context to mean constructing an environment with one or more words not in the global contxt, not in the sense of obtaining a "direct reference to the context"; I think we've both stated in various ways that REBOL doesn't really give a way to access contexts (per se) directly. As for your commeonts on the numbered list of things one could do with a first-class context, perhaps I didn't express sufficiently clearly that I considered them all to be inter- related. For example...
> >1) ask for the context of a specific word; > > That would be useful, but mainly only if you were able to > ask CONTEXT! what other words it has, and things like these; > i.e. only if it behaved like OBJECT!... >
No, sorry, I wasn't asking for object-like behavior.
> (Which is like asking RT to turn every CONTEXT! into an > OBJECT! --- pretty ironic conclusion for a thread that > started with "'CONTEXT is a confusing name for a function > that makes OBJECT!s". :) >
The very fact that I was unable to make the difference clear in what I was asking for demonstrates (to me at least) that the confusion/damage is already done.
> >2) use a context as the explicit second argument to BIND; > > If you already have a word bound to it... (Well, that said, > I'd like to have BIND accept at least OBJECT!s, to avoid that > extra IN, but even more to accept functions etc. to avoid all > the magic needed to get to it...) >
If contexts were first class, one *wouldn't* need a word that is already bound to it. That was my whole point. Let's put items (1) and (2) together and consider the following (imaginary) bit of REBOL: use [ini mini meini mo] [ ini: mini: meini: mo: none ; ; some functions that do interesting things, using ; those four "private" words to maintain state ; immm-namespace: func [] [get-the-context-of ini] ] Now I could say things like this: a-context-var: immm-namespace ; ; time passes... ; flarp a-context other-args... where flarp: func [ctxt [context!] ...] [ ; ; and somewhere down inside FLARP or the body of a ; function that FLARP evaluates... ; bind [ini] ctxt ; or if equal? ctxt get-the-context-of word-ref [...] ; or if defined-in-context ctxt some-word-ref [...] ;...
> >4) be able easily to ask whether two words belonged to the > > same context; > > That's a point. :) > > >5) ask whether a specific word belonged to a specific context; > > Two points. ;) > > >and so on ... Making contexts first-class would be consistent > >with the REBOL approach that "everything is just a value" and > >would likely help de-mystify some of the more interesting > >things that REBOL can do that can't even be *said* in some > >other languages. > > I agree here. (I second Ladislav in his desire to have all REBOL > types as first-class.) >
Being able to do (1) and keep the result, pass it as an argument, or whatever else one does with a first-class value, provides a simple way to do (4) and (5) in terms of the context itself, rather than having to keep around some specific word within the context. Therefore, I'm puzzled that we agree on the value of (4), (5), and the general issue of first-class-hood, and yet don't see (1) and (2) alike... -jn- -- ; sub REBOL {}; sub head ($) {@_[0]} REBOL [] # despam: func [e] [replace replace/all e ":" "." "#" "@"] ; sub despam {my ($e) = @_; $e =~ tr/:#/.@/; return "\n$e"} print head reverse despam "moc:xedef#yleen:leoj" ;