World: r3wp
[Core] Discuss core issues
older newer | first last |
Jerry 27-Oct-2006 [5861] | I have noticed some REBOL experts designing their own protocols, which, by the way, are very cool. By "protocol," I mean the protocol part of an url, it doesn't have to have anything to do with networking. I would like to design my own protocol, too. So I can write: >> print read DICT://English/English/Cheyenne Cheyenne -noun, plural -ennes, (especially collectively) -enne for 1. 1. a member of a North American Indian people of the western plains, formerly in central Minnesota and North and South Dakota, and now divided between Montana and Oklahoma. 2. an Algonquian language, the language of the Cheyenne Indians. 3. a city in and the capital of Wyoming, in the S part. 47,283. >> Is there any document I can read about this. Thank you for your help. |
Rebolek 27-Oct-2006 [5862] | your definition is missing the REBOL web server from DocKimbel ;o) |
Jerry 27-Oct-2006 [5863] | My mistake. Sorry, DocKimbel. And thank you for bringing us the wonderful Cheyenne web server |
Anton 27-Oct-2006 [5864] | Jerry, go to http://knowngood.com/rebol/ and search "rebol scheme handler" The first link for me is "Rebol Forces — Writing your own Protocol Handler" which as I remember is written very well by Jeff Kreis. |
Pekr 27-Oct-2006 [5865] | ah, Jeff Kreis, Holger Kruse, those were the times :-) |
Anton 27-Oct-2006 [5866x2] | and be prepared to get your hands pretty dirty writing scheme handlers. You will need to understand how words are bound to different contexts. However, your scheme looks pretty easy to write. |
(I mean, looks pretty simple, so *easier* to write.) | |
Jerry 27-Oct-2006 [5868] | Thanks, Anton. |
Anton 27-Oct-2006 [5869x2] | I have used data: read/binary url and saved data to disk. Now I want, without accessing the disk again, to translate the line terminators as if I had just READ the file at the beginning. Any ideas ? |
(I think I hit this problem already a long time ago..) | |
Sunanda 27-Oct-2006 [5871] | Is it as simple as this? data: read/binary http://www.rebol.com to-string data |
Maxim 27-Oct-2006 [5872x2] | if you want to strip the CRLF form (which is what I guess you are trying to do: data: replace/all to-string data "^M" "" |
this will remove any CR chars hanging around after the to-string... | |
Anton 27-Oct-2006 [5874] | Hmm.. can't be a simple as that. I think READ determines the file's host platform somehow and translates accordingly. |
Maxim 27-Oct-2006 [5875] | rebol only strores newlines using the LF char internally (like unix) |
Anton 27-Oct-2006 [5876] | Yes...... |
Maxim 27-Oct-2006 [5877x2] | so the above will read DOS and UNIX newlines. |
I'm using it myself for http operations on a server. and it works flawlessly. | |
Anton 27-Oct-2006 [5879] | Mac uses just CR. |
Maxim 27-Oct-2006 [5880] | yes, but then how to determine the input itself. |
Anton 27-Oct-2006 [5881] | Let me just see what to-string does... |
Maxim 27-Oct-2006 [5882x4] | if you have a potential for receiving Mac Files... (I was just about to give you this when you posted about mac ;-) |
if converts byte for byte each char in the binary string;... | |
I have been handling binary data now for the last 2 weeks in many different operations. | |
for a more unified conversion you could do this: data: replace/all replace/all to-string data "^M^/" "^/" "^M" "^/" this way if its CRLF it will strip them and if its only CR it will convert them. | |
Anton 27-Oct-2006 [5886x2] | That looks better. |
(Yes, looks like to-string doesn't really do anything except change the datatype from binary to string.) | |
Maxim 27-Oct-2006 [5888x6] | that's a good thing. |
otherwise, some operations within rebol would be just to crazy to handle. | |
working on EDI data, for example, the binary data is converted to string by PARSE... so if it tried to "fix" stuff, I could not properly parse it... :-( | |
and EDI uses non-printable characters as separators... | |
and btw, I love REBOL's extended character set for words. being able to use - + = ' &, etc in words just makes words so much more expressive. | |
I just discovered this week that we can use the tick in words! | |
Anton 27-Oct-2006 [5894] | Yes, pretty handy sometimes. |
Maxim 27-Oct-2006 [5895x2] | as in : value': 99 |
so this allows us to define words which pretty much equate to themselves. blue': 'blue hehe | |
Gregg 27-Oct-2006 [5897x2] | Also handy for more readable English contractions. e.g. can't-do-it?: true |
I got two REBOL functions, say, f1 and f2, which are both time-consuming. How can I make them run simultaneous in the same process? We don't have threads in REBOL (though the rumored task type in R3 may give us this capability), so you need to do big tasks in little chunks, maybe FSM driven, to simulate things like co-routines. | |
Anton 27-Oct-2006 [5899x4] | This parse rule appears to be over twice as fast: |
parse/all str [ any [ to "^M" here: ["^M^/" (remove here) | "^M" (change here "^/")] ] to end ] | |
I hope it's correct. | |
Compared 10000 iterations on a 67k script. | |
Maxim 27-Oct-2006 [5903] | Carl has once said that most string iterating funcs are about equally fast in REBOL... the difference in this is that parse is only parsing the string once, whereas the previous one-liner does two replaces. So I guess that's the main reason. |
Anton 28-Oct-2006 [5904x5] | Makes sense. |
This version corrects a bug in the above parse rule: | |
to-rebol-line-terminators: func [ string [any-string!] /local here ][ parse/all string [ any [ to "^M" here: ["^M^/" (remove here) :here | "^M" (change here "^/")] ;thru "^M" here: ["^/" (remove back here) :here | (change back here "^/")] ] to end ] ] to-rebol-line-terminators bin: #{0d} bin | |
(and has an alternative way, but I think it will operate minutely slower.) | |
Actually, parse version looks only about 10% faster. When there is no work to do it is about twice as fast. | |
Gabriele 28-Oct-2006 [5909x2] | if you are doing to string! instead of as-string, then a copy version could be faster, when there are characters to remove. |
alternatively you could create a dummy port handler to let the native code do the job for you. | |
older newer | first last |