Slowly learning, bit confused
Hi, I'm trying a simple REBOL script that inputs a name and then prints it in uppercase (to practice using functions).
When it's run, the name is entered in lower case, the function is called but then when I try "print low-name up-name" (which should print the lower case version and upper case version), the original has been turned into upper.
I'm assuming it's the way I pass the variable to the function, but could do with a clue about where to fix it.
Thanks in advance
R E B O L [
Title: "Brian Test Program"
Author: "Brian Turner"
Purpose: (Test stuff out in Rebol)
This is a function that doesn't return a value (like a SUB)
- uses the "does" command
print-hello: does [print "Hello"]
This is a function that returns a value
- uses "func" command
upper-name: func [arg1] [return uppercase arg1]
prin "What is your name: "
up-name: upper-name low-name
prin [low-name "-> "]
posted by: Brain 14-Apr-2014/6:22:43-7:00
The 'uppercase functions actually alters the input string:
>> uppercase x
'Sort and some other series manipulation functions do this. Use a copy of the string as the argument to the function:
upper-name: func [arg1] [uppercase copy arg1]
BTW, does  is just a shortcut for func . It still returns a value.
posted by: Nick 14-Apr-2014/8:05:05-7:00
Thanks, that explains it. I couldn't find the command for just passing a copy of the original.
I think I also misunderstood the "does" block and assumed that as it didn't take a value then it didn't return anything to the code that called it.
posted by: Brain 14-Apr-2014/11:25:39-7:00