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

basics: meaning and uses of make object! vs. context

 [1/12] from: jason::cunliffe::verizon::net at: 10-Jun-2002 10:35


Hi I looked at Ladislav's amazing article http://www.sweb.cz/LMecir/contexts.html but it's still a bit beyond me .. Please can anyone provide an introductory explanation of the difference between make object! and "context"? ..hopefully then I can get back to studying Ladislav's essay. These both appear to do the same thing: o: make object! [ name: "jason" email: [jasonic--nomadics--org] sendme: func [message] [send email message] ] o: context [ name: "jason" email: [jasonic--nomadics--org] sendme: func [message] [send email message] ]
>> o/name
== "jason"
>> o/email
== [jasonic--nomadics--org]
>> o/sendme "hello"
Q1: Are they different, and if so How? Q2: Why/when/what determines which form to use..? thanks ./Jason

 [2/12] from: ammon:rcslv at: 8-Jun-2002 15:37


Hi, Use the SOURCE luke!
>> source context
context: func [ "Defines a unique (underived) object." blk [block!] "Object variables and values." ][ make object! blk ] HTH Ammon A short time ago, Jason Cunliffe, sent an email stating:

 [3/12] from: lmecir:mbox:vol:cz at: 10-Jun-2002 17:43


Hi Jason, you can do e.g. source context in the console and see, that the CONTEXT function is a kind of shortcut for make object!, which is a bit unlucky, because it may be misleading sometimes. HTH -L ----- Original Message ----- From: "Jason Cunliffe" Hi I looked at Ladislav's amazing article http://www.sweb.cz/LMecir/contexts.html but it's still a bit beyond me .. Please can anyone provide an introductory explanation of the difference between make object! and "context"? ..hopefully then I can get back to studying Ladislav's essay. ...snip...

 [4/12] from: joel:neely:fedex at: 10-Jun-2002 10:35


Hi, Jason, Jason Cunliffe wrote:
> Please can anyone provide an introductory explanation of the > difference between "make object!" and "context"? >
Merely the amount of typing.
>> source context
context: func [ "Defines a unique (underived) object." blk [block!] "Object variables and values." ][ make object! blk ] This is another example along the lines of the TO-FOO vs. MAKE FOO thread. -jn-

 [5/12] from: jason:cunliffe:verizon at: 10-Jun-2002 13:31


> source context > > in the console and see, that the CONTEXT function is a kind of shortcut for > make object!, which is a bit unlucky, because it may be misleading > sometimes.
It had me confused.. it sounded so much more complicated. But that only shows I have not learned to trust SOURCE fully yet. Q1: Are there any situations when source 'someword hides something? [LUKE??] Q2: If CONTEXT is just a typing shortcut, then what are people's preferences for readability, and why? thanks very much ./Jason

 [6/12] from: ammon:rcslv at: 8-Jun-2002 20:11


Hi again, Yes, there are times when the SOURCE hides things from you...
>> source make
make: native [ "Constructs and returns a new value." type [any-type!] "The datatype or example value." spec [any-type!] "The attributes of the new value." ] You see MAKE is a Native! It isn't done in REBOL code, but rather in the language REBOL is written in (C?) so SOURCE couldn't tell you if it wanted to. Other than that, SOURCE will hide nothing from you. Use the SOURCE, Luke! The SOURCE will not fail you... ;-) HTH Ammon A short time ago, Jason Cunliffe, sent an email stating:

 [7/12] from: lmecir:mbox:vol:cz at: 10-Jun-2002 23:36


Hi Jason, ----- Original Message ----- From: "Jason Cunliffe" ...snip... Q2: If CONTEXT is just a typing shortcut, then what are people's preferences for readability, and why? thanks very much ./Jason <<Ladislav>> Joel criticized the name of the function, because the meaning of the word context is already used in Rebol with different meaning (the whole Contexts article is discussing that). That is why some of us think, that the name may lead to confusions. -L

 [8/12] from: ingo:2b1 at: 11-Jun-2002 0:25


Hi Jason, Ammon, Ammon Johnson wrote:
> Hi again, > Yes, there are times when the SOURCE hides things from you...
<<quoted lines omitted: 9>>
> to. Other than that, SOURCE will hide nothing from you. Use the SOURCE, > Luke! The SOURCE will not fail you... ;-)
Unless it does, of course ...
>> a: make object! [ blk: [ print "HI" ] set 'f func [][ do blk ]] >> f
HI
>> source f
f: func [][do blk]
>> blk
** Script Error: blk has no value ** Near: blk This is an artificial example, of course, but it is not that uncommon that critical parts of a function are hidden in an object!. Especially once you start with /View. That said, 'source is always worth a try. Kind regards, Ingo

 [9/12] from: ingo:2b1 at: 11-Jun-2002 14:25


Now answering my own email ... Ingo Hohmann wrote:
> Ammon Johnson wrote: >> Use the SOURCE, Luke! The SOURCE will not fail you... ;-)
<<quoted lines omitted: 7>>
> ** Script Error: blk has no value > ** Near: blk
Of course, given Rebols inspection abilities, you _can_ get to the source:
>> second :f ; gives you the functions body
== [do blk]
>> second second :f ; the second element in the function body
== blk
>> get second second :f ; and, at last, the value of 'blk
== [print "HI"] Sometimes you need to dig a little ... Kind regards, Ingo

 [10/12] from: ammon:rcslv at: 9-Jun-2002 15:15


Hi,
>> a: make object! [ blk: [print 'Hi] set 'f func [] [do blk]] >> f
Hi
>> source f
f: func [][do blk] The little bit above is an actual cut and paste from a fresh REBOL/Command console on Linux RedHat 7.2 if you actually get something different somewhere else please let us know. I don't see what you are talking about, I didn't see any lost code. Source delivered to you EXACTLY what you asked for, the very source of 'f. What is the difference between the example above and the example below? (again this is from a fresh console)
>> set 'f func [] [do blk] >> blk: [print 'Hi]
== [print 'Hi]
>> source f
f: func [][do blk]
>> f
Hi basically nothing. In the previous example the Global word 'f was set when the spec block of 'a was evaluated by 'make. In this example f was set at the commandline. The reason that 'f does the value of a/blk in your example is because 'f was created in the *context* of a, or in other words the words within the 'a object are *local* to 'f. I am not sure what you were expecting to see when you typed "source f" at the commandline, but you saw the actual source of 'f. That said, I think that what you are refering to is the fact that when you pass a block to make as you did in your example the block is evaluated and any commands given are done, any values that are not assigned to words with in the spec block are lost for example.
>> a: make object! [
[ print "making a" ; this line will be lost [ a: does [print "making a"] ;this will not [ ] making a
>> source a
a: make object! [ a: func [][print "making a"] ]
>> mold a
== { make object! [ a: func [][print "making a"] ]}
>> form a
== "?object?"
>> probe a
make object! [ a: func [][print "making a"] ] Do you see what I am saying? SOURCE will even give you the the very SOURCE of an Object! (something I wasn't fully aware of) Go ahead, use the SOURCE faithfully it. It will not fail you LUKE! HTH Ammon PS thanks to your post, I found that you can create a global word that has a context different than the global context without using 'bind! Enjoy!! A short time ago, Ingo Hohmann, sent an email stating:

 [11/12] from: ingo:2b1 at: 11-Jun-2002 19:30


Hi Ammon, Ammon Johnson wrote:
>>>a: make object! [ blk: [print 'Hi] set 'f func [] [do blk]] >>>f
<<quoted lines omitted: 3>>
>> > f: func [][do blk]
<..>
> I don't see what you are talking about, I didn't see any lost code. Source > delivered to you EXACTLY what you asked for, the very source of 'f. What is
<<quoted lines omitted: 17>>
> expecting to see when you typed "source f" at the commandline, but you saw > the actual source of 'f.
You are right, there is no _basic_ difference, between the two. What I wanted to illustrate is, that you can't understand what 'f is doing, without knowing the content of 'blk. And the content of 'blk, in my example, is hidden in a different context, so 'source won't tell you about it. A real world example:
>> source request-date
request-date: func ["Requests a date." /offset xy][ if none? base [init] either offset [inform/offset date-lay xy] [inform date-lay] base ] Can you tell me what this function will be doing, from viewing the 'source output, alone? I guess not.
> That said, I think that what you are refering to is the fact that when you > pass a block to make as you did in your example the block is evaluated and
<<quoted lines omitted: 12>>
> a: func [][print "making a"] > ]
<..>
> Do you see what I am saying? SOURCE will even give you the the very SOURCE > of an Object! (something I wasn't fully aware of) Go ahead, use the SOURCE > faithfully it. It will not fail you LUKE!
Then, have you tried to 'source the 'a object! from above?
>> source a
a: make object! [ blk: [print 'Hi] ] (or probe, or whatever ...) Sometimes theres more to the SOURCE than meets the eye :o) Ingo P.S: probe req-funcs/reg-date ;to get the missing link for request-date.

 [12/12] from: ammon:rcslv at: 9-Jun-2002 18:34


Hi, Ok, in that sense, you are right. If you need to know the value of words that are given within the context of a function, source will not give that to you as it only appears as a word in the function. However you have shown me a very valuable tool for finding the value of a word that is within a function...
>> a: make object! [ blk: [ print "HI" ] set 'f func [][ do blk ]] >> get second second :f
[print "Hi"] Thanks!! Ammon A short time ago, Ingo Hohmann, sent an email stating:

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted