[REBOL] REBOL Newbie tries to convert C source to REBOL (long posting) Part II
From: WisD00M::gmx::net at: 22-Nov-2003 5:18
I've replied to all responses within one eMail - so if I didn't forget
you should find my comments and answers to your mail below!
First of all: thanks to everybody who offered support and provided useful
feedback. I really appreciate all your efforts !!
I didn't expect such a prompt response - and then so many replies !
On "altme", the chat client: I am certainly going to have a look into it !
Are many of you really using it ?
A J Martin > I looked at the data above and noticed that it's not directly
A J Martin > with Rebol as these values "N012.11.029" will get turned into
Well I didn't seem to have any problems loading the data - the specific
needs to be addressed at a later time anyway - so insofar it's absolutely
okay to initially have the data separated by whitespaces.
A J Martin > So the next plan is to use 'parse. The basic application of
A J Martin > whitespace is important is:
A J Martin > parse/all data rules
Indeed, I am already using parse - I've read some interesting stuff about it
- on the REBOL.COM
webpages, but also in other tutorials. When fooling around with parse I did
I read it would be possible to provide parse with patterns to look for - so
REBOL [ ]
;data is now a variable containing several lines of data i.e.
; -> datalinex HFD 111.11 N012.11.099 E034.31.114
foreach line data [
print parse line [rules] ;just to return whether the rules specified where
matched or not
However,using actual patterns didn't seem to work for me.
Looking at the line of data provided in the comment above,
I would want to check whether a line of data has the following form:
any characters, one whitespace, 3 numbers, 1 dot, 2 numbers, 1 whitespace, 1
char N | S,
3 numbers,1 dot, 2 numbers, 1 dot, 3 numbers, 1 whitespace, 1 char E|W, 3
numbers,1 dot, 2
numbers, 1 dot, 3 numbers, 1 whitespace,
So, trying to put that into REBOL's "words", I came up with the following
line: "datalinex HFD 111.11 N012.11.099 E034.31.114"; example line
digits: charset "0123456789"; all numbers that are allowed
alpha: charset "abcdefghijklmnopqrstuvwxyz"; all characters that are
allowed (not case specific)
dot: #"."; a dot
whitespace: #" "; a whitespace
rule: [any alpha 1 whitespace 3 digits 1 dot 2 digits]; an abbreviated rule
to match the first three elemnts of data
print parse line [rule]; to check whether the line contains data in the
format specified by rule
However this doesn't seem to work the way I would want it to ... probably I
am again making a stupid
A J Martin > Now to work out the rules that are needed. I can see that there
A J Martin > sections in the line which seem to be terminated by newlines.
A J Martin > rules: [
A J Martin > some section_rule
A J Martin > end
A J Martin > ]
A J Martin > I can see that each section starts with a open square bracket,
A J Martin > a section name (which seems important)
Well, the actual section name isn't really that important - indeed it is
as the data in each line is supposed to get 'recognized' by its syntax -
exactly like I tried
to show a frew lines above:
I intend to create several rules for all formats that are common - and when
offsets have been determined I want to run these rules against each section
in order to determine
whether rule1, rule2, or maybe rule11 is applicable is to the data stored in
A J Martin >followed by a closing square bracket,
A J Martin > (perhaps optional whitespace?) and a newline.
Yes, that's right: each section is determined by its name being enclosed in
square brackets - with no other data on that line.
A J Martin > After that, there's any number
A J Martin > of data lines, which seem to form a table of values of various
A J Martin > perhaps a trailing empty line?
This is also correct.
regardin the code that you provided here as an example, it looks quite good
I will look through it and try to understand what exactly it is doing and
You mentioned a "pattern.r-file" written by you - is there any documenation
available on the
actual usage of your library file ?
The 90° swapping idea looks also interesting - but I would probably rather
the conversion on a ruleset for recognition of data and then the actual
to a different format.
That seems pretty logical to me - as most data in its basic form is unlike
the syntax in
each section identical. That way I could also put rules together that are
rule_description: [any alpha]
rule_coordinates: [N|S|W|E 3 digits 1 dot 2 digits]
But as I said: my way of thinking doesn't seem to be right yet - cause that
part isn't doing
what it is supposed to do.
The later conversion to CSV format shouldn't really require any external
as soon as I sorted the data in each line apart and have converted it to a
that is suitable.
Just another example:
While the positional data is currently stored in a format like "N034.12.331"
I will need the last four bytes of the string ommitted/removed - so that I
Then remove the 2nd byte of the string (the 0)- then it looks like:
Then have the first byte of that string moved to the end the string so that
A J Martin > I hope that helps!
yes, for sure - thank you very much for your ideas and suggestions !
Tom Conlin > hopefuly this will get your mind moving slightly differently
okay, thank you for the code - as well as putting comments behind it !! :-)
I will have a look at it and try to incorporate the ideas into my script.
Anton Rolls > What does the application do and why does it do it?
The actual C application converts tables with GPS data from one format to
Besides the obvious GPS coordinates there is also some other information
the file, that depending on the format might also be required to be parsed
converted to the other format (CSV).
Now I want to port it to REBOL in order to enhance the functionality and
Anton Rolls > What does the data describe?
Like I said: each line contains at least longitude and latitude data (GPS) -
are also abbreviations and numbers that might also be needed for final
Anton Rolls > I've got all values as strings, but depending what they are
Anton Rolls > could use numbers, words and issues for easier handling later.
strings are perfectly okay, I intend to check the validity of data with its
rules-so there's no need to manually check whether data is valid or not.
Anton Rolls > I don't know - what do you want to do with the data?
GPS coordinates and other data in a certain format need to be converted to a
format to be used with a different application.
So bacially I'm having something like this in my datafile:
["dataline1" "111.11" "N012.11.029" "E034.31.110"]
but my target format requires for example
- field #1 to be at the 2nd position
- field #2 to be at the 1st position
- fields #3 & #4 to be converted to a format without miliseconds, without a
leading 0 but with a trailing character
(either N/S or W/E)
In this example I would then need:
["111.11" "dataline1" "12.11N" "34.31E"]
And as the actual data format varies with each section I just want to
rules in order to recognize the way data is stored - and when a rule is
I want to apply according to that another rule for conversion.
So in the above example my conversion rule would need to swap data elements
as well as splitting the GPS strings into directon, degrees,hrs,min,ms and
data for a format acceptable for the other application.
Anton Rolls > After finishing the extraction, you can get to the block of
Anton Rolls > for each section like this:
Anton Rolls > section1-data: select my-block "sec2"
This looks indeed intuitive - so it seems with that method I wouldn't have
to manually compute
the offsets of each section ? - but rather store each section's name in a
Anton Rolls > I am assuming, for each section, that each line has the same
Anton Rolls > elements. If not, then I recommend putting each line into a
Anton Rolls > its own, so it looks like this:
Yes, blocks seem to make sense to me, too - as each section can have a
Anton Rolls > Did you do any Java?
Anton Rolls > "Everything is a pointer" is kind of more
yes, I guess that's why I understood meanwhile - though the sytax is a bit
in assembler I simply consider everything a (D)WORD - so it doesn't seem to
different with REBOL.
But it's not really easy to get through the code - there are so many things
Sometimes I am really having trouble to decide whether to use literals or
the evaluation seems also heavily to rely where one put brackets ...
Anton Rolls > like rebol. Ask any questions here you want. We'll help you.
thank you ! - I am already stunned by the enormous response my first posting
received here !!
Anton Rolls > This has often been wished for already.
Anton Rolls > I think it's a bit of a waste of time at the moment.
Anton Rolls > There are plenty of good text editors out there, and rebol
Anton Rolls > highlighting for them too.
Sure, there are literally tens of thousands of editors out - also most of
some basic syntax highlighting.
But I thought more about an object oriented approach: an editor really
the programmer, and doing background parsing of the code that I write.
Having written some smaller View/VID test programs, I did always have to
have half a
dozen of browser windows with documentation in the background - just for
Simply, because I didn't knew for example what styles,faces and the like is
Unfortunately, the documentation about using actions & events with REBOL
view isn't very
good either - I was practically 'learning' by looking at example code from
If instead the editor would be doing background parsing and watch me create
or button it could really support me by displaying all possible options with
So when I created an object at the beginning of the file
house: make object! [
shutdoor: does [
opendoor: does [
and at a later time I clone this object by writing:
greenhouse: make house 
the editor might support me by displaying the elements (variables,
of that object and expected parameters for functions.
This would be even more useful if it gets extended to the whole REBOL
the editor could show in another window or maybe with popup menu the
elements in the current context.
In the tutorial section on functions I read somewhere it would be possible
enclose a comment on the function's purpose within the function header -
very header might also be useful information that could get displayed.
That way it could also show what styles are supported for a given type.
Since it's dialect-based it should be pretty possible to read out
display parameters and stuff like that.
So you begin to open a DRAW section within a layout and voilá: REBOL shows
can be done.
Seems to me like something REBOL is "born" to do ;-)
Anton Rolls > There is RebolFrance.net - if you can read French it helps.
Sorry, "mon ami": I don't understand any french ... thanks anyways !
P.S.: Does this list support attachments (ascii) ? Cause, actually I
attached some code
with my last mail but didn't see it on line (listview) - are the attachments
NEU FÜR ALLE - GMX MediaCenter - für Fotos, Musik, Dateien...
Fotoalbum, File Sharing, MMS, Multimedia-Gruß, GMX FotoService
Jetzt kostenlos anmelden unter http://www.gmx.net
+++ GMX - die erste Adresse für Mail, Message, More! +++