Wiki

Changes between Initial Version and Version 1 of Print

Show
Ignore:
Timestamp:
05/04/10 12:44:53 (15 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Print

    v1 v1  
     1= Print =  
     2 
     3Print the given expression or expressionlist. 
     4e.g.  
     5{{{ 
     6print 'My name is Cobra.' 
     7}}} 
     8 
     9Lacking any 'to DEST' clause the expressions provided are printed to the standard output with a trailing  
     10line terminator (\n or \r\n depending on platform). 
     11 
     12This trailing line terminator may be suppressed with a terminating 'stop'  
     13token after the expression list. ( There is no ',' before this token) 
     14{{{ 
     15print 'No newline' stop  
     16}}} 
     17  
     18Multiple comma separated expressions are printed each separated by a  
     19single space. 
     20{{{ 
     21print 'No moa', 'No moa', 'in all aotearoa'  
     22# emits 'No moa No moa in all aotearoa\n'   
     23}}} 
     24 
     25If a 'to DEST' clause is given the expression list is printed to that 
     26destination which must be a !TextWriter or subclass. 
     27 
     28The final form of the print statement given below does not print anything but sets up 
     29a (!TextWriter or subclass) redirection destination for any print  
     30statements in the subsequent block. 
     31 
     32Any and all of string expression interpolation and String.format 
     33processing can be specified within the expressions of the expression list. 
     34 
     35== Grammar == 
     36{{{ 
     37print 
     38 
     39print [to DEST,] <expression> [, expression ...] [ stop] 
     40 
     41print to DEST 
     42    BLOCK 
     43}}} 
     44 
     45== Platform == 
     46.Net: the destination must be a System.IO.!TextWriter or subclass. 
     47 
     48== Examples == 
     49{{{ 
     50print   # emit a blank line 
     51print 'Hello World' 
     52}}} 
     53 
     54{{{ 
     55print 'Prompt:' stop 
     56input = Console.readline 
     57 
     58print a,b,c stop 
     59print d 
     60# a b c d all end up on the same line 
     61}}} 
     62 
     63{{{ 
     64print "one", '2', 'free'  
     65# emits 'one 2 free\n' 
     66 
     67i = 2 
     68s = 'free' 
     69print 'one [i] [s]' # same output as above 
     70}}} 
     71 
     72{{{ 
     73 
     74# print to std error 
     75print to Console.error,  'error: all froobits bedazzled' 
     76 
     77sw = StringWriter() 
     78print to sw 
     79    print "Redirected to the StringWriter' 
     80s = sw.toString 
     81assert s.contains('Redirected to the StringWriter')     
     82}}} 
     83 
     84 
     85== Notes == 
     86 
     87Non string expressions are converted to a string representation for printing  
     88(presumably using their toString methods). 
     89 
     90Collections are expanded so their contents are displayed using  
     91{{{CobraCore.PrintStringMaker.makeString}}}  
     92(++ This needs expansion/explanation ++ ) 
     93 
     94See discussion forum [http://cobra-language.com/forums/viewtopic.php?f=4&t=160  Print vs Console.Writeline]