World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
Henrik 12-May-2009 [2165] | vars: make object! [ b: c: none ] f1: func [a] [ vars/b: join a "-Bee" vars/c: join b "-Cee" vars ] |
mhinson 12-May-2009 [2166] | I see, it looks as if both techniques will help me in different cases |
Henrik 12-May-2009 [2167] | when using objects, you will have less maintenance and you have one place where your object contents is defined. imagine if you have 10 different functions that would return blocks (10 block definitions) versus 10 functions that return objects (1 object definition). |
mhinson 12-May-2009 [2168x2] | I dont understand how this prevents the sort of problems I might get using global variables? I was expecting to have to define the object inside the function to keep all the variables local to the function. |
I am thinking that if I take care with these things I will be able to reuse fragments of code in lots of projects without worrying that I have used the same global variable in two places that conflict. | |
[unknown: 5] 12-May-2009 [2170x2] | no you must use the /local switch to do that. |
func [arg1 arg2 /local lc1 lc2 ...][body...] | |
mhinson 12-May-2009 [2172] | Paul, how does that relate to using objects please? |
[unknown: 5] 12-May-2009 [2173] | Only the things you define in a function as local are local. |
PeterWood 12-May-2009 [2174] | Each object has its own context. All variables in the object are local to the object's context. Only the object "variable" would be in the global context: >> a: 1 == 1 >> obj: make object! [ [ a: "one" [ b: "two" [ c: "three" [ ] >> a == 1 >> obj/a == "one" >> b ** Script Error: b has no value ** Near: b >> obj/b == "two" |
mhinson 13-May-2009 [2175] | Hi, I have been puzzeling over this all evening & would love a few tips please. I am trying to write a single parse rule that will extract the first number before the "/" in each case, but my logic must be faulty I think. digit: charset [#"0" - #"9"] data1: {random 10/2} data2: {2/33-35,2/48} parse/all data1 [ some [[h: 1 2 digit :h copy result to "/" thru end] | skip]] result parse/all data2 [ some [[h: 1 2 digit :h copy result to "/" thru end] | skip]] result |
Oldes 13-May-2009 [2176] | something like this? digit: charset [#"0" - #"9"] rest: complement digit data1: {random 10/2} data2: {2/33-35,2/48} parse/all data1 [any [copy x some digit #"/" (probe x) | some digit | some rest]] parse/all data2 [any [copy x some digit #"/" (probe x) | some digit | some rest]] |
mhinson 13-May-2009 [2177] | PeterWood, thanks for your example. I think I understand too little about objects to use them to any benifit yet, I expect it will slowly get clearer. |
Steeve 13-May-2009 [2178] | or parse/all data1 [any [copy x some digit opt [#"/" (probe x)] | skip]] |
mhinson 13-May-2009 [2179] | Thanks Oldes, that looks good. I didnt know I could use compliment in a parse like that either. I must have been doing it wrong when I tried as I kept getting errors. Thanks Steeve, I must go & study more about opt too now. I very much appreciate you clever guys coming in this group to help me with my simple questions. I am begining to get a bit more productive with some of the things I am trying to do, although I am still very much a beginner in most areas. Thanks. |
mhinson 14-May-2009 [2180] | I just don't "get" Parsing.. I dont understand the syntax & every new thing I try takes hours before I chance upon the right syntax. There are so many tutorials & examples that I dont really know which one to concentrate my time reading. When i use OR (|) I get paticularly confused as it dosnt seem to evaluate the expressions in order in every case. |
Janko 14-May-2009 [2181] | you mean parsing with charsets or the "normal" parsing? |
mhinson 14-May-2009 [2182x2] | normal I think |
Like it took me an hour to work out how to modify Steeve's example to only output the first occurance of the match. | |
Janko 14-May-2009 [2184x2] | aha, that is easier to learn .. I also don't the advanced parsing that oldes gave you example, and I wrote a couple of finished programs that used "normal" parsing as a main featurea |
start with easy examples and go forward from that | |
mhinson 14-May-2009 [2186x3] | Trouble is that the easy examples dont produce the results I need for processing my data :-( |
I have spent about 6 hours so far trying to convert this sort of format {random 2/2,2/4-6,2/33-37} to module: 2 port: [2 4 5 6 33 34 35 36 37] So far even with lots of help I have only managed to extract the module number & the ranges, but not the last one because there is no comma after it. | |
I suppose I could add a comma to the end of the string then I would be able to use it as a marker. | |
Janko 14-May-2009 [2189x2] | sometimes an easier solution is possible if you do it in more parse runs |
or if only comma is the problem slap it at the end and be done with it | |
Henrik 14-May-2009 [2191] | yes, for something like that, I would do some simple splitting to get the numbers isolated. |
Janko 14-May-2009 [2192] | ... from where do you parse 5 out... is that supose NUM-NUM suppose to be ranges? |
mhinson 14-May-2009 [2193] | so I will add a comma to the end, then parse data [any [ some digit #"/" copy result #"," (insert results result) | skip]] |
Janko 14-May-2009 [2194] | If it is I wouldn't call that a parse problem, ... remember you have to divide and conquer the problems , and that looks like a compound problem which parsing is not the big part of.. you just need regular "split" method |
mhinson 14-May-2009 [2195] | some are ranges & some are single ports |
Janko 14-May-2009 [2196] | what does 2 mean in 2/x-y ? |
mhinson 14-May-2009 [2197] | the 2 is a module number on a Cisco catos switch |
Janko 14-May-2009 [2198] | I qould 1) split on comma to get list of entities 2) for each entity if it's a single num append it to block, else split again and append whole range to the block |
mhinson 14-May-2009 [2199] | the port information is stored in a form like set port disable 2/2,2/4,2/6-8 set port disable 3/1-5,3/7 Then the same sort of thing for the names given to the ports. I want to extract it all into a standard format for analysis & comparison of IOS based information (done the IOS stuff ok) |
BrianH 14-May-2009 [2200] | a: [...] some-a-with-comma: [a any ["," a]] |
mhinson 14-May-2009 [2201] | CIsco operating systems are IOS or CATOS on switches and output formats are very different. |
Ladislav 14-May-2009 [2202] | mhinson: the above {copy result #","} does not look intended to me |
mhinson 14-May-2009 [2203] | ah, do I need a copy result to perhaps? |
Ladislav 14-May-2009 [2204x3] | if {copy result to ...} is what you want then I understand why you are having trouble with the END |
not-comma: complement charset "," copy result any [not-comma | skip] | |
sorry, just copy result not-comma | |
PeterWood 14-May-2009 [2207] | I think the advice to break the problem down and use more than one parse statement is good advice. Let's see how we can do that. I'll go through how I would approach the problem step by step. Sorry that I'll be squashing things on to one line but AltME paste doesn't work well on Mac. |
mhinson 14-May-2009 [2208] | :-) |
PeterWood 14-May-2009 [2209] | I usually try to take a few small steps rather than try to get the answer straight away. The test data: >> inp: {random 2/2,2/4-6,2/33-37} == "random 2/2,2/4-6,2/33-37" |
mhinson 14-May-2009 [2210] | random is sometimes a word & sometimes a number between 1 & 1000 |
PeterWood 14-May-2009 [2211x2] | We'll need to look for digits so : > digit: charset [#"0" - #"9"] == make bitset! #{ 000000000000FF03000000000000000000000000000000000000000000000000 } |
Does random ever have the sequence 2/number in it? | |
mhinson 14-May-2009 [2213x2] | no |
specific words (not many of them) on numeric alone | |
older newer | first last |