
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses


Task

Create a string variable equal to any text value.

Prepend the string variable with another string literal.

If your language supports any idiomatic ways to do this without referring to the variable twice in one expression, include such solutions.



To illustrate the operation, show the content of the variable.




\ the following functions are commonly native to a Forth system. Shown for completeness
 
: C+!     ( n addr -- ) dup c@ rot + swap c! ;             \ primitive: increment a byte at addr by n
 
: +PLACE  ( addr1 length addr2 -- )                        \ Append addr1 length to addr2
          2dup 2>r  count + swap move 2r> c+! ;
 
: PLACE   ( addr1 len addr2 -- )                           \ addr1 and length, placed at addr2 as counted string
          2dup 2>r  1+  swap  move  2r> c! ;
 
\ Example begins here
: PREPEND ( addr len addr2 -- addr2)
           >R                                              \ push addr2 to return stack
           PAD PLACE                                       \ place the 1st string in PAD
           R@  count PAD +PLACE                            \ append PAD with addr2 string
           PAD count R@   PLACE                            \ move the whole thing back into addr2
           R> ;                                            \ leave a copy of addr2 on the data stack
 
: writeln ( addr -- ) cr count type ;                      \ syntax sugar for testing