r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[I'm new] Ask any question, and a helpful person will try to answer.

BrianH
23-Jun-2009
[3098x2]
>> parse/all { X X  XX X X} [(prin 'a) some [(prin 'b) "X" (prin 
'c) [(prin 'd) "X" (print 'e) | (prin 'f) skip (prin 'g)] (prin 'h) 
| (prin 'i) skip (prin 'j)] (prin 'k)]
abijbcdfghbcdfghbijbcde
hbijbcdfghbcdfijbik== true
Now the fij is a bug in parse - it should be fgh.
sqlab
24-Jun-2009
[3100x2]
Excuse, if I did confuse you with my examples-

I just tried to show you that you can get loops with an definite 
loop counter in parse.
regarding 

parse/all "fd doixx s x x x oie    x } " [some [copy d   "x" (print 
d) | skip]]
what did you expect?

If you know what you are looking for you can extend it to


parse/all "fd doixx s x x x oie    x } " [some [copy d   ["x"   | 
"y" | "z" ]    (print d) | skip]]
and you will get your searched values.

But maybe I just don't understand the problem.
mhinson
24-Jun-2009
[3102x4]
Thanks Brian, I am finaly getting it I think. the prin 'a etc is 
better than debugging techniquies I have tried because it is small 
and dosen't add too much to the complexity, I can see I could reduce 
this method further with something like a: does [prin 'a]
Thanks sqlab, no need to excuse yourself please, your examples are 
great & I learnt a new use for COPY in PARSE. This has made your 
examples clear to me now, so thanks for spending your time helping 
me.  


The problem I have set myself is purely to understand parse more 
clearly so I have enough know-how to write any scripts I need without 
spending all day doing it. That is why I start off anking one question, 
then jump to another question if I don't fully understand the help 
I get.  


I have used parse a fair bit all ready, but limited myself to very 
simple concepts. see http://www.rebol.org/script-information.r?script-name=cisco-extract.r
and marvel that it even works ;-)   Thanks.
I have been reminded that   |skip   is a word  | skip   is OR skip. 
 it is so easy to miss the space between | & skip
Right, I would say that the following snippit is the most educational 
thing I have done with PARSE.  It shows me a lot of things about 
what is happening & validates the construction and use of charsets 
& whatever the 'address block is called.     Thanks everyone for 
your help.

digit: charset [#"0" - #"9"]
address: [1 3 digit "." 1 3 digit "." 1 3 digit "." 1 3 digit]

a: does [prin 'a] b: does [prin 'b] c: does [prin 'c] d: does [prin 
'd] e: does [prin 'e] f: does [prin 'f]
parse/all {1 23 4.5.6.12 222.1.1.1 7 8} [some[

 (a) copy x address (prin x) some[ (b) copy y address break | skip 
 (c)] (print y) | skip (d)
]]
adadadadada4.5.6.12bcb222.1.1.1
Graham
24-Jun-2009
[3106x2]
why not use block parsing?
parse [ 1 23 4.5.6.12 222.1.1.1 7 8 ] [ integer! integer! tuple! 
tuple! integer! integer! ]
BrianH
24-Jun-2009
[3108]
Because he's parsing Cisco config files.
mhinson
24-Jun-2009
[3109]
I am just learning everything I can, so knowing about Block Parsing 
sounds good to. tuples! are quite good for IP addresses, but ip addresses 
often need exactly 4 parts. I wonder why there are no datatypes specific 
for networking? e.g. networks & masks & inverse masks and domain 
names. and DNS records.
Steeve
24-Jun-2009
[3110]
Mhinsob, if you load an ip address (from a string) you got a tuple, 
so what is different in your request ?
>> type? probe load "1.2.3.4" 
1.2.3.4
== tuple!
Izkata
24-Jun-2009
[3111]
Possibly checking that it's a valid IP address?
>> length? 1.2.3.4
== 4
>> length? 1.2.3.4.5
== 5
>> length? 1.2.3.44.5
== 5
Tomc
24-Jun-2009
[3112]
early tuples were more restrictive if I recall  (max of lenght 4) 
but then we complained we wanted to use them for more than just networking
BrianH
24-Jun-2009
[3113x2]
You can use up to 10 tuple elements - any higher wouldn't fit into 
an immediate value.
I wonder why there are no datatypes specific for networking?

In general we like our types to be more widely applicable. However, 
we have tuple!, url!, and port!. The rest can be handled by functions.
Paul
24-Jun-2009
[3115x3]
mhinson, not sure if your using R2 or R3 but if your using R2 then 
you might want to know about get-modes.
>> get-modes tcp:// 'interfaces
== [make object! [
        name: "lo0"
        addr: 127.0.0.1
        netmask: 255.0.0.0
        broadcast: none
        dest-addr...
>> print get-modes tcp:// 'interfaces
name: "lo0"
addr: 127.0.0.1
netmask: 255.0.0.0
broadcast: none
dest-addr: none
flags: [multicast loopback]
name: "if15"
addr: 169.254.102.14
netmask: 255.255.0.0
broadcast: 169.254.255.255
dest-addr: none
flags: [broadcast multicast]
name: "if12"
addr: 192.168.1.105
netmask: 255.255.255.0
broadcast: 192.168.1.255
dest-addr: none
flags: [broadcast multicast]
I don't know what the equivalent in R3 is.
BrianH
24-Jun-2009
[3118]
Nothing yet :(
mhinson
25-Jun-2009
[3119]
The get-modes looks interesting. Can it produce information about 
any ip address I might give it?  like 172.22.37.55/28 

I suppose that is an example of a very common network address "type"
BrianH
26-Jun-2009
[3120]
GET-MODES gets information about ports, not addresses.
mhinson
26-Jun-2009
[3121]
Hi. is there a special function to remove the last element of a string 
please? this works, but seems a bit cryptic.
reverse next reverse {a.b.c.}        Thanks.
Sunanda
26-Jun-2009
[3122]
These avoids the double reversal -- not sure if they are less cryptic:
     head clear  back tail  {a.b.c.}
     head remove back tail {a.b.c.}
mhinson
26-Jun-2009
[3123]
Thanks Sunanda. I like clear back tail {a.b.c.}  then I can directly 
modify my string.
Gregg
28-Jun-2009
[3124]
Wrapping it in a func makes it less cryptic. :-)
mhinson
4-Jul-2009
[3125]
Hi. If I obtain a date from a file and it is a DATE!  what is in 
that date?  for example I know it contains date/month, but can I 
get it to return the month as a string with a leading 0 or anything 
like that?  Or is it up to me to code the formatting I need from 
integer date values? Is this documented anywhere or can I see any 
of the source some how.  Thanks.
BrianH
4-Jul-2009
[3126]
There are no built-in date formatting functions that do that. However, 
I'm sure the REBOL.org script library has one :)
mhinson
4-Jul-2009
[3127]
Hi Brian, I see some goodies there. What I am doing is too trivial 
to want to link any large blocks of code just for that so I will 
just code the bit I need I think.  I was puzzled because DATE returns 
the info with the month as  a word, but date/month returns an integer, 
so I imagined there must me more to DATE! than just a structure containing 
integers?
Ladislav
4-Jul-2009
[3128x2]
documented: do you mean like date/month date/day, etc?
http://www.rebol.com/docs/core23/rebolcore-16.html#section-3.2
mhinson
4-Jul-2009
[3130]
Hi Ladislav, yes. or any other bits of information attached to dtae 
types
Ladislav
4-Jul-2009
[3131x3]
(I found a couple of errors in the text)
seems, it was changed recently
the file http://www.rebol.com/r3/docs/datatypes/date.htmllooks like 
being affected too
Graham
4-Jul-2009
[3134x2]
>> d: now
== 5-Jul-2009/10:36:09+12:00
>> d/1
== 2009
>> d/2
== 7
>> d/3
== 5
though it's 4th of July for you guys ...
Ladislav
4-Jul-2009
[3136]
not for me anymore
mhinson
4-Jul-2009
[3137]
Thanks...  I can work with that information, but I am curious as 
to how referencing the whole date gives Jul  but there seems no option 
fot the month as a word.... not that I want it, but I am curious 
how that works.
Ladislav
4-Jul-2009
[3138]
>> d: now
== 5-Jul-2009/0:36:25+1:00
Graham
4-Jul-2009
[3139]
not applying to those guys who should be asleep!
Ladislav
4-Jul-2009
[3140]
LOL
Graham
4-Jul-2009
[3141]
which reminds me .. date functions should have a /utc refinement 
:)
mhinson
4-Jul-2009
[3142]
I write my best code in the middle of the night with no PC... shame 
it is all forgotton by the morning, or written on toilet pater.
Sunanda
4-Jul-2009
[3143]
Happy 753rd year of independence (source: wikipedia, apparently):
http://www.theonion.com/content/node/50902
Graham
4-Jul-2009
[3144x2]
mhinson .. look at the locale
753 years ???
Sunanda
4-Jul-2009
[3146]
Check the article, graham.
Graham
4-Jul-2009
[3147]
>> probe system/locale
make object! [
    months: [
        "January" "February" "March" "April" "May" "June"

        "July" "August" "September" "October" "November" "December"
    ]
    days: [

        "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"
    ]
]