World: r3wp
[Rebol School] Rebol School
older newer | first last |
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? | |
Sunanda 23-Sep-2010 [3294] | Does this do the trick? remove-each item html-blk [ find [ " " "^/" ] item] |
PatrickP61 23-Sep-2010 [3295] | Why didn't item = any [ val1 val2] work? How should I be stating something like this? |
BrianH 23-Sep-2010 [3296] | The ANY is calculated independently of the = and first too. So that is equivalent to item = " ". |
Sunanda 23-Sep-2010 [3297] | You'd've had to have written it any [item = " " item = "^/"] |
PatrickP61 23-Sep-2010 [3298x2] | Sunanda, your trick did work. Ok, so then ANY of [something] will return true when something is satisfied, but just stating it the way I did, it was always true because there was no real condition -- so I should always state ANY [with the full conditions inside] right? |
I don't think I communicated that well | |
BrianH 23-Sep-2010 [3300] | No, that makes sense. You got it. |
PatrickP61 23-Sep-2010 [3301] | Oh God, the Rebolers understand me -- I must be starting to talk Rebol now!!! ha |
Sunanda 23-Sep-2010 [3302] | I understand :) ANY is really a short-cut for OR, so: if any [a = 1 b = 2] means if (a = 1) or (b = 2) |
BrianH 23-Sep-2010 [3303] | But the trick is that with ANY it will only evaluate the expressions until it finds the first TRUE? one, not the rest. With OR both the expressions are evaluated. ANY and ALL are used as control structures too. |
Maxim 23-Sep-2010 [3304] | they're even more usefull in R3 now that more functions are none transparent :-) |
PatrickP61 23-Sep-2010 [3305] | Yes, so if I said something like DATA: ANY [ val1 val2] then the first non empty value would be set to DATA right? |
Maxim 23-Sep-2010 [3306] | first true? value (not none not fase) |
BrianH 23-Sep-2010 [3307] | Or less useful, depending on whether the none was an error. Learn to love ASSERT in R3. |
PatrickP61 23-Sep-2010 [3308] | ASSERT? Looking it up now |
Maxim 23-Sep-2010 [3309x2] | for example: 0, "", [] would end up into data. |
brian, is assert faster than its equivalent [any all] combination ? | |
PatrickP61 23-Sep-2010 [3311] | Thank you Maxim and Brian. I enjoy your help! |
BrianH 23-Sep-2010 [3312] | ASSERT is as fast as ANY, but faster once you add the error generation code to the ANY statement. ASSERT/type is *much* faster than ANY. |
Maxim 23-Sep-2010 [3313] | cool |
BrianH 23-Sep-2010 [3314x2] | ASSERT is a great way to integrate your tests right into your code, making TDD irrelevant. The module system uses ASSERT a lot to catch attempts to hack the security. |
For now, at least. We may switch to explicit error generation in some cases, for more informative errors. | |
PatrickP61 6-Oct-2010 [3316] | In R2 I'm trying to define a function that will return back 120% of some values similar to this: scale: func [ val ][ val * 1.2 ] <-- this works but returns a decimal -- I'd like it to return integer, so I tried scale: func [ val ][ to-integer reduce [ val * 1.2 ]] <-- doesn't work -- what am I doing wrong |
GrahamC 6-Oct-2010 [3317x2] | remove the [ ] |
and the reduce | |
older newer | first last |