AltME: Rebol School

Messages

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.
DocKimbel
The notion of "variable" is different in most other programming languages, that is why I put it between double quotes. The documentation should be extra careful when using that term, because it implies a different underlying model for most newcomers learning Rebol. I would personaly ban it completely from the documentation to avoid confusion.
Ladislav
Also, for Patrick: you confused the things, indeed. This is how you could have done it, alternative #1:
start:  func ['block-name] [
    print rejoin ["start " block-name]
    do get 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
What you should realize is that if you define
start:  func [block-name] [
    print rejoin ["start " block-name]
    do get block-name
    print rejoin ["stop " block-name]
]
and cal the function like this:
start count-to-10
then the START function does not obtain block name, in fact.
Ladislav
Doc wrote: "The answer is yes, you simply define the argument of the function as a lit-word." - again, contradicts the documentation. The specification
start: func ['block-name] ...
does not define the argument as a lit-word. Instead (see the documentation) it specifies that literal argument passing shall be used, passing words literally (without getting their value).
Yet another alternative is:
start:  func [block-name] [
    print rejoin ["start " block-name]
    do get block-name
    print rejoin ["stop " block-name]
]
, in which case, however, the function must be called like this:
start 'count-to-10
, which literally passes the word count-to-10 to the function
DocKimbel
If you want to be nit-picking (as usual), try to be at least accurate when quoting me. I said "you define the argument", not "the specification defines the argument". In the specification block, the 'block-name is a lit-word defined as-is by the user, that doesn't contradict the documentation.
Ladislav
I quoted you using cut and paste, so I do not know what you are talking about.
Also, it is you who is criticinzing the documentation while proving you haven't read it
DocKimbel
You wrote: "The specification [...] does not define the argument as a lit-word." This is a strawman, this is not what I said. But as usual, talking to you is like talking to a brick wall. Your condescendence gets in the way of any normal discussion.
Ladislav
Ok, if you insist, I can adjust the wording:
Using the specification
start: func ['block-name] ...
you do not not define the argument as a lit-word. Instead (see the documentation) you specifiy that literal argument passing shall be used, passing words literally (without getting their value).
Note that what I adjusted is not the citation, though. That remains valid.
DocKimbel
You're still misunderstanding my sentence. I was giving instructions to PatrickP61 to change the word argument in the specification to a lit-word argument. That's all. My sentence has nothing to do with how you interpret the specification block once that change has been done.
PatrickP61
My thanks to all.  My intention was not to start any flame wars!
Ladislav
Why do you think you did?
Bo
Ladislav does not mince words.  Everyone here knows that, so we come to expect it. :-)

GiuseppeC
I have a question on Foreach:
foreach [a b] [1 2 3 4 5 6]  [
    mycode
]
how do I know in "mycode" if I am at the last couple of the serie ? (Even the knowing if I am at the start could be useful)
DocKimbel
If you need such info in the loop body, you should use FORALL instead.

Last message posted 161 weeks ago.