Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Rebol/Core User's Guide

From: lmecir::geocities::com at: 11-Oct-2000 13:11

Hi List! Sorry for the length, but some may be interested, I hope... Variables: [Quote] A variable refers to a specific value only within a defined context, such as a block, a function, or an entire program. [End Quote] That seems to be in contradiction with:
>> probe block
[a a a] == [a a a]
>> do probe first block
a == 1
>> do probe second block
a ** Script Error: a has no value. ** Where: do probe second block
>> do probe third block
a == 2 Words: [Quote] For example, -1 and +1 are numbers, not words. [End Quote] The following exceptions to the rule might be interesting:
>> type? probe to word! "-1"
-1 == word!
>> type? probe to word! "+1"
+1 == word!
>> type? probe to word! "{"
{ == word!
>> type? probe to word! "[test]"
[test] == word!
>> type? probe to word! "@#$%^,"
@#$%, == word!
>> type? probe to word! {
{ } == word!
>> type? probe to word! ":a"
:a == word!
>> type? probe to word! "a:"
a: == word!
>> type? probe to word! "a/v"
a/v == word!
>> type? probe to word! "'a"
'a == word! [Quote] Word Format word REBOL's Treatment Evaluates the word. This is the most natural and common way to write words. If the word holds a function, it will be evaluated. Otherwise, the value of the word will be returned. [End Quote] I see the following exceptions to this rule: 1) If the word holds a set-word, the corresponding word is set. 2) If the word holds a lit-word, the corresponding word is returned. 3) If the word holds a path, the path is evaluated and the result of the evaluation is returned. 4) If the word holds a lit-path, the corresponding path is returned. 5) If the word holds a paren, the paren is evaluated and the result of the evaluation is returned. 6) If the word holds a set-path, the corresponding path is set. 7) If the word is unset, an error occurs. Series: page 5-2 [Quote] A series is a set of values organized in a specific order. [End Quote] The problem with this definition is, that it is a little bit incorrect. The reason is as follows: Let's have two mathematical sets: {0} (a set containing zero) and {0,1} (a set containing zero and one). It is obvious, that these are different sets. As opposed to this, it is not a problem to have one Rebol series, that contains only zero and change it to contain both zero and one: series: [0] append series 1 series That is why the correct definition of the series should take into account, that a series is an ordered container used when we want to store/retrieve Rebol values. [Quote] The first position of the block is called its head. [End Quote] This is incorrect, as can be seen here: block: next [1 2 3 4]
>> first block
== 2 But:
>> first head block
== 1 I would use a little bit different definition: Every series has got a position (an integer number), that can be obtained as follows: index? series Series with position 1 is called head. [Quote] The last position is called tail. [End Quote] I would prefer a more consistent wording, e.g.: A series can have a subseries having a higher position. The smallest possible subseries of a series is a series with the highest possible position containing no elements, which is called its tail. The position of the tail is the length of the head series plus one. page 5-6 [Quote] Now the 'colors variable is resting at the tail of the block. ... print tail? colors false [End Quote] An error, IMO. It should be True. page 5-36 [Quote] Although 'str is a local variable, its string value is global. [End Quote] [My Favourite Wording] Although 'str is a local variable, initialized every time Print-it is evaluated, its string value is contained (or referenced?) in the body of Print-it and therefore persistent as long as Print-it exists, or at least as long, as its body references the string in question. [End My Favourite Wording] The main reason for suggesting the changed formulation is, that a sentence: ... string value is global... Doesn't have any meaning a common user (e.g. me) could understand. (How can I tell a global string from "a local one"?) page 5-64 [Quote] Multiple variables can refer to the same series. [End Quote] The above wording underlines variables, but there are other means how to obtain a series (a function result, e.g. Next Series, an element of another series,...) [My Favourite Wording] Multiple Rebol series can be the subseries of the same head series. [End My Favourite Wording] Scope of Variables page 8-30 REBOL/Core User Guide Version 2.3 [Quote] For example, here is a signed if function that evaluates one of three blocks based on the sign of a conditional value: ifs: func [ "If positive do block 1, zero do block 2, minus do 3" condition block1 block2 block3 ][ if positive? condition [return do block1] if negative? condition [return do block3] return do block2 ] print ifs 12:00 - now/time ["morning"]["noon"]["night"] night [End Quote] The above definition doesn't work correctly, because it doesn't have the Throw attribute. [Corrected version] ifs: func [ "If positive do block 1, zero do block 2, minus do 3" [throw] condition block1 block2 block3 ][ either positive? condition [do block1] [ either negative? condition [do block3] [do block2] ] ] print ifs 12:00 - now/time ["morning"]["noon"]["night"] morning [End Corrected Version] Object Functions [Quote] In the case of the bank-account object, the functions for deposit and withdraw can be added to the current definition: bank-account: make bank-account [ deposit: func [amount [money!]] [ balance: balance + amount ] withdraw: func [amount [money!]] [ either negative? balance [ print ["Denied. Account overdrawn by" absolute balance] ][balance: balance - amount] ] ] In the example, notice that the functions are able to refer to the balance directly within the object. That's because the functions are part of the object's context. [End Quote] I don't like the formulation: "...the functions are part of the object's context...". The functions surely use words like '+, '-, 'either, which aren't part of the object's context (are they?), moreover, I am sure I don't even know, what that should mean. Objects Referring to Self 9-12 REBOL/Core User Guide Version 2.3 [Quote] Every object includes a predefined variable called self. Within the context of an object, the self variable refers to the object itself. It can be used to pass the object to other functions or to return it as a result of a function. [End Quote] The above is true with the following exception: o: make object! [a: 11] o/self: 12 -Ladislav