World: r3wp
[Rebol School] Rebol School
older newer | first last |
Chris 23-Sep-2010 [3244] | You can use 'echo to capture the result in a temporary file, then delete the file after: echo %tmp.txt what echo none parse read %tmp.txt [...] delete %tmp.txt Shame you can't echo to a string or binary... |
PatrickP61 23-Sep-2010 [3245] | Chris, That is a good idea, for the quick and dirty, but I am having an issue with WHAT WHAT has what is supposed to be an optional field for module name that follows it. But if I do this: echo %tmp.txt what echo none This is processed as if it was this: echo %tmp.txt what echo <--- echo becomes the passed parameter into WHAT none How do I get around that other than specifying a dummy field? Try this: echo %tmp.txt what halt <--- halt will NOT be executed since it is pulled into the WHAT function!! echo none |
BrianH 23-Sep-2010 [3246x2] | It's only optional from the command line, not within a script. |
In a script, try what (). | |
PatrickP61 23-Sep-2010 [3248] | Will do |
BrianH 23-Sep-2010 [3249] | or (what) |
PatrickP61 23-Sep-2010 [3250x2] | That works just fine! Thanks |
What is the easiest way to capture the first literal in a string? LIST: {?? Debug print a word, path, or blo...} I tried FIRST TO-BLOCK LIST but got this: >> first to-block list ** Syntax error: invalid "word" -- "word," ** Where: to to-block ** Near: (line 1) ?? Debug print a word, pat... It works when I have a valid word (not ?? or other) | |
Steeve 23-Sep-2010 [3252] | first load/next list |
BrianH 23-Sep-2010 [3253x2] | >> a: {?? Debug print a word, path, or blo...} == {?? Debug print a word, path, or blo...} >> parse a [return to " "] == "??" |
That's R3 though. | |
PatrickP61 23-Sep-2010 [3255x2] | Yeah, I'm in R3 |
They both work! Thanks | |
BrianH 23-Sep-2010 [3257] | >> to-word parse a [return to " "] == ?? It will be faster than LOAD/next, trust me. Might be slower than TRANSCODE/next though. |
PatrickP61 23-Sep-2010 [3258] | Parse is very fast I guess?? |
BrianH 23-Sep-2010 [3259x2] | Yes, but TRANSCODE is faster. However, TRANSCODE only works on UTF8 binary, so when you add the binary conversion the PARSE method ends up being marginally faster. |
>> dp [first transcode/next to-binary a] == make object! [ timer: 0:00:00.000013 evals: 15 eval-natives: 6 eval-functions: 2 series-made: 4 series-freed: 1 series-expanded: 1 series-bytes: 570 series-recycled: 0 made-blocks: 2 made-objects: 0 recycles: 0 ] >> dp [to-word parse a [return to " "]] == make object! [ timer: 0:00:00.000012 evals: 17 eval-natives: 5 eval-functions: 2 series-made: 2 series-freed: 0 series-expanded: 0 series-bytes: 435 series-recycled: 0 made-blocks: 1 made-objects: 0 recycles: 0 ] >> b: to-binary a == #{ 3F3F20202020202020202020202020202020202020204465627567207072696E 74206120776F72642C20706174682C206F7220626C6F2E2E2E } >> dp [first transcode/next b] == make object! [ timer: 0:00:00.00001 evals: 11 eval-natives: 5 eval-functions: 1 series-made: 3 series-freed: 1 series-expanded: 1 series-bytes: 512 series-recycled: 0 made-blocks: 2 made-objects: 0 recycles: 0 ] | |
PatrickP61 23-Sep-2010 [3261x2] | Will ECHO write a file in UTF-8 and so allow me to use TRANSCODE? |
I guess I could just try it out | |
BrianH 23-Sep-2010 [3263] | But remember, READ/lines and all line-oriented stuff works with strings, not binary. You might be better off working with PARSE. |
PatrickP61 23-Sep-2010 [3264x2] | Hey, this worked! first transcode/next read %tmp.txt ! <-- which is the first function name in my temporary file Now, how do I get the first literal for each line??? Parse?? |
Here is what I have so far in my attempt to capture ONLY the function names in Rebol: echo %tmp.txt what () echo none funct-list: first transcode/next read %tmp.txt Not exactly sure how to go through all the records in %tmp.txt yet | |
BrianH 23-Sep-2010 [3266] | map-each x read/lines %tmp.txt [to-word parse x [return to " "]] |
PatrickP61 23-Sep-2010 [3267x2] | Thank you very much BrianH and Steeve. I appreciate it |
Here is the completed script to get only Function names (nothing else) in a file: echo %tmp.txt what () echo none funct-block: read/lines %tmp.txt funct-names: map-each x funct-block [to-word parse x [return to " "]] write/lines %Funct.txt funct-names | |
BrianH 23-Sep-2010 [3269x2] | funct-names: sort map-each [w v] to-block system/contexts/exports [either any-function? :v [to-word w] [()]] |
WHAT gets its words from the system/contexts/exports object. MAP-EACH takes a block, so the object is converted to a block. The :v is equivalent to GET/any 'v in R3. The () in the second EITHER block is to generate an unset! value, which will cause MAP-EACH to not add a value to the block for that round. And SORT sorts words in R3. | |
PatrickP61 23-Sep-2010 [3271x2] | The ECHO was quick and dirty. Your solution is, of course, better since it is getting the values directly as opposed to using ECHO. Thanks BrianH |
Hi everyone, I would really like to be able to capture some text from an html webpage into a block. Looking at Carl's cookbook at www.rebol.net/cookbook/recipes/0041.html , he has a tiny script called "Tiny HTML to Text converter". So I thought I could try it in R3, but alas, the /markup refinement doesn't seem to be defined. What would you suggest I use instead to capture a webpage text using R3? | |
BrianH 23-Sep-2010 [3273x2] | Are you using a107? If so, try this: >> decode 'markup to-binary "<html>blah</html>" == [<html> "blah" </html>] |
Note that it works on binaries, not strings, so just use plain READ. We haven't made a nice mezzanine wrapper for it yet. Bringing back the LOAD/markup option is unlikely (LOAD is too complex already) but a simple LOAD-MARKUP function is likely. | |
PatrickP61 23-Sep-2010 [3275x2] | Hi Brian, Man, do you ever sleep -- you were up late last night, or are you somewhere around the globe? Yes the Decode did work when I did this: html-blk: decode 'markup to-binary read http://www.rebol.com/docs/reference.html Is there an easy way to parse out the html stuff and get ONLY the text parts? |
I am guessing I could use "remove-each item html-blk [tag? item] .. I'll give it a try. | |
Maxim 23-Sep-2010 [3277x2] | remove-each item html-blk [tag? item] |
hehe | |
PatrickP61 23-Sep-2010 [3279] | lol |
Maxim 23-Sep-2010 [3280] | confirmed... you are now an official reboler (why are you using Rebol School ;-) |
BrianH 23-Sep-2010 [3281] | You could even remove the TO-BINARY from your code - READ returns a binary. |
PatrickP61 23-Sep-2010 [3282] | I am soooo intimidated by all you expert rebolers -- I'm just playing around getting the hang of it! |
BrianH 23-Sep-2010 [3283x2] | Everyone needs to ask a question here now and again, even if it's rhetorical. Rebol School and I'm New are for everyone :) |
Yes, I do sleep, during the morning (in my time zone). I'm a late-night guy. | |
PatrickP61 23-Sep-2010 [3285x3] | My only excuse is that my wife and I had a fight, and so instead of the couch, I opted for my chair! |
Man, I absolutly love how powerful Rebol is! It is just amazing | |
Ok, I captured the Rebol Quick Reference webpage, and I've removed all html tags. I now have a lot of individual newlines values inside my block. To remove them I tried this: remove-each item html-blk [newline item] to which I got == 944 Then I tried to see it's values: html-blk == [] I guess I deleted all the remaining items huh. What did I do wrong? | |
Maxim 23-Sep-2010 [3288x2] | the remove-each is returning a "truthy" value (not false or none). |
I guess its missing an = :-) | |
BrianH 23-Sep-2010 [3290] | remove-each item html-blk [item = "^/"] |
PatrickP61 23-Sep-2010 [3291x3] | OHHHHHH, so my condition was true for all I see! |
Much better! | |
If I want to remove all items which are either a blank space OR a newline, could I do this: remove-each item html-blk [ item = any [ " " "^/" ] ] It didn't do what I thought it would, Is there a better way to state it? | |
older newer | first last |