Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
2
Task/Copy-a-string/COBOL/copy-a-string.cobol
Normal file
2
Task/Copy-a-string/COBOL/copy-a-string.cobol
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
MOVE "Hello" TO src
|
||||
MOVE src TO dst
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
VAR
|
||||
str1: ARRAY 128 OF CHAR;
|
||||
str2: ARRAY 32 OF CHAR;
|
||||
str3: ARRAY 25 OF CHAR;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
str1 := "abcdefghijklmnopqrstuvwxyz";
|
||||
str3 := str1; (* don't compile, incompatible assignement *)
|
||||
str3 := str1$; (* runtime error, string too long *)
|
||||
str2 := str1$; (* OK *)
|
||||
|
|
@ -1,2 +1,13 @@
|
|||
val src = "Hello"
|
||||
val des = src
|
||||
val src = "Hello"
|
||||
// Its actually not a copy but a reference
|
||||
// That is not a problem because String is immutable
|
||||
// In fact its a feature
|
||||
val des = src
|
||||
assert(src eq des) // Proves the same reference is used.
|
||||
// To make a real copy makes no sense.
|
||||
// Actually its hard to make a copy, the compiler is too smart.
|
||||
// mkString, toString makes also not a real copy
|
||||
val cop = src.mkString.toString
|
||||
assert((src eq cop)) // Still no copyed image
|
||||
val copy = src.reverse.reverse // Finally double reverse makes a copy
|
||||
assert(src == copy && !(src eq copy))// Prove, but it really makes no sense.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue