rebol

How to mix together string parsing and block parsing in the same rule?

给你一囗甜甜゛ 提交于 2019-12-05 11:59:58
It's cool that Rebol's PARSE dialect is generalized enough that it can do pattern matching and extraction on symbolic structures as well as on strings. Like this: ; match a single "a" character, followed by any number of "b" chars >> string-rule: ["a" some "b"] >> parse "abb" string-rule == true >> parse "aab" string-rule == false ; look for a single apple symbol, followed by any number of bananas >> block-rule: ['apple some 'banana] >> parse [apple banana banana] block-rule == true >> parse [apple apple banana] block-rule == false But let's say I'm looking for a block containing an apple

How do I pass a URL a cookie using Rebol 3?

我只是一个虾纸丫 提交于 2019-12-05 11:09:01
Using R3, I need to get a localized version of a page from a website that uses cookies to handle this. In REBOL 2.x, I could do this: page: http://www.rci.com/resort-directory/resortDetails?resortCode=0450 read/custom page [header [Cookie: "USER_LOCALE=fr_FR"]] Based on the sketchy docs for R3, I should be able to do something like: result: write page [GET [Cookie: "USER_LOCALE"] {fr_FR}] Anyone have any ideas? The R2 method worked well, but since R2 doesn't handle UTF-8 needed for many foreign languages it's of little use to me here. ** Update ** The solution (restated) in R2 for my example

Is there an equivalent to “continue” (python) in rebol?

此生再无相见时 提交于 2019-12-05 10:32:09
I am converting some python code to rebol, and I just came across a "continue" instruction. It interrupts the processing of a loop, going to the next iteration of the loop. I find this word quite elegant and readable. I came across some answers there: (in French), but nothing really "elegant": http://pl.legoff.free.fr/dotclear/vf/index.php/post/2003/01/05/Equivalent-d-un-Continue-ou-Next-dans-une-bouc As this converation is about 10 years old, maybe some improvements were made in Rebol since? DocKimbel You can do it in Rebol2 using exceptions: continue: does [throw 'continue] loop 2 [ catch [

Dynamically adding words to a context in REBOL

一世执手 提交于 2019-12-05 04:16:55
Imagine the following REBOL code: foo: context [bar: 3] I now have a context foo in which 'bar is defined. How can I dynamically inject a new word into this context? Is it possible? I've tried: set/any in foo 'baz 3 But that doesn't work because the expression in foo 'baz fails because there is no word 'baz defined in the foo context. I should add that I realize one way to do this is as follows: foo-prototype: [bar: 3] foo: context foo-prototype foo: context head append foo-prototype [baz: 3] But what if you don't have access to foo 's prototype block? You can achieve the same by using the

How to parse inside HTML tags with REBOL?

谁说我不能喝 提交于 2019-12-04 12:32:48
I have a web page that I've loaded with load/markup. I need to parse a bunch of stuff out of it, but some of the data is in the tags. Any ideas of how I can parse it? Here's a sample of what I've got (and tried) so far: REBOL [] mess: { <td>Bob Sockaway</td> <td><a href=mailto:bsockaway@example.com>bsockaway@example.com</a></td> <td>9999</td> } rules: [ some [ ; The expression below /will/ work, but is useless because of specificity. ; <td> <a href=mailto:bsockaway@example.com> s: string! </a> (print s/1) </td> | ; The expression below will not work, because <a> doesn't match <a mailto=...> ;

How to get the response content of an HTTP 404 response

若如初见. 提交于 2019-12-04 09:47:22
Is there an easier way of getting the content of an HTTP 404 response than directly accessing the host via tcp? This is a sample of a 404 response with content: HTTP/1.1 404 Object Not Found Server: CouchDB/1.3.0 (Erlang OTP/R15B03) Date: Wed, 24 Jul 2013 08:32:50 GMT Content-Type: text/plain; charset=utf-8 Content-Length: 41 Cache-Control: must-revalidate {"error":"not_found","reason":"missing"} The Rebol HTTP scheme really isn't designed with this in mind, it's geared toward reading content the way you would in a browser, not services over HTTP. In saying that, you can hack the protocol to

When I use error? and try, err need a value

守給你的承諾、 提交于 2019-12-04 09:38:18
Here my function that execute cmd as a Rebol instructions : exec-cmd: func [ cmd [ block! ] "Rebol instructions" /local err ] [ if error? err: try [ do cmd ] [ print mold disarm err ] ] When I launch the function, I've encountered the following error message : ** Script Error: err needs a value ** Where: exec-cmd ** Near: if error? err: try [ do cmd ] How can I avoid this message and manage the error ? When the Rebol default evaluator sees a sequence of a SET-WORD! followed by a "complete" expression, it will assign the result of that expression to the named word. However, Rebol has the

REBOL 3 - Where can user defined namespace words be accessed?

落花浮王杯 提交于 2019-12-04 07:48:17
Lets say I define a few words: Word1: 5 Word2: "blahdiddyblah" Is there some part or block of the system that stores which words are in use? Tried something like this but it failed: S1: to-block copy system/contexts/user D: 3 S2: to-block copy system/contexts/user Difference s1 s2 According to @johnk suggestion, I tried: >> snapshot-of-words: words-of system/contexts/user == [system snapshot-of-words words-of contexts user] >> x: 1 == 1 >> difference snapshot-of-words words-of system/contexts/user == [x difference] >> difference snapshot-of-words words-of system/contexts/user == [x difference]

What is the 'reword' function in Rebol and how do I use it?

梦想的初衷 提交于 2019-12-03 12:22:49
I saw someone mention the reword function today, but documentation for it is very brief. It looks like shell script environment variable substitution, or maybe regex substitution, but different. How do I use this function and what kind of gotchas am I going to run into? Here there be dragons! The reword function is a bit of an experiment to add shell-style string interpolation to Rebol in a way that works with the way we do things. Unlike a lot of Rebol's series functions, it really is optimized for working on just string types, and the design reflects that. The current version is a design

Avoiding recursion when reading/writing a port synchronously?

北城以北 提交于 2019-12-03 10:20:57
问题 All port operations in Rebol 3 are asynchronous. The only way I can find to do synchronous communication is calling wait . But the problem with calling wait in this case is that it will check events for all open ports (even if they are not in the port block passed to wait). Then they call their responding event handlers, but a read/write could be done in one of those event handlers. That could result in recursive calls to "wait". How do I get around this? 回答1: Why don´t you create a kind of