World: r3wp
[Core] Discuss core issues
older newer | first last |
Rod 23-Feb-2008 [9280] | I am trying to pull some information out of a moderately formatted wiki and am tripping over something simple. I have grabbed what equates to a record in a table so far that looks as follows. ||Key 123||Description text||Status||02/23/08||Y|| I have parse giving me this as a block of values. Since this wiki is only loosely formatted the first field varies one line to the next, sometimes might just be Key, or *Key ###. What I am working too hard at is how to test a line is a pure Key ### value. I went looking using find for "Key "(with the space) values but that still picks up "*Key ###" values. I have multiple key types but generally it follows the pattern of trying to avoid the leading * lines and any line that isn't a known Key with some number following it. My old procedural habits would like a simple substring so I can test from the beginning for x number of characters. I have tried copy/part but am not getting the range syntax correct. I am also thinking I should just further split the field to the key+number so I can test that both parts exist and have appropriate values. Suggestions or nudges towards enlightenment? |
btiffin 23-Feb-2008 [9281x2] | Umm, I'll get this wrong; but parse is the ticket. nums: make bitset! [#"0" - #"9"] valid: parse value [ "Key" 3 nums] I think. |
space: make bitset! " " valid: parse/all value ["Key" space 3 nums space to end] Maybe? | |
Brock 23-Feb-2008 [9283x3] | I'd include a characterset that excludes the * character |
sorry bitset... nums: make bitset! [#"0" - #"9"] skip-char: complement make bitset! [#"*"] valid: parse value [skip-char "Key" " " 3 nums] | |
... something to that affect anyway. | |
Ingo 23-Feb-2008 [9286] | How about: nums: charset [#"0" - #"9"] space: charset [#" "] parse wiki ["||" any space "key" any space 3 nums any space "||" ] and so on ...] |
Rod 23-Feb-2008 [9287] | Brian, the first one seems to work for my test data, will give it a try on the real thing on Monday. Thanks all for the tips, will keep them handy as I refine this little script. |
Graham 23-Feb-2008 [9288] | Anyone got a clean-script that works with the new rebol syntax ? |
[unknown: 5] 23-Feb-2008 [9289] | Is there an easy way to remove double blocks from a block. So that something that looks like [[something]] looks like [something]? If not shouldn't we have something like this in REBOL as a mezz function? |
Henrik 23-Feb-2008 [9290x2] | this has been discussed before, but I think the solution has scrolled out of view a long time ago... |
R3 can do it using the new methods that loops can use, I believe. | |
[unknown: 5] 23-Feb-2008 [9292] | Are you saying it can't be done until R3? |
Henrik 23-Feb-2008 [9293x3] | it can easily be done. the simplest way is: |
form [[1][2][3]] | |
but it has limitations | |
[unknown: 5] 23-Feb-2008 [9296] | Can you expland on the limitations? |
Henrik 23-Feb-2008 [9297x3] | you lose bindings and it won't work on series inside the blocks inside the block. |
oops, it should be to-block form [[1][2][3]] | |
there are better solutions, but that is the quickest one. | |
[unknown: 5] 23-Feb-2008 [9300] | That is how I do also Henrik, I would be interested in a better solution but I was thinking we need one to handle the blocks within blocks |
Henrik 23-Feb-2008 [9301] | the only other way in R2 is to process each block one by one with a loop |
[unknown: 5] 23-Feb-2008 [9302] | I can build the function to loop through a block looking for others but am curious about the effect on bindings. |
Henrik 23-Feb-2008 [9303] | I think we made a 'flatten function once. |
[unknown: 5] 23-Feb-2008 [9304x2] | good name |
Tell me more about in what way you think the bindings will get lost. | |
Henrik 23-Feb-2008 [9306x2] | with FORM you always lose bindings |
try searching for flatten in AltME. plenty of references to it, I can see here. | |
[unknown: 5] 23-Feb-2008 [9308x2] | But I can only think that bindings would be lost for those blocks assigned as a value to a word |
Seems it would still be useful for data taken from a stream of string data | |
Henrik 23-Feb-2008 [9310] | I can't calculate in my head when exactly the bindings are lost, so I would suggest simply experimenting in the console. |
[unknown: 5] 23-Feb-2008 [9311] | Yeah I definately think that would be the case for set-words that contain block values but should be no problem on passing block data to set-words that are currently not set. |
Gregg 23-Feb-2008 [9312] | flatten: func [blk [block!] /local res rule value] [ res: copy [] rule: [some [into rule | set value skip (append res :value)]] parse blk rule res ] |
[unknown: 5] 23-Feb-2008 [9313x2] | Here is a function for when you just want part of the block's flattened for when you reduce a bunch of data and want to use select on the data: semi-flat: func [blk /local blk2][ while [not tail? blk][ if block? blk/1 [ blk2: copy blk/1 insert remove blk blk2 blk: next next blk ] ] blk: head blk ] |
>> data: [[1 ["record1"]] [2 ["record2"]] [3 ["record3"]]] == [[1 ["record1"]] [2 ["record2"]] [3 ["record3"]]] >> semi-flat data == [1 ["record1"] 2 ["record2"] 3 ["record3"]] >> select data 2 == ["record2"] >> select data 3 == ["record3"] | |
Anton 23-Feb-2008 [9315x3] | Paul, you can avoid copy blk/1 by using change/part. And perhaps better to continue processing the data when blk/1 is not a block. |
semi-flat: func [blk][ while [not tail? blk][ blk: either block? blk/1 [ change/part blk blk/1 1 ][ next blk ] ] head blk ] semi-flat [[1 ["one"]] [2 ["two"]] "other data"] | |
You can also use until instead of while: semi-flat: func [blk][ until [ tail? blk: either block? blk/1 [ change/part blk blk/1 1 ][ next blk ] ] head blk ] | |
[unknown: 5] 23-Feb-2008 [9318x2] | Yes Anton, thanks. |
Anton, both of those functions you provided didn't seem to achieve what I was intending to do which was to format the block for easy selecting using 'select. | |
Anton 23-Feb-2008 [9320] | My example data contains "other data" which is probably confusing you, sorry. |
[unknown: 5] 25-Feb-2008 [9321x3] | Anyone know what the discussions are regarding extending the alias function in REBOL3? I have a bit ugly function that does something like that now. What I'm talking about is the ability to alias for example find/only or find/case or instead of just find so that no refinement has to be supplied. I submitted a wish for this some time ago and hoped it would make it in REBOL3 but don't know what is intended regarding that. |
I checked the alpha and noticed that it still says it doesn't allow path! for its word argument. | |
Probably should move this question to R3 group | |
james_nak 26-Feb-2008 [9324] | Gregg, thanks I will look into the ICS method. |
Louis 26-Feb-2008 [9325] | I have a script that sends out a newsletter to several hundred people. Sometimes (often) the mail server will disconnect before all the emails are sent. What is the best way to make the script reconnect and continue sending? |
[unknown: 5] 26-Feb-2008 [9326x4] | Here is a little function I made to handle a situation I often find myself in. Say you got three words and want to do something if one of the words has a value other than false or none. But you may want to do something else if two words have a true value or maybe all three and then if also if none have a value such as a default. This is a very flexible function I created to allow you to do that: |
evals: func [blk blk2 /local r i l][ r: 0 i: 0 l: length? blk2: reverse blk2 foreach item blk [if get item [r: r + (2 ** i)] i: i + 1] while [l > 0][ if r > (2 ** (l - 3)) [return first blk2] blk2: next blk2 l: l - 1 ] last blk2: head blk2 ] | |
Now say you have some locals in a function that you want to check for any combination of them being used. The evals function will let you do that. | |
the 'blk argument would be the locals (assuming that 'evals is a subfunction of our function) that you want to pass to the evals function and the 'blk2 would be what to return if those values are true. So for example, if I have the following locals in my function: /any /only and say I have a default value of "default" that I want to return if /any or /only is not used. Therefore, I pass the following: evals [any only]["default" "any" "only" "any and only"] it would then process the result. This can be a very handy function. | |
older newer | first last |