1. question about repeat() function
- Posted by jessedavis Apr 16, 2010
- 1371 views
I do not understand the following behavior of the repeat() function. According to the book repeat("*",10) should return a sequence of 10 *. If I try to print the string I get the sequence in character string error. We appear to be back to the extra set of braces problem or is there a subtle difference between a character sequence and a general sequence? Any help appreciated. Thx
sequence txt txt = repeat("*",10) include std/pretty.e pretty_print(1,txt,{}) printf(1,"%d\n",length(txt)) printf(1,"%s\n",{txt}) --if remove braces get one * as expected
{ {42'*'}, {42'*'}, {42'*'}, {42'*'}, {42'*'}, {42'*'}, {42'*'}, {42'*'}, {42'*'}, {42'*'} }10 test.ex:6 sequence found inside character string --> See ex.err
2. Re: question about repeat() function
- Posted by ArthurCrump Apr 16, 2010
- 1351 views
repeat('*',10) will produce "**", repeating the single character '*'.
repeat("*",10) is different, because "*" is a sequence and the entire sequence is repeated.
3. Re: question about repeat() function
- Posted by jessedavis Apr 16, 2010
- 1321 views
Thanks for the help. Right on the spot! Regards, jd
4. Re: question about repeat() function
- Posted by _tom (admin) Apr 16, 2010
- 1307 views
Single( ' ) quotes are to delimit an characer-- which is just an atom.
Double-quotes( " ) are used to delimit a string-- which is a sequence, that is to say a sequence of characters.
Thus
s = "string"
is the same as:
s = { 's', 't', 'r', 'i', 'n', 'g' }
It is critical to see that 'a', and "a" are not the same (first is an atom, and the second is a sequence with one element).
This should help in understanding why A.C's explaination works.
5. Re: question about repeat() function
- Posted by jessedavis Apr 18, 2010
- 1297 views
Tom, Thanks for you help. Fog may be starting to clear!
regards, jd