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

[REBOL] Re: Anchor? - A newbie question

From: jason:cunliffe:verizon at: 16-Oct-2002 13:44

Jan Kmunicek wrote:
> Is there a keyword or flag that allows direct jump > into a specific part of Rebol source code? Actually > I mean something like anchor in HTML. I probably > missed some basic thing in all the beginner's stuff.
Hi Jan Not sure quite what you are asking, so I apologize if my notes are already too obvious for your question. The 'switch' function can be useful to jumping to a certain piece of code based on conditions. Perhaps that's what you are looking for. If you mean like Basic's GOTO statements, then Rebol is not really meant to be approached like that. But it is very flexible. Rebol encourages you wrap everything up in well-named functions or objects. Objects can include functions and all sorts of logic detection and routing already available within them. You have to decide how much you want to create large sophisticated tools or lots of small modular ones. LEGO-style But blocks are the main tool for everything. So you can do something very simple like this:
>> someblock: [print "hello from someblock"]
== [print "hello from someblock"]
>> do someblock
hello from someblock
>> someinstruction: does someblock >> someinstruction
hello from someblock 'does is useful for defining simple deferred action. For example in REBOL/View when you want to adding action to buttons, you can define Rebol words using 'does.
>> ? does
USAGE: DOES body DESCRIPTION: A shortcut to define a function that has no arguments or locals. DOES is a function value. ARGUMENTS: body -- The body block of the function (Type: block) (SPECIAL ATTRIBUTES) catch Rebol blocks can be trivial like my example above or scale to large applications or big databases. In general, you probably want to combine create and combine your own functions and objects.
>> saysomething: func[][print "hello from someblock"] >> saysomething
hello from someblock The difference is that, unlike 'does, you can add function arguments..
>> saysomething: func[something[string!]] [print something] >> saysomething "say what you want"
say what you want or define a function which uses do inside to evaluate a block as input:
>> do-something: func[inblock[block!]] [do inblock] >> do-something someblock ; it's defined above
== hello from someblock and of course directly too
>> do-something [read %.]
== [%sys-port-drag-accept.r %sys-port-drag-accept.r.bak %ShellExecute.r %ShellExecute.r.bak] This is a pretty silly example in practice, but technique is important. In the above you'd likely want to do much more within the function for it to become useful. But not always, It can be often helpful to start by 'sketching', defining simple stub words with names which are meaningful to you and your application. Rebol encourages rapid continuous experiments in its console shell. cut'n' paste the results to a script file. Often that means do-ing blocks which later will be expanded and generalized. The Deep End of all this has been brilliantly covered by Ladislav Mecir hth ./Jason