Macaulay2 » Documentation
Packages » Macaulay2Doc > The Macaulay2 language > getting input from the user
next | previous | forward | backward | up | index | toc

getting input from the user

The function read can be used to prompt the user and obtain a line of input as a string. In response to the prompt, the user enters sample and press return.
i1 : filename = read "file name : "
file name : sample

o1 = sample
Let's use peek to verify that this string contains no newline characters.
i2 : peek filename

o2 = "sample"
If necessary, we may use value to evaluate the string provided by the user. In this example, we enter (x+y)^2 in response to the prompt.
i3 : R = ZZ[x,y];
i4 : s = read "polynomial : "
polynomial : (x+y)^2

o4 = (x+y)^2
i5 : value s

      2           2
o5 = x  + 2x*y + y

o5 : R