[REBOL] [REBOL]Advice in using global values
How do I make a value global? That is, so that it can be "seen" by any code in a file, include user-define functions? I would also welcome advice as to the pro and cons of using globals, as well as when best to use them, and what under what circumstances where such usage would be a bad idea. thank in advance. tim At 01:19 PM 4/2/00 -0700, you wrote: >Hi t, > >A file! type is a filename with a leading % character. Example: %myfile.r >%/c/mydir/. A file! may be any type of file, including a directory. > >A port! datatype is a low-level i/o abstraction that REBOL uses to >serialize different types of i/o channels, such as files (here we are not >talking about the filename, but access to the file's contents), and socket >i/o. > >The access to ports is typically controlled by protocols that define how >information is read and written to a port, and also commonly implement some >convenient navigation functions for the port's datastream, such as first, >next, insert, pick, etc. These functions work in a sensible way on a port! >datatype. They enable you to treat ports as though they were series values >(i.e. blocks, paths, hashes ...) to a degree, hence the term serialize is >used to describe this type of access to i/o channels. > >There are some limitations, since not all ports lend themselves to being >treated as a series effectively with respect to all series! functions. > >I haven't been following this thread, so I don't know why you are using >ports. Generally speaking, it is often more convenient to use higher level >functions when dealing with files, then accessing them as ports. read, >write, read/lines, write/append write/lines, write/append/lines, save, >load, come to mind. All of these functions take a filename (type file!), >and do not require that you manage the file on the port level, for instance >with respect to positioning, etc. > > >Hope this helps. > > > >;- Elan >> [: - )] > >
[REBOL] [REBOL]Problem with function argument Re:(4)
Thanks Elan: Your discussion is very helpful. As to your question: >I haven't been following this thread, so I don't know why you are using >ports. Generally speaking, it is often more convenient to use higher As to the above, I want re-usable code that will allow me to easily write to a file OR to standard output. My approach is to set up a value that could point EITHER to a file or to standard output. EX: in C: FILE *f; if(write_to_file) f = fopen("test.txt","w") else f = stdout; fprintf(f,"line one"); That in part is my choice of using ports. Part of that is circumstance, as well, perhaps the upper level functions would be better, given this need. I would welcome your advice. As well, I come from the c/c++/assembler background, I try to think in terms of minimizing machine overhead. I do primarily CGI programming, and like to use the same code to do either web content or send that web content to file. Either for testing purposes or in case a client wants me to enable him/her to build or update a page on the machine end. Keep up the good work Elan, you are always helpful. tim At 01:19 PM 4/2/00 -0700, you wrote: >Hi t, > >A file! type is a filename with a leading % character. Example: %myfile.r >%/c/mydir/. A file! may be any type of file, including a directory. > >A port! datatype is a low-level i/o abstraction that REBOL uses to >serialize different types of i/o channels, such as files (here we are not >talking about the filename, but access to the file's contents), and socket >i/o. > >The access to ports is typically controlled by protocols that define how >information is read and written to a port, and also commonly implement some >convenient navigation functions for the port's datastream, such as first, >next, insert, pick, etc. These functions work in a sensible way on a port! >datatype. They enable you to treat ports as though they were series values >(i.e. blocks, paths, hashes ...) to a degree, hence the term serialize is >used to describe this type of access to i/o channels. > >There are some limitations, since not all ports lend themselves to being >treated as a series effectively with respect to all series! functions. > level >functions when dealing with files, then accessing them as ports. read, >write, read/lines, write/append write/lines, write/append/lines, save, >load, come to mind. All of these functions take a filename (type file!), >and do not require that you manage the file on the port level, for instance >with respect to positioning, etc. > > >Hope this helps. > > > >;- Elan >> [: - )] > >
[REBOL]
unsubscribe
[REBOL] Newbie question #2 - Pattern making and using? Re:(11)
Hi Gabriele, thanks for posting this to the mailing list. In general I would appreciate it if questions that are probably of general interest be posted to the mailing list, since we can all learn from the questions as well as the answers. At 12:00 PM 4/2/00 +0200, you wrote: >Hello jb! > >On 01-Apr-00, you wrote: > >[Forwarding to the list] > > j> Gabrielle, > >Just one "l"... :-) > > j> For the past two months when I have the time to review the > j> rebol posts, I've appreciated reading your succint, thoughful > j> and clear examples. Thankyou. Your method outlined below is a > j> fine example of this. You are both an excellent teacher and > j> certainly you must be a world class programmer ! :-> > >Thank you. You're surely exaggerating --- I'm just a student! :) > > j> Perhaps you will be so kind as to provide urls for the best > j> examples of pattern matching techniques for REBOL? For > >I think you can find a lot of examples on rebol.org. I've written >a site-saver too (downloads an HTML document plus all of the links >etc.); it still needs some work, so I didn't publish it yet, as >you can get a couple of other script doing the same job on >rebol.org, but if you're interested... > > j> example, let's assume a useful utility will crawl through a > j> web site and gather only the links on the site saving them to > j> a file, how does a good rebol programmer think about and then > j> execute the following: > > j> find all instances of the following pattern > j> http://yy.yyy/ ( ie any and all urls in a web page.) > j> and return and then store only the http://y.yyy portion to > j> a file appending a newline to each ? > >If you assume that the initial "http://" is always present, as >well as the "/" after the domain name, the task is really easy: > > file-port: open/lines %destination-file.txt > parse text-containing-links [ > any [ > to "http://" copy url ["http://" to "/"] > (insert tail file-port url) > ] > ] > close file-port > >If you just want to assume that the URLs begin with "http://": > > url-rule: ["http://" some domain-chars] > domain-chars: complement charset [#"^(00)" - #" " #"/"] > parse text-containing-links [ > any [ > to "http://" copy url url-rule > (insert tail file-port url) > ] > ] > > j> Now with perl the matching expression is relatively short and > j> the assignment of the value is rather straight forward as well > j> as the printing to a append the file. > > j> Feel free to forward this letter to the list with your > j> response. I'd love to see how others will answer it. > > j> TIA, > j> JB > > j> PS > j> *I'm replying off list because my temporary isp doesn't > j> forward my mail when I use my subscribed email account. > >Regards, >Gabriele. >-- >o) .-^-. (--o >| Gabriele Santilli / /_/_\_\ \ Amiga Group Italia --- L'Aquila | >| GIESSE on IRC \ \-\_/-/ / http://www.amyresource.it/AGI/ | >o) `-v-' (--o > > > > ;- Elan >> [: - )]
[REBOL] [REBOL]Problem with function argument Re:(3)
Hi t, A file! type is a filename with a leading % character. Example: %myfile.r %/c/mydir/. A file! may be any type of file, including a directory. A port! datatype is a low-level i/o abstraction that REBOL uses to serialize different types of i/o channels, such as files (here we are not talking about the filename, but access to the file's contents), and socket i/o. The access to ports is typically controlled by protocols that define how information is read and written to a port, and also commonly implement some convenient navigation functions for the port's datastream, such as first, next, insert, pick, etc. These functions work in a sensible way on a port! datatype. They enable you to treat ports as though they were series values (i.e. blocks, paths, hashes ...) to a degree, hence the term serialize is used to describe this type of access to i/o channels. There are some limitations, since not all ports lend themselves to being treated as a series effectively with respect to all series! functions. I haven't been following this thread, so I don't know why you are using ports. Generally speaking, it is often more convenient to use higher level functions when dealing with files, then accessing them as ports. read, write, read/lines, write/append write/lines, write/append/lines, save, load, come to mind. All of these functions take a filename (type file!), and do not require that you manage the file on the port level, for instance with respect to positioning, etc. Hope this helps. ;- Elan >> [: - )]
[REBOL] [REBOL]Problem with function argument Re:(2)
Hi Ladislav: Thanks, you got it! All I was doing was using the wrong data type in the function arg. Obviously, I am not entirely clear about the distinction between "port" and "file" data types. Can anyone enlighten me, or point me to the documentation that will clarify for me? regards :>) tim At 11:13 AM 4/2/00 +0200, you wrote: >Hi, > >- Puvodní zpráva - >Od: <[EMAIL PROTECTED]> >Komu: <[EMAIL PROTECTED]> >Odesláno: 2. dubna 2000 7:33 >Predmet: [REBOL] [REBOL]Problem with function argument > > >> Hello All: >> >> I am getting an error message when attempting >> to pass a value as a argument to a user-defined >> function: >> >> the error message is: >> fprint expected fp argument of type: file. >> ** Where: fprint fp "line one" >> >> code follows: thanks in advance to all!! >> tim >> >> ; first the function >> fprint: func [fp[file!] value[string!]] >> [ >> either not-equal? fp none >> [ >> write/append fp value >> write/append fp newline >> ] >> [ print value ] >> ] >> fp: none >> ; check for server name in cgi environment variables >> either equal? system/options/cgi/server-name none >> > >>; value is empty, presume the script is run from commad line >>print "no server name, application run from console" >>fp: open/new/write %hello.htm >> ] >> ; script is invoked via server, yes, I know we need >> ; a content-header string, etc here. >> > >> prin "Server name: " >> print system/options/cgi/server-name >> ] >> ; call function >> fprint fp "line one" ; rebol doesn't like this >> ; if the file has been opened, close it >> if not-equal? fp none [close fp] >> > >The header of your function should probably be as follows: > >fprint: func [fp[port! none!] value[string!]] > >to allow open ports and none as the valid arguments. > >Moreover, the following: > >> either not-equal? fp none >> [ >> write/append fp value >> write/append fp newline >> ] >> [ print value ] >> ] > > >will not work for ports. You can change it to: > >either fp [ >append fp value >append fp newline >] [print value] > >Regards, >Ladislav > > >
[REBOL] Re: Newbie question #2 - Pattern making and using? Re:(9)
Hello jb! On 01-Apr-00, you wrote: [Forwarding to the list] j> Gabrielle, Just one "l"... :-) j> For the past two months when I have the time to review the j> rebol posts, I've appreciated reading your succint, thoughful j> and clear examples. Thankyou. Your method outlined below is a j> fine example of this. You are both an excellent teacher and j> certainly you must be a world class programmer ! :-> Thank you. You're surely exaggerating --- I'm just a student! :) j> Perhaps you will be so kind as to provide urls for the best j> examples of pattern matching techniques for REBOL? For I think you can find a lot of examples on rebol.org. I've written a site-saver too (downloads an HTML document plus all of the links etc.); it still needs some work, so I didn't publish it yet, as you can get a couple of other script doing the same job on rebol.org, but if you're interested... j> example, let's assume a useful utility will crawl through a j> web site and gather only the links on the site saving them to j> a file, how does a good rebol programmer think about and then j> execute the following: j> find all instances of the following pattern j> http://yy.yyy/ ( ie any and all urls in a web page.) j> and return and then store only the http://y.yyy portion to j> a file appending a newline to each ? If you assume that the initial "http://" is always present, as well as the "/" after the domain name, the task is really easy: file-port: open/lines %destination-file.txt parse text-containing-links [ any [ to "http://" copy url ["http://" to "/"] (insert tail file-port url) ] ] close file-port If you just want to assume that the URLs begin with "http://": url-rule: ["http://" some domain-chars] domain-chars: complement charset [#"^(00)" - #" " #"/"] parse text-containing-links [ any [ to "http://" copy url url-rule (insert tail file-port url) ] ] j> Now with perl the matching expression is relatively short and j> the assignment of the value is rather straight forward as well j> as the printing to a append the file. j> Feel free to forward this letter to the list with your j> response. I'd love to see how others will answer it. j> TIA, j> JB j> PS j> *I'm replying off list because my temporary isp doesn't j> forward my mail when I use my subscribed email account. Regards, Gabriele. -- o) .-^-. (--o | Gabriele Santilli / /_/_\_\ \ Amiga Group Italia --- L'Aquila | | GIESSE on IRC \ \-\_/-/ / http://www.amyresource.it/AGI/ | o) `-v-' (--o
[REBOL] [REBOL]Problem with function argument Re:
Hi [EMAIL PROTECTED]: when you do an 'open, you don't get a file!, but a port. so change your func this way: fprint: func [fp[port!] value[string!]] [ either not-equal? fp none [ ; thou canst write on a port, just append ... append fp value append fp newline ] [ print value ] ] regards, Ingo -- _ ._ ingo@)|_ /| _| _ ingo@| |(_|o(_)| (_| http://www.2b1.de/Rebol/ ._| ._|
[REBOL] [REBOL]Problem with function argument Re:
Hi, - Puvodní zpráva - Od: <[EMAIL PROTECTED]> Komu: <[EMAIL PROTECTED]> Odesláno: 2. dubna 2000 7:33 Predmet: [REBOL] [REBOL]Problem with function argument > Hello All: > > I am getting an error message when attempting > to pass a value as a argument to a user-defined > function: > > the error message is: > fprint expected fp argument of type: file. > ** Where: fprint fp "line one" > > code follows: thanks in advance to all!! > tim > > ; first the function > fprint: func [fp[file!] value[string!]] > [ > either not-equal? fp none > [ > write/append fp value > write/append fp newline > ] > [ print value ] > ] > fp: none > ; check for server name in cgi environment variables > either equal? system/options/cgi/server-name none > >; value is empty, presume the script is run from commad line >print "no server name, application run from console" >fp: open/new/write %hello.htm > ] > ; script is invoked via server, yes, I know we need > ; a content-header string, etc here. > > prin "Server name: " > print system/options/cgi/server-name > ] > ; call function > fprint fp "line one" ; rebol doesn't like this > ; if the file has been opened, close it > if not-equal? fp none [close fp] > The header of your function should probably be as follows: fprint: func [fp[port! none!] value[string!]] to allow open ports and none as the valid arguments. Moreover, the following: > either not-equal? fp none > [ > write/append fp value > write/append fp newline > ] > [ print value ] > ] will not work for ports. You can change it to: either fp [ append fp value append fp newline ] [print value] Regards, Ladislav
[REBOL] Redirecting CGI Content Re:(5)
> I tested it before a while and it works: > (I've subdirectory REBOL with index.html) > > print "Location: REBOL/index.html^/" > > Regards, > Jan Thank you very much, exactly what I needed! Regards, Rachid
[REBOL] [REBOL]Problem with function argument Re:
>> do %test.r no server name, application run from console ** Script Error: fprint expected fp argument of type: file. ** Where: fprint fp "line one" if not-equal? >> type? fp == port! > fprint: func [fp[file!] value[string!]] >> port! = file! == false I hope that helps. Andrew Martin Awakening the dragon... (in another universe) :-) ICQ: 26227169 http://members.xoom.com/AndrewMartin/ -><- - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, 2 April 2000 5:33 PM Subject: [REBOL] [REBOL]Problem with function argument > Hello All: > > I am getting an error message when attempting > to pass a value as a argument to a user-defined > function: > > the error message is: > fprint expected fp argument of type: file. > ** Where: fprint fp "line one" > > code follows: thanks in advance to all!! > tim > > ; first the function > fprint: func [fp[file!] value[string!]] > [ > either not-equal? fp none > [ > write/append fp value > write/append fp newline > ] > [ print value ] > ] > fp: none > ; check for server name in cgi environment variables > either equal? system/options/cgi/server-name none > [ >; value is empty, presume the script is run from commad line >print "no server name, application run from console" >fp: open/new/write %hello.htm > ] > ; script is invoked via server, yes, I know we need > ; a content-header string, etc here. > [ > prin "Server name: " > print system/options/cgi/server-name > ] > ; call function > fprint fp "line one" ; rebol doesn't like this > ; if the file has been opened, close it > if not-equal? fp none [close fp] > >