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

[REBOL] Control structures are mutable [was Annabelle Content Management System]

From: tim-johnsons::web::com at: 14-Sep-2007 9:41

On Thursday 13 September 2007, Sabu Francis wrote:
> Hi > Thanks for the code. That would be useful. Though I did not understand > how 'def works (Maybe it is in the scripts?). 'findall' does that and
In rebol - subroutines are mutable, I.E., they are produced by rebol code: In fact all sorts of control structures (such as 'every) can be 'hand rolled'. doing the following from the rebol console will prove very enlightening: help func source func help function source function help has source has help does source does Rebol's default is that words are global. Local words are 'declared' in the basic rebol subroutines. I find it *very* useful to have a subroutine that automatically generates local variables, since a type can create a 'leak' - thus the use of 'def. 'def is derived from code written by Andrew Martin and Ladislav Mecir I highly recommend that you look at Ladislav's rebol page at: http://www.fm.vslib.cz/~ladislav/rebol/index.html - you will find that he has written many custom control structures. Below is the code for 'def and its dependencies, contained in my user.r file: ;; -------------------------------------------------------------------------------------------------- make object! [ Find-Locals: function [Locals [block!] Body [block!] Deep [none! logic!]] [Value] [ parse Body [ any [ set Value set-word! ( if not found? find Locals Value: to word! :Value [ insert tail Locals Value ]) | set Value block! ( if Deep [ Find-Locals Locals Value Deep ]) | skip ] ] Locals ] set 'Fun function [ {Automatic local word generation for a function. Andrew Martin, Ladislav Mecir} Spec [block!] {Optional help info followed by arg words, optional type and string.} Body [block!] "The body block of the function." /Deep "Inspect block! values recursively for more local words." ][ Locals LocalRefinement ][ Locals: copy [] if found? LocalRefinement: find Spec /local [ insert Locals next LocalRefinement Spec: copy/part Spec LocalRefinement ] Find-Locals Locals Body Deep Locals: exclude Locals Spec function Spec Locals Body ] set 'Sub :Fun ] ;; end anonymous object def: sub[ {subroutine that automatically generates local words} Spec[block!] Body[block!]][sub/deep Spec Body] ;; ---------------------------------------------------------------------------------------------------------- cheers tim