AltME: Rebol School

Messages

Henrik
Marco, does the /PAD refinement to SET give you anything?

Gregg
What doesn't work Marco?
Endo
I use the following function:
build-object: func [
    "Builds an object from a block"
    names [block!] "Field names"
    /values val [block!] "Initial values"
    /local o name value
] [
    o: copy []
    names: compose names
    o: either values [
        parse names [some [set name [word! | set-word!] (append o to-set-word name) | skip]]
        set/pad reflect o: context append o none 'words val
        o
    ] [
        if any [
            parse names [some [set name [word! | set-word!] (append o reduce [to-set-word name none])]]
            parse names [(clear o) some [set name [word! | set-word!] set value any-type! (append o reduce [to-set-word name :value])]]
        ] [context o]
    ]
    o
]
It supports following uses:
build-object [a b c] [1 2 3]
build-object/values [a b c] [1 2 3]
build-object/values [a b c] [1 2]
build-object/values [a b c] [1 2 3 4]
build-object [a: 1 b: 2]
build-object [a: 2 b: 2 c]
build-object/values [a: 1 b: 2 c d] [3 4 5]
x: 3 probe build-object [a: 1 b (x)]
It's for R2 but can be update to run on R3.
The first example should be: build-object [a b c] ; == context [a: b: c: none]

Endo
I found a difference between (R2.7.6 + r2-forward) and R2.7.8,
SELECT doesn't accept object! type in 2.7.6.
Is it not possible to make it compatible with 2.7.8s SELECT function in r2-forward? As R3s SELECT accepts object! type too.
Maxim
you shoudn't use 2.7.6 there are quite a few things improved and a few crashes too.
"improved since"

Endo
Is there any change log?
Maxim
I am sure there is one somewhere on the Rebol.com site.

Marco
I do not want to create a new object, nor pad "empty" values with none(s). I want to assign some strings (or something else) found in a block to some specific set-words of an existing object.

PatrickP61
What am I doing wrong with this code in r3:
start:  func [block-name] [
    print rejoin ["start " block-name]
    do  block-name
    print rejoin ["stop " block-name]
]
count-to-10:    [
    for x 1 10 1 [prin x prin " "]
    print " "
]
print "ready to start"
start count-to-10
I get this:
ready to start
start for x 1 10 1 prin x prin   print
1 2 3 4 5 6 7 8 9 10
stop for x 1 10 1 prin x prin   print
-- but I wanted:
ready to start
start count-to-10
1 2 3 4 5 6 7 8 9 10
stop count-to-10
-- how do I pass to START the string of the block to eventually DO?  I want the function to expect a string -- even if that string has already been defined as a block.  i.e.  I don't want the block to be evaluated just yet.
If I use START 'COUNT-TO-10   instead, and then use DO REDUCE BLOCK-NAME, It still doesn't work right.
I want to pass BLOCK-NAME unevaluated (as a string) to START
Have it print the message of what it is starting and the string name
then perform the DO and evaluate the string into a block
then print the stop message of the string name
Just unsure how to control evaluations
DocKimbel
The following version should run just fine:
start:  func [block-name] [
    print ["start" mold block-name]
    do get block-name
    print ["stop" mold block-name]
]
count-to-10:    [
    for x 1 10 1 [prin x prin " "]
    print " "
]
print "ready to start"
start 'count-to-10
PatrickP61
I understand the quote ' will tell rebol this is a string.
Is it at all possible to define a function to accept a string, even if it is defined as a block?  i.e. be able to say START COUNT-TO-10   (without the quote '   )?
DocKimbel
"I understand the quote ' will tell rebol this is a string."
No, the quote denotes a literal word (lit-word! datatype). Strings are enclosed in "..." or {...}.
In your previous posts, you incorrectly use "string" (sequence of characters) to talk about words (which are symbols).
PatrickP61
Yes,  I see what you mean now, I meant words!
DocKimbel
"Is it at all possible to define a function to accept a string, even if it is defined as a block?" Even if I replace "string" by "word" in your sentence, it is still very confused. Words are not "variables" in Rebol-like languages, they exist by themselves (unlike in most other languages). So a word is not "defined as", but "refers to". A word can refer to a value. A word is a value too.
" i.e. be able to say START COUNT-TO-10   (without the quote '   )?" This part is correctly formulated. :-) The answer is yes, you simply define the argument of the function as a lit-word. For example:
start:  func ['block-name] [
    print ["start" mold block-name]
    do get block-name
    print ["stop" mold block-name]
]
PatrickP61
Wow, that worked perfectly!!!   I'm not sure why it works, but it does.
Thank you DocKimbel
Just to clarify:  when rebol sees the word START, it knows that I've already defined some code and will reference that block with a following argument for block-name.
when rebol sees the word COUNT-TO-10, it also knows that is already defined etc and will reference that code, but because the argument is defined as a lit-word in START, it is not evaluated yet.
Do I have that right?
Just getting my head around it!
Bo
PatrickP61:  Yes, that is correct.
Ladislav
Doc wrote: 'Words are not "variables" in Rebol-like languages' - that contradicts the documentation. Documentation states that words can be used as variables if they are bound to a context.

Last message posted 184 weeks ago.