Console input and output



Note: console input and output may cause problems if you compile your programs. This makes sense: if you compile it, the console is simply not there! Red Wiki about issues

native! print         Red-by-example        MyCode4fun

print sends data to the console. After the data, it sends a newline character to the console. It evaluates its argument before printing it, that is , it applies a reduce to the argument before printing.

Red []


print "hello"

print 33

print 3 + 5


hello

33

8

native! prin        Red-by-example        MyCode4fun

prin also sends data to the console, but it does NOT send the newline character . It evaluates its argument before printing it.

Red []


prin "Hello"

prin "World"

prin 42


HelloWorld42

function! probe Red-by-example    MyCode4fun

probe prints its argument without evaluation and also returns it.  Remember that print evaluates its argument. probe prints and returns the argument "as it is", so to speak. It's able to show expressions that would cause print to give an error.
It may be used for debugging as a way of showing code (by printing) without changing it.

>> print [3 + 2]

5


>> probe [3 + 2]

[3 + 2]

== [3 + 2]


>> print probe [3 + 2]

[3 + 2]

5


>> a: [circle 5x4 10]

== [circle 5x4 10]


>> print a

*** Script Error: circle has no value

*** Where: print

*** Stack:  


>> probe a

[circle 5x4 10]

== [circle 5x4 10]



Described also here, following mold.

function! input Red-by-example    MyCode4fun

Inputs a string from the console. Notice that any number typed on console are converted to a string.newline character is removed.

Red []


prin "Enter a name: "

name: input

print [name "is" length? name "characters long"]


John

John is 4 characters long

routine! ask  Red-by-example    MyCode4fun

Same as input, but displays a string.

Red []


name: ask "What is your name: "

prin "Your name is "

print name


What is your name: John

Your name is John


< Previous topic                                                                                          Next topic >