REBOL: Концепция БЛОК
sergey shishkinhttps://telegra.ph/Koncepcii-REBOL-10-06
https://telegra.ph/Altscript-10-02
Blocks are used to hold both code and data. They are a fundamental concept in REBOL and it is important to know how to create and manipulate blocks.
Words
and values
are grouped into blocks
, enclosed in square brackets []
.
Within a block, values and words can be organized in any order and can span any number of lines.
You can see that both code and data use blocks.
Why brackets, not braces? REBOL uses square brackets because they are un-shifted on the US keyboard. Basically, they are easier to type. (Of course, that's not true on non-US keyboards, where it's probably best to setup a keyboard macro for [ and ].) Also, they seemed easier to read than braces (because they render as a cleaner glyph.) Also, REBOL's design was influenced just a small amount by Logo, the language from MIT created to help teach programming in schools.
Accessing strings and blocks
The extension library provides functions for accessing and creating strings and blocks. These functions are access via macros that use the library pointer passed in RX_Init
.
RL_MAKE_BLOCK - make a new block of given length
RL_MAKE_STRING - make a new string of given length and width
RL_MAP_WORDS - map a block of words to their canonical symbol identifiers
RL_FIND_WORD - find word in an array of symbol identifiers
RL_SERIES_INFO - get series info: length, size, etc.
RL_GET_CHAR - get a char from a string
RL_SET_CHAR - set a char in a string
RL_GET_VALUE - get a value from a block
RL_SET_VALUE - set a value in a block
RL_GET_STRING - get string as an arrayIt is likely that more functions will be added as needed.
Note: allocation GC concerns
Code is held in blocks
https://rebol.tiddlyspot.com/#Code%20is%20held%20in%20blocks
Blocks aren't always evaluated
Blocks are not always evaluated. In many cases blocks may be skipped, due to the result of an expression.
Blocks return results
... all use print to display their results. That was done to make them clear, but the print hides an important fact: when evaluated, every block returns a result ... The result of blocks is often used in code, and you will be seeing it in many examples ahead.
Block Types
block! - Blocks of values
paren! - Blocks of values enclosed in parentheses
path! - Paths of values
list! - Linked lists
hash! - Associative arrays
Bitset specification block
https://rebol.tiddlyspot.com/#Bitset%20specification%20block
Block functions
https://rebol.tiddlyspot.com/#Block%20functions
Blocks: Arrays
https://rebol.tiddlyspot.com/#Concepts%3A%20Blocks%3A%20Arrays
Blocks: String Functions
https://rebol.tiddlyspot.com/#Concepts%3A%20Blocks%3A%20String%20Functions
Blocks of Blocks
https://rebol.tiddlyspot.com/#Concepts%3A%20Blocks%3A%20Blocks%20of%20Blocks
Composing Blocks
The compose function is handy for creating blocks from dynamic values. It can be used for creating both data and code.
The compose function takes a block as an argument and returns a block that has each value in the argument block. Values in parentheses are evaluated before the block is returned.
https://rebol.tiddlyspot.com/#Concepts%3A%20Blocks%3A%20Composing%20Blocks
Converting Values to Strings
https://rebol.tiddlyspot.com/#Concepts%3A%20Blocks%3A%20Converting%20Values%20to%20Strings
Paths for Nested Blocks
https://rebol.tiddlyspot.com/#Concepts%3A%20Blocks%3A%20Paths%20for%20Nested%20Blocks
Expressions: Blocks
https://rebol.tiddlyspot.com/#Concepts%3A%20Expressions%3A%20Blocks
Expressions: Trying Blocks
https://rebol.tiddlyspot.com/#Concepts%3A%20Expressions%3A%20Trying%20Blocks
Files: Blocks of Lines
https://rebol.tiddlyspot.com/#Concepts%3A%20Files%3A%20Blocks%20of%20Lines
Parsing: Parsing Blocks and Dialects
https://rebol.tiddlyspot.com/#Concepts%3A%20Parsing%3A%20Parsing%20Blocks%20and%20Dialects