World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
Pekr 3-May-2009 [2103x3] | Look at my explanation above, and try to understand it. After here:, there is going to be "B" matched. So it means, that index is moved past "B". But you want to have your string copied including "B". So by issuing :here, you put parser to the saved position. |
exactly ... | |
... you can have many such named markers ... | |
mhinson 3-May-2009 [2106x3] | I can apreciate the usefullness of that. |
I am not sure why the BREAK is needed in the example from Ladislav above. Is it to force the rule to return true when the "B" and "." matches are found to prevent it carrying on looking for a second match further down the string? | |
Testing that idea out looks as if I have stumbled on the right answer. Maybe there is hope for me yet. | |
Pekr 4-May-2009 [2109] | 'break is needed in Ladislav's code imo because after first match of "B" you want to escape (break from) repetitive 'any block, and continue your processing with furhter rules (which is not the case with Ladislav's example, but is the case with your example, where 'copy followed. If there would be no break, after matching "B", the rule would still succeed, because if there is no "B", then there is always "skip option, which is always valid until the end of the script. So actually without the 'break, this 'any block would 'skip till the end of input string is reached ... |
Ladislav 4-May-2009 [2110] | re Break: it is used to make sure the "B"..."." is processed just once. If you need to process many such parts, then don't use Break |
mhinson 4-May-2009 [2111] | I have been working out ways to extract IP addresses from a string today. Is this a good way to do it? What could catch me out? parse to-block "junk 111.111.111.111 0.0.0.0 255.255.255.128 junk" [ any [ set tup tuple! (print tup) | skip ] ] |
Oldes 4-May-2009 [2112] | It depends, what the junk can be.. in your case it must be REBOL loadable. |
mhinson 4-May-2009 [2113] | I was hoping the TO-BLOCK would take care of that. do I need to parse the junk first to remove unloadable strings? or is there another TO- function that will do it for me please? |
Oldes 4-May-2009 [2114] | This should be safe: use [ ch_numbers ch_rest rl_ip ip-start ip-end ips ][ ch_numbers: charset "0123456789" ch_rest: complement ch_numbers ips: copy [] rl_ip: [ ip-start: some ch_numbers #"." some ch_numbers #"." some ch_numbers #"." some ch_numbers ip-end: (error? try [append ips to-tuple copy/part ip-start ip-end]) ] set 'get-ips func [str][ clear ips parse/all str [ some [ any ch_rest rl_ip ] ] ips ] ] get-ips "err,.;s 111.111.111.111 0.0.0.0 255.255.255.128 junk" |
mhinson 4-May-2009 [2115] | Thanks or that snippet, sounds as if you have been on this trail before. Thanks. |
Oldes 4-May-2009 [2116] | sorry.. : some [ any ch_rest rl_ip | skip ] so it handles cases like: get-ips "err,.;s 111.111.111 0.0.0.0 255.255.255.128 junk" |
mhinson 4-May-2009 [2117] | clever, defo better than my simple tuple search. Thanks. |
Oldes 4-May-2009 [2118x4] | and or you can use: get-ips2: func[str /local ips ip][ str: parse str none ips: copy [] while [not tail? str] [ error? try [ ip: to-tuple str/1 if 4 = length? ip [append ips ip] ] str: next str ] ips ] |
BUT in the second version there is problem with cases like: get-ips2 {"this is invisible IP 0.0.0.0" 255.0.0.0} | |
Also it fails with: get-ips2 {this is NOT an IP 255.0.0.} | |
So the result is.. if you want to be sure, use the string based parsing. | |
mhinson 4-May-2009 [2122] | I suppose it depends where the data comes from. looking at configs from routers should mean the IP addresses & masks etc are already propperly formatted. Thanks. |
Pekr 5-May-2009 [2123] | you could also probably enhance it by stati 1 to 3 digitis, dot ... |
mhinson 7-May-2009 [2124] | Hi, I have been working on a bit of code for some time & it now does something usefull for me, but to use it I am coding the output file into the code & running it repeatedly against every file in a directory. I thought it would be nice for it to have a very simple GUI to navigate to the input directory & output file & perhaps display some indicator of progress. Is this something a beginner might hope to add to existing code, or should I start from scratch again with the GUI part, then try to recreate my code in the view Layout part? Thanks. |
Henrik 7-May-2009 [2125] | you can create a prototype of the GUI first, by just creating a layout with the placement of the styles you want. afterwards you can make it work as you want using SET-FACE, GET-FACE, etc. |
mhinson 7-May-2009 [2126] | I will have a fiddle & see if I can understand that. Thanks very much Henrik |
Henrik 7-May-2009 [2127] | It's very easy to create prototypes and VID is excellent for that: view layout [ across space 2 box blue 300x300 "List View" box yellow 100x300 "Buttons" return box red 402x24 "OK/Cancel Panel" ] |
mhinson 7-May-2009 [2128x2] | Thanks, I started looking at this before & got confused with how I extract the information I can see on the screen & use it in the context of another block of code. With VB I think event handelers pop up everywhere? not sure but I think it is something like that. I couldnt work out how the same sort of thing is done in Rebol. |
if I have view layout [box green 400x400 field] the interpreter wont even load any more lines of script while the box is on the screen, so I am guessing I have to call the rest of my code from within the view layout block? | |
Henrik 7-May-2009 [2130x3] | Here's some learning by doing: With the above line of code, activate the console and press escape. The event handler is returned to the console. Now you can control the window interactively. Type UNVIEW. |
Then try this line: view layout [b: box green 400x400 f: field] Go back to console and escape. b/color: yellow show b set-face f "hello" get-face f hide f show f That's how you access UI parts. | |
If you want to return the event handler to the UI, type DO-EVENTS. | |
mhinson 7-May-2009 [2133] | Unview! wow, that will save me exiting the console a hundred times a day!! That is a top tip & should be in a prominate place for newbies. |
Henrik 7-May-2009 [2134] | If you want to show a window and return to console immediately, use VIEW/NEW instead. |
mhinson 7-May-2009 [2135x2] | This might be doable even for me. Thanks for these tips, I have read so much about Rebol, but I never seem to take it in properly. One of the great things with rebol is how I can test even the smallest fragment of code in the console, this makes it very friendly. Thanks for your help. |
I have been looking at the library examples & noticed that some of them start off with something like navigator: make object! [ The ones like this dont do anything so I am guessing I need to use this code in a way I have not come across yet. I have been madley trying things like make a: navigator and looking up make in the documentation, but not understanding the answers. | |
Henrik 7-May-2009 [2137] | make object! is the same as making a context. If you see an entire script wrapped in make object! [] or context [], it is because it was desired to use this script with other scripts without polluting the global namespace. |
mhinson 7-May-2009 [2138] | Oh, I see, the actual functions are inside the object. |
Henrik 7-May-2009 [2139] | Try this: context [ a: 2 set 'b 3 set 'c does [return a] ] >> a >> b >> c A simple way to control what's private and public. |
mhinson 7-May-2009 [2140] | I see, that is good. I have seen the 'b syntax used but not understood it yet. I see in your example the set 'b 3 seems like b: 3 in the global context. Thanks very much for your tips, they are a great help. |
Sunanda 7-May-2009 [2141] | On the other hand, if you want 'a, 'b, 'c to be local to the context -- so other parts of your application can also have their own 'a. 'b and 'c without overwriting each other: my-api: context [ a: 2 b: 3 c: does [return a + b] ] my-api/a: 5 ;; override default value print my-api/c ;; executes function in context |
mhinson 7-May-2009 [2142] | I wondered how the xxx/xxx/xxx paths to data were constructed... I was thinking of this sort of thing as a way to refer to valuse in a multi demensional array by name rather than number house: context [ room1: context [ items: [bed chair table] ] room2: context [ items: [TV sofa HiFi] ] ] |
Sunanda 7-May-2009 [2143] | That's the way I do it, using 'context / make object! Some people prefer using blocks rather than objects: blk: [a 4 b 5 c 6] blk/b == 5 blk/b: 99 probe blk == [a 4 b 99 c 6] There are advantages and disadvantages to each approach. |
mhinson 7-May-2009 [2144] | I used to get the same sort of effect in Pascal by defining ordinal types with values that were meaningfull words & use them to index my arrays. |
Sunanda 7-May-2009 [2145] | :-) ..... You could think of it as a type of associative array. |
mhinson 7-May-2009 [2146] | A question: if I want to provide a dialoge to navigate to a directory can I call up the ms windows file open & save dialogs, or do I have to do it all in rebol. I cant find any examples of this & dont have the skills to create my own... I like the idea of having a GUI interface, but I may have to go back to command line if it is too hard for me :-) |
Sunanda 7-May-2009 [2147] | File open dialog is simple. source request-file :-) |
mhinson 7-May-2009 [2148] | oh, that was simpler than expected. Thanks very much. I must say I dont think Rebol is very easy to learn, but once all these tricks are known it must be very easy to write things quickly. Perl is like a tool shop & a tree for wood, while Rebol is like a high street full of all sorts of shops as well as tools. |
Sunanda 7-May-2009 [2149] | And unexpected pot holes :-) |
mhinson 7-May-2009 [2150] | There is a request-dir too, but it is a bit of a joke. Looks like the way to go is to use the request-file then extract the directory. Why would request-dir even exist in such a feeble state? Sorry, I hope I am not speaking out of turn, but if anyone had that pop up they would think it was a bit odd. |
Sunanda 7-May-2009 [2151] | No, request-dir is pretty low standard. |
Henrik 7-May-2009 [2152] | some parts are sub-par, like request-color as well. fortunately it's possible to rewrite them. |
older newer | first last |