include, require, yamm, ...
[1/3] from: weirddream::volny::cz at: 12-Aug-2000 17:48
Warning: This is a message in MIME format. Your mail reader does not
support MIME. Some parts of this message will be readable as plain text.
To see the rest, you will need to upgrade your mail reader. Following are
some URLs where you can find MIME-capable mail programs for common platforms:
Amiga............: YAM http://www.yam.ch/
Unix.............: Metamail ftp://ftp.bellcore.com/nsb/
Windows/Macintosh: Eudora http://www.qualcomm.com/
General info about MIME can be found at:
http://www.cis.ohio-state.edu/hypertext/faq/usenet/mail/mime-faq/top.html
--BOUNDARY.516289616.3
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Zdravim,
Maybe you need something like C/C++ 'include in REBOL. Maybe you've used
'include, 'yamm, 'require, 'evoke... But nothing is perfect. I think that
'require is most advanced example but it misses one VERY CRITICAL FEATURE -
paths to look in for script. So I've implemented it to 'require instead of
writing my own function. It is compatible with the old one except if you
'require script without path it looks for it in known paths. You can add to
them but you cannot save them - you have to edit the file manually. But I've
wrote it in one and half hour so you can call it QUICK-HACK.
I hope you'll find some bugs otherwise I'm perfect and there's no room to
improve myself :-)
Louci se
--
---------------------------------------------------------------
Boleslav Brezovsky, NOT know as Kryptoplex, maybe on [weirddream--volny--cz]
member of R.U.R (means RobotenUndRebol this week)
www.volny.cz/weirddream MUSIC&SOUND listen.to/sintezar
---------------------------------------------------------------
--BOUNDARY.516289616.3
Content-Type: text/plain; charset=iso-8859-1; name="require.r"
Content-Disposition: attachment; filename="require.r"
Content-Transfer-Encoding: quoted-printable
REBOL [
Title: "Script Requirements Manager"
Date: 12-Aug-2000
File: %require.r ; Used internally, see source for details.
Author: ["Brian Hawley" "REBolek"]
Email: [[brian--hawley--bigfoot--com][weirddream--volny--cz]]
Version: 0.1.1
Purpose: "Manages script dependencies and current versions"
Comment: trim/auto {
Require manages script dependencies in a way similar to
C/C++ #include but limiting inclusion to only a single time,
or optionally when the script has been modified. The list of
included scripts will be carried over if you do or require
%require.r again.
This script demonstrates a technique for implementing static
local variables, initialized using compose, and some other
fun tricks.
See http://www.bigfoot.com/~brian.hawley/rebol/ for updates.
---
Found it useful bud missed paths to read from. So I've added them.
}
History: [
0.1.1 "REBolek" {My first try to implement paths. They're static->
you cannot save them (real 'path can do it!) but you can
add to them. At least.}
]
Future: {It doesn't check for version for scripts searched in paths.
It reads first found script so I'll have to meake some fix or what.}
Category: [script advanced]
]
unprotect 'require
require: func [
"Runs a script or scripts if not included yet, or perhaps if new."
[catch]
scripts [file! url! block!] "The script(s) required."
/yet? "Check when a script has been included (none if never)."
/new "Update if script has changed."
/list-scripts "Return a copy of the list of included scripts."
/add-path "Adds new path to searched paths"
new-path "New path to add"
/local paths script-list stime iref itime e
] compose [
comment "List of paths to search in"
paths: [
system/options/home
path/daemon ;yes, you need 'path initialized for this.
]
comment "The list of included scripts, modified in place."
script-list: (
; Carry over existing list of included scripts, if any
if not all [
; Check for an existing list
block? require: try [require/list-scripts []]
; Test the integrity of the list
even? length? require: head require
foreach [f d] require [
either all [
any [file? :f url? :f] date? :d
] [true] [break/value false]
]
] [require: []]
; Add the current script to the list
use [f d] [
f: clean-path system/script/header/file
if date? d: try [modified? f] [
change any [find/last require f tail require] reduce [f d]
]
]
; Return the list
reduce [require]
)
; Handle list query operations, if any
if yet? [
return either block? scripts [none] [
pick any [
find/last script-list clean-path scripts tail script-list
] 2
]
]
; Deal with the single case
if not block? scripts [scripts: reduce [scripts]]
;I have to find the script in given paths
foreach script scripts [
if all [
file? script
none? find script #"/" ;pokud je zad=E1no pouze jm=E9no skriptu (ne cesta)
] [
foreach path paths [ ;je skript hled=E1n ve v=EEech cest=E1ch
if exists? join path script [ ; a kdy=F9 existuje
replace scripts script join path script ; je nahrazen za skute=E7nou lokaci
break ; po prvn=EDm n=E1lezu je konec
] ; cht=EBlo by to naj=EDt nejnov=EBj=EE=ED verzi.
]
]
]
; Include file/url list
foreach script scripts [
if all [
if any [file? :script url? :script] [script: clean-path script]
date? stime: try [modified? script]
any [
itime: none
none? iref: find/last script-list script
not date? itime: pick iref 2
all [new stime > itime]
]
] [
change any [iref tail script-list] reduce [copy script stime]
if error? set/any 'e try [do script] [
while [iref: find script-list script] [remove/part iref 2]
if date? itime [append script-list reduce [script itime]]
throw e
]
]
]
if list-scripts [return copy/deep script-list]
either add-path [append paths new-path] [exit]
]
protect 'require
--BOUNDARY.516289616.3--
[2/3] from: brian:hawley:bigfoot at: 14-Aug-2000 15:50
Boleslav Brezovsky ([weirddream--volny--cz]) wrote:
>Zdravim,
>Maybe you need something like C/C++ 'include in REBOL. Maybe you've used
<<quoted lines omitted: 7>>
>I hope you'll find some bugs otherwise I'm perfect and there's no room to
>improve myself :-)
I'll take a look at it. Already I can tell it's not reentrant,
and the paths don't preserve themselves when the script is done
again like the script list does. Should be easy to fix...
I designed the require function this way to be more bulletproof
when run in a long-running, server environment. It may seem to
be overkill for quick scripts, but even there the reentrancy is
essential in a script dependencies manager.
Would you prefer a single search path list, a default list with
the option to specify more paths, the option for a replacement
list, or specifying the list every time? I gave a lot of thought
to the API since the function was written to be used by people
who didn't know how to program well. Any subtleties in the style
of intended usage should be reflected in the interface.
Of course, require will need a rewrite when module support is
added to REBOL. It would probably be made obsolete by a proper
implementation of the Needs header option. The ongoing task...
Brian Hawley
[3/3] from: weirddream:volny:cz at: 16-Aug-2000 18:51
Nazdarek [brian--hawley--bigfoot--com]
yes I know, but I made it as quick hack I needed so it looks not very nice and
is not as clever as the rest of 'require. I have to think about it better -
looking for newest versions in given paths instead of loading first found
script , saving itself with new paths added... It will take time, but the WORD
was said - someone NEEDS paths :)
> I'll take a look at it. Already I can tell it's not reentrant,
> and the paths don't preserve themselves when the script is done
<<quoted lines omitted: 13>>
> implementation of the Needs header option. The ongoing task...
> Brian Hawley
Diky za pozornost,
--
---------------------------------------------------------------
Boleslav Brezovsky, NOT know as Kryptoplex, maybe on [weirddream--volny--cz]
member of R.U.R (means RobotenUndRebol this week)
www.volny.cz/weirddream MUSIC&SOUND listen.to/sintezar
---------------------------------------------------------------
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted