1. question about repeat() function

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  
 

new topic     » topic index » view message » categorize

2. Re: question about repeat() function

repeat('*',10) will produce "**", repeating the single character '*'.
repeat("*",10) is different, because "*" is a sequence and the entire sequence is repeated.

new topic     » goto parent     » topic index » view message » categorize

3. Re: question about repeat() function

Thanks for the help. Right on the spot! Regards, jd

new topic     » goto parent     » topic index » view message » categorize

4. Re: question about repeat() function

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.

new topic     » goto parent     » topic index » view message » categorize

5. Re: question about repeat() function

Tom, Thanks for you help. Fog may be starting to clear!

regards, jd

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu