On 10/6/05, Gregg Irwin <[EMAIL PROTECTED]> wrote:
>
> Hi Glenn,
>
> GML>         How do I differentiate between static class methods and 'nor=
mal'
> GML> class methods?   Hmmm... that's not the right name... I mean to diff=
erentiate
> GML> between methods that don't require a 'self' pointer and those that d=
o.
>
> Welcome to REBOL! You got some answers already; Volker's being the
> concrete one you might expect in other language forums, while Sunanda
> and Tim started you on the REBOL path of "think differently". Coming
> from other languages to REBOL can be tough at times. To really
> leverage REBOL, you do need to think differently, and it doesn't work
> like all other languages, which is why it's a great tool to *add* to
> your arsenal. For some of us it *is* our arsenal. :)
>
> For an OO thinker, like yourself, it can take some time to relax and
> start thinking in terms of "data being evaluated" versus "classes and
> instances", but it's a good healthy way to stretch your mind, and a
> lot of fun to boot.
>
> It took me a while to adapt, and I'm still learning to "unthink"
> things, but the people here are great. Even after four years with
> REBOL, I'm amazed at what they can do and the insights they have.
>
> Happy REBOLing!
>
> -- Gregg
>
> --
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
>
>

Thanks :)
But actually that "other languages example" is the way more complex
rebol-stuff is build.
Thats why you often dump code and cant just paste it because something
is undefined.
And since Glen gave me a motivating thanks privately,
i thought since then how to explain more,
and here is an opportunity:


!> source focus
focus: func [
    "Focuses key events on a specific face."
    face
    /no-show
    /local tmp-face
][
    unfocus
    if not face [exit]
    focal-face: face
    if not string? face/text [
        face/text: either face/text [form face/text] [copy ""]
        face/line-list: none
    ]
    if not caret [caret: tail face/text]
    if none? face/line-list [
        if face/para [face/para/scroll: 0x0]
        caret: tail face/text
    ]
    if flag-face? face field [hilight-all face]
    if not no-show [show face]
]


paste the function in the console. Then:
!> focus face
** Script Error: caret has no value
** Where: focus
** Near: if not caret [caret: tail face/text]
if


Hu? Its from "the source"?!
Well, thats because focus is defined in system/view.
In the source-code, that is.
Its only later moved to the global context.
Now inside system/view we have interesting things:

!> probe first system/view
[self screen-face focal-face caret highlight-start highlight-end
title-size resize-border no-resize-border line-info VID event-port
debug pop-face pop-list wake-event window-feel popface-feel
popface-feel-nobtn popface-feel-away popface-feel-away-nobtn
popface-feel-win popface-feel-win-nobtn popface-feel-win-away
popface-feel-win-away-nobtn]

We find a 'caret here and a 'focal-face and some stuff more. :)


If i compare with OOP, i see some differences:

In classic OO each method has a this-pointer.
This allows the method to work implicitely with its object.

Now in REBOL each word has a this-pointer!
Sounds weird?
Until you try meta-programming the reverse way:
not building like we do with macros,
but cutting code in pieces like we do with dialect.

What please? OK:

instance: context[
 string: "Hello world"
 lay: [text string]
]
probe instance/lay
; prints: [text string]
view layout instance/lay
; shows: "Hello world"


Surely you note that 'string" is defined inside 'instance.
So how does 'layout know where it comes from?
And where is 'text?

Well, as i noted, each word has its own this-pointer.
This this-pointers (i love duping words! :)
is assigned when an object/context is constructed.
To each word which is defined in the object.

And dialects can take a word and access its value. In this context.


Lets try to make that visible.
I prepend words with their contexts and "~":

global~instance: global~context[
 instance~string: "Hello world"
 instance~lay: [global~text instance~string]
]
global~probe global~instance/instance~lay
; prints: [global~text instance~string]

I hope the magic fades. (Although fading magic is disappointing)

Well, going on: Now we have 'text left. Should be global, but

>> ?? text
** Script Error: text has no value
** Where: ??
** Near: mold name: get name

Not global? Actually it is, which is why it has no value. Hehe.
For now i tell only so much: no-value (unset!) is a value too.
Its a super-strong nil, which lets you not even access the content of a wor=
d.
Practically the word is not there, which is the intention.
'text in invisible cloaks.
There are some things though - but we all like magic, so i stop
talking about it :)

Ok, so there is no text.
But 'layout is a dialect, not a macros-expander.
Dialects cut code in pieces.
Sometimes they get the values of pieces, like with 'string.
Sometimes they use the word itself, in a switch or something.
Then words act like keywords, not variables.
This is what 'layout does with 'text, using it as a keyword.

!> source layout
[snip]

Waaah!!!

Well. layout is long. And old. Nobody understands it anymore.
Its partly older than 'parse for blocks, our best tool for dialects.
It - well, ok, but it works.

But not as example.
To keep the magic *and* have a hopefully usefull example, i wrote this:


instance: context[
 string: "Hello world"
 lay: [text string]
]
rule: [
 input: (print [newline "We parse " mold input "!"])
 any[
  'text (print "We see a text!")
  set word word!( print ["Its the word" word "! Its value is" mold get
word "!"] )
  |
  'text (print "We see the text again! We stuck here..")
  set value skip ( print ["Its" mold value "!"] )
  |
  set whats-this? skip ( print ["What do you mean with" mold whats-this? "?=
?"])
 ]
]
parse instance/lay rule
parse [foo text "Hello foo bar" bar] rule


Hope this is complicated enough.
Have fun with the magic wand. If not, ask here.

PS: I see i did not talk about "Why rebol is not oops, and how to
think different".
So much, as OOPis we can see it as patterns on stereoids.
So steroided it does not need much OOP any more. But healthy, though.
Alas, i wrote a lot for now.


--
-Volker

"Any problem in computer science can be solved with another layer of
indirection. But that usually will create another problem." David
Wheeler
-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to