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

Library loader

 [1/5] from: andrew::martin::colenso::school::nz at: 24-Dec-2003 22:45


Here's my Library loader script: use [Patches Files Provided Do_Script Defer_Script Script Header Requires Provides] [ do Patches: %Patches.r Files: exclude read %./ reduce [Rebol/script/header/File Patches] Provided: make block! 100 Do_Script: [ do Script if all [ not none? Provides Provides: get Provides any [ word? Provides block? Provides ] ] [ insert tail Provided Provides ] true ] foreach File Files [ Defer_Script: [ insert/only tail Files Script ] Script: any [ if block? File [ File ] if all [ file? File found? find/last File %.r ] [ load/header File ] ] if Script [ Header: first Script Requires: in Header 'Requires Provides: in Header 'Provides any [ if none? Requires Do_Script if word? Requires: get Requires [ either found? find Provided Requires Do_Script Defer_Script ] if block? Requires [ either empty? exclude Requires Provided Do_Script Defer_Script ] ] ] ] ] It examines each script's header for the 'Requires and 'Provides fields, like (from my ML.r %script): Requires: [Build-Tag Push Pop] Provides: [ML] It doesn't attempt to do any versioning or downloading, just 'load-s and 'do-es scripts so that scripts that require words defined are 'do-ne after scripts that provide values for those words. For the above example, the files that provide 'Build-Tag, 'Push & 'Pop are 'do-ne before the file containing a value for 'ML. One problem the above script has, it that if a script requires a value for a word that no other script provides, the above function never returns. I haven't figured out a solution for this. Can anyone think of one? Andrew J Martin Attendance Officer Speaking in tongues and performing miracles. Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [2/5] from: antonr:iinet:au at: 12-Nov-2003 0:16


Pretty nice, straight-forward code. Just at the end, you might like to save a bit of code. If word? Requires [Requires: reduce [Requires]] Now you know it's a block and you can remove one if. Is the infinite loop because the script keeps getting deferred? Can you explain the flow in & out of the stacks you have a bit? Also watch out for load/header. In the rare case that you have a script with only a header in it, and no code following, load/header gives you the header object back directly, not in a block. Usually, you get a block with the header object in first position, followed by all the code. That bit me when I tried to process all my scripts using it. Anton.

 [3/5] from: greggirwin:mindspring at: 11-Nov-2003 8:58


Hi Anton, AR> If word? Requires [Requires: reduce [Requires]] AR> Now you know it's a block and you can remove one if. You can also use COMPOSE to blockify things: requires: compose [(requires)] -- Gregg

 [4/5] from: nitsch-lists:netcologne at: 11-Nov-2003 21:12


Am Dienstag, 11. November 2003 16:58 schrieb Gregg Irwin:
> Hi Anton, > > AR> If word? Requires [Requires: reduce [Requires]] > AR> Now you know it's a block and you can remove one if. > > You can also use COMPOSE to blockify things: > > requires: compose [(requires)] >
I guess its to direct, but how about requires: to-block requires ? ;)
>> to-block [1]
== [1]
>> to-block 1
== [1]
> -- Gregg
-Volker

 [5/5] from: antonr:iinet:au at: 12-Nov-2003 18:27


I think the problem is that the stack of files you maintain does not include any information about dependencies, so you can't check later that they have been provided for. The stack is a simple list of files that only tells you in what order to do them. Perhaps you can maintain two lists: - All-Provided: all the words provided by all the scripts - All-Required: all the words required by all the scripts then you can check if there are any missing by looking in exclude All-Required All-Provided . But if I were you, I'd probably redesign the algorithm and just rewrite it. It's short enough. Anton.