Menu
  • HOME
  • TAGS

Print binary data to stdout using Rebol

rebol,rebol3,rebol2

In Rebol 2 you can use write-io for unadulterated writing to ports like STDOUT. So your example would look like this: Rebol [] for i 0 255 1 [ write-io system/ports/output to-string to char! i 1 ] Rebol 3 doesn't have write-io and instead uses write so in theory your...

What's the most efficient way to decode a UTF16 binary?

unicode,utf-16,rebol,rebol3

OK, there doesn't seem to be an easy way to do it. So I just added two codecs UTF-16LE/BE for this purpose. See this commit: https://github.com/zsx/r3/commit/630945070eaa4ae4310f53d9dbf34c30db712a21 With this change, you can do: >> b: encode 'utf-16le "hello" == #{680065006C006C006F00} >> s: decode 'utf-16le b == "hello" >> b: encode 'utf-16be...

Evaluating code blocks in Rebol3

rebol3,expression-evaluation

First, I would say it's better to construct a block directly, instead of constructing a string and converting it to a block. But if you really want to do that, this should do the trick: view/options compose/only [ hgroup (load hgroup-data) ] [bg-color: gameback] ...

Write a block array of data to a file

rebol,rebol3

Rebol keeps newlines as they are. But after reading with read/lines you just get a block of items without the newlines. If you want a block of items written as lines separated by newlines, you should write them again with the refinement write/lines and Rebol adds the newlines again. myArray:...

Access word value inside object

object,scope,rebol,rebol3,red

When Rebol creates an object, it collects the (set-)words from the spec first and uses them to create the new object. The words of the new object are initially assigned to none. The spec is then bound to the new object and evaluated. In your first example, you haven't included...

Add to map inside of parse dialect

rebol,rebol3,red

You need to reduce the words quarto_hash and quarto_url if not old [append checksums reduce [quarto_hash quarto_url ]] There is also no need to extract the words of the map, you should be faster with a select direct on the map I would use if not select checksums quarto_hash [...

What's the purpose of #[datatype] constructor in Rebol

rebol,rebol3

This syntactic structure is called "construction syntax" (also see CureCode issue #1955). Its raison d'être is to allow literal forms for values which could not otherwise be directly represented. There are two main classes of situations that require construction syntax. Values which (except for construction syntax) have no separate lexical...

How to extend object by adding a function, and then access original object using self?

rebol,rebol3

Given the workings of "definitional scoping"...your routine defined as does [print self/key] did binding into the enclosing context. That context could be a module or some context we can't see here. But let's introduce a manual context just to show what I mean: context [ key: "OUTER CONTEXT KEY" email-service!:...

How can I turn on a word's new-line state in Rebol?

rebol,rebol3

Seemingly the new-line state is assigned to the word based on whether the assigned value has a preceding new-line at the time of assignment (I'll ruminate on the correctness of that statement for a while). This function reassigns the same value (should retain context) to the word with a new...

How to break out of a subrule once a certain part of the rule is met?

midi,rebol,rebol3,firmata

You'll need to break the loop when it hits sysex-end one way or another. You either match sysex-end each time around the loop and break when it hits, or you only match against everything which is not a sysex-end. The first option obviously brings sysex-end into the subrule, but it...

load a map of hash - object key pair

rebol,rebol3,red

SAVE uses an imperfect but more readable format. Use SAVE/ALL to preserve all values exactly as they should be (SAVE/ALL uses so call serialization format in form of #[datatype! value]). Also, just use LOAD and not DO LOAD to get the data back. DO is not required in this case...

copy/part with pair in REBOL 3

rebol,rebol3

The /part pair! refinement works with images. The pair relates to the x/y coordinates as in >> img: load %image.png == make image! [519x391 #{ 1D2F9F1D2F9F1C2E9E1C2E9E1B2D9D1B2D9D1B2D9D1B2D9D1D2F9F1C2E9E 1A2C9C192B9B192B9B1A2C9C1B2D9D1C2E9E1D2EA01... >> copy/part img 2x2 == make image! [2x2 #{ 1D2F9F1D2F9F1D2F9F1D2F9F }] REBOL/View Image Datatype And here an example how /part series! is working...

If…else if…else in REBOL

switch-statement,rebol,rebol3

The construct you would be looking for would be CASE. It takes a series of conditions and code blocks to evaluate, evaluating the blocks only if the condition is true and stopping after the first true condition is met. theVar: 60 case [ theVar > 60 [ print "Greater than...

Efficient way to fill an array with its own indices in Rebol3

arrays,random,rebol3

If you want random array (block!) why not start with block instead of string in the first place? >> random array/initial length: 10 does [-- length] == [3 10 7 9 2 5 8 6 1 4] ...

What is causing a “word not bound to context” error in this script?

rebol,rebol3,r3-gui

The problem is arising because the anonymous function that is being created by the parse-layout function should be a closure, and it isn't. See the diff at https://gist.github.com/earl/a009454787d9fe4cfaca which fixes the problem.

How to express branch in Rebol PARSE dialect?

parsing,rebol,rebol3

I much favour (where possible) building up a set of grammar rules with positive terms to match target input—I find it's more literate, precise, flexible and easier to debug. In your snippet above, we can identify five core components: space: use [space][ space: charset "^-^/ " [some space] ] word:...

Partial read from urls with READ/PART or READ/SEEK

rebol,rebol3

You can see from the source https://github.com/rebol/rebol/blob/master/src/mezz/prot-http.r#L424 that the read actor does not have any refinements defined. This doesn't mean they can't be defined but at present no decision has been made on whether it should be done by using refinements, or by using a query dialect. You can see...

How do you set initial focus in a layout?

rebol,rebol3,r3-gui

The correct trigger to use is the 'enter trigger when [enter] on-action [focus f] ...

Difference between BREAK and REJECT in PARSE

parsing,rebol,rebol3,red

The truth value produced by break depends on whether the minimum number of iterations in an iterative rule have been reached or not. >> parse "aaabbb" [ some [ "a" break ] to end] == true Here we have matched "a" at least once, and then broken out of the...

save to disk in append mode

rebol,rebol3,red

save is a mezzanine function, that is basically write mold. So it's possible to mimic the save function using write or it's possible to update save function to support /append refinement.

Text and caret in VID or R3-Gui

rebol,rebol3,r3-gui

As you want the conversion on the fly, you can either modify R3-GUI before loading. So load r3-gui.r3 down to your local directory. Then you add the line if key == #"w" [key: #"z"] to the function do-text-key, so it looks like do-text-key: funct [ "Process text face keyboard events."...

Object vs Block

rebol,rebol3

Why not dialect? [h1 10x30 "Hello World!" font arial] Internally I would store it as an object!, because it provides you with an easier manipulation....