WeixiangYan/CodeTransOcean huggingface dataset:
Task: String comparison


C++: #include <algorithm>
#include <iostream>
#include <sstream>
#include <string>

template <typename T>
void demo_compare(const T &a, const T &b, const std::string &semantically) {
    std::cout << a << " and " << b << " are " << ((a == b) ? "" : "not ")
              << "exactly " << semantically << " equal." << std::endl;

    std::cout << a << " and " << b << " are " << ((a != b) ? "" : "not ")
              << semantically << "inequal." << std::endl;

    std::cout << a << " is " << ((a < b) ? "" : "not ") << semantically
              << " ordered before " << b << '.' << std::endl;

    std::cout << a << " is " << ((a > b) ? "" : "not ") << semantically
              << " ordered after " << b << '.' << std::endl;
}

int main(int argc, char *argv[]) {
    
    std::string a((argc > 1) ? argv[1] : "1.2.Foo");
    std::string b((argc > 2) ? argv[2] : "1.3.Bar");
    demo_compare<std::string>(a, b, "lexically");

    
    std::transform(a.begin(), a.end(), a.begin(), ::tolower);
    std::transform(b.begin(), b.end(), b.begin(), ::tolower);
    demo_compare<std::string>(a, b, "lexically");

    
    
    double numA, numB;
    std::istringstream(a) >> numA;
    std::istringstream(b) >> numB;
    demo_compare<double>(numA, numB, "numerically");
    return (a == b);
}









Fortran:       PRINT 42,N
   42 FORMAT (14HThe answer is ,I9)
Task: Verify distribution uniformity_Naive


C++: #include <map>
#include <iostream>
#include <cmath>

template<typename F>
 bool test_distribution(F f, int calls, double delta)
{
  typedef std::map<int, int> distmap;
  distmap dist;

  for (int i = 0; i < calls; ++i)
    ++dist[f()];

  double mean = 1.0/dist.size();

  bool good = true;

  for (distmap::iterator i = dist.begin(); i != dist.end(); ++i)
  {
    if (std::abs((1.0 * i->second)/calls - mean) > delta)
    {
      std::cout << "Relative frequency " << i->second/(1.0*calls)
                << " of result " << i->first
                << " deviates by more than " << delta
                << " from the expected value " << mean << "\n";
      good = false;
    }
  }

  return good;
}









Fortran: subroutine distcheck(randgen, n, delta)

  interface
    function randgen
      integer :: randgen 
    end function randgen
  end interface
  
  real, intent(in) :: delta
  integer, intent(in) :: n
  integer :: i, mval, lolim, hilim
  integer, allocatable :: buckets(:)
  integer, allocatable :: rnums(:)
  logical :: skewed = .false.
     
  allocate(rnums(n))
  
  do i = 1, n
    rnums(i) = randgen()
  end do

  mval = maxval(rnums)
  allocate(buckets(mval))
  buckets = 0
  
  do i = 1, n
    buckets(rnums(i)) = buckets(rnums(i)) + 1
  end do

  lolim = n/mval - n/mval*delta
  hilim = n/mval + n/mval*delta
  
  do i = 1, mval  
    if(buckets(i) < lolim .or. buckets(i) > hilim) then
      write(*,"(a,i0,a,i0,a,i0)") "Distribution potentially skewed for bucket ", i, "   Expected: ", &
                                   n/mval, "   Actual: ", buckets(i)
      skewed = .true.
    end if
  end do 

  if (.not. skewed) write(*,"(a)") "Distribution uniform"
  
  deallocate(rnums)
  deallocate(buckets)
    
end subroutine
Task: Use another language to call a function


C++: #include <string>
using std::string;


extern "C" int
Query (char *Data, size_t *Length)
{
   const string Message = "Here am I";

   
   if (*Length < Message.length())
      return false;  

   *Length = Message.length();
   Message.copy(Data, *Length);
   return true;
}









Fortran: 


function  fortran_query(data, length) result(answer) bind(c, name='Query')
   use, intrinsic  :: iso_c_binding, only: c_char, c_int, c_size_t, c_null_char
   implicit none
   character(len=1,kind=c_char), dimension(length),  intent(inout) ::  data
   integer(c_size_t), intent(inout) :: length
   integer(c_int) :: answer
   answer = 0
   if(length<10) return
   data = transfer("Here I am"//c_null_char, data)
   length = 10_c_size_t
   answer = 1
end function fortran_query
Task: ABC words







Python: python -c '
import sys
for ln in sys.stdin:
    if "a" in ln and ln.find("a") < ln.find("b") < ln.find("c"):
        print(ln.rstrip())
' < unixdict.txt



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC-WORDS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 WORD            PIC X(32).
       
       WORKING-STORAGE SECTION.
       01 A               PIC 99.
       01 B               PIC 99.
       01 C               PIC 99.
       01 X               PIC 99.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       READ-WORD.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORD.
           
       CHECK-WORD.
           MOVE ZERO TO A, B, C, X.
           INSPECT WORD TALLYING A FOR CHARACTERS BEFORE INITIAL 'a'.
           INSPECT WORD TALLYING B FOR CHARACTERS BEFORE INITIAL 'b'.
           INSPECT WORD TALLYING C FOR CHARACTERS BEFORE INITIAL 'c'.
           INSPECT WORD TALLYING X FOR CHARACTERS BEFORE INITIAL ' '.
           IF A IS LESS THAN B 
           AND B IS LESS THAN C 
           AND C IS LESS THAN X,
               DISPLAY WORD.
Task: Two identical strings







Python: def bits(n):
    
    r = 0
    while n:
        n >>= 1
        r += 1
    return r
    
def concat(n):
    
    return n << bits(n) | n
    
n = 1
while concat(n) <= 1000:
    print("{0}: {0:b}".format(concat(n)))
    n += 1



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  IDENTICAL-STRINGS.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 INPUT-NUMBER            PIC 9(4).
          03 BINARY-REPRESENTATION   PIC 9(10).
          03 BIT                     REDEFINES BINARY-REPRESENTATION,
                                     PIC 9 OCCURS 10 TIMES.
          03 FIRST-SET-BIT           PIC 99.
          03 CURRENT-BIT             PIC 99.
          03 SECOND-BIT              PIC 99.
          03 BIT-VALUE               PIC 9(4).
          03 OUTPUT-NUMBER           PIC 9(4) VALUE ZERO.
          03 REMAINING-BITS          PIC 9(4)V9.
          03 FILLER                  REDEFINES REMAINING-BITS.
             05 REST                 PIC 9(4).
             05 FILLER               PIC 9.
                88 BIT-IS-SET        VALUE 5.

       01 OUTPUT-FORMAT.
          03 DECIMAL-OUTPUT          PIC Z(3)9.
          03 BINARY-OUTPUT           PIC Z(9)9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM IDENTICAL-STRING
               VARYING INPUT-NUMBER FROM 1 BY 1
               UNTIL OUTPUT-NUMBER IS GREATER THAN 1000.
           STOP RUN.

       IDENTICAL-STRING.
           MOVE ZERO TO BINARY-REPRESENTATION.
           MOVE 10 TO CURRENT-BIT.
           MOVE INPUT-NUMBER TO REMAINING-BITS.
           PERFORM EXTRACT-BIT UNTIL REMAINING-BITS EQUAL ZERO.
           MOVE CURRENT-BIT TO FIRST-SET-BIT.
           MOVE 10 TO SECOND-BIT.
           PERFORM COPY-BIT UNTIL SECOND-BIT IS EQUAL TO FIRST-SET-BIT.
           MOVE ZERO TO OUTPUT-NUMBER.
           IF CURRENT-BIT IS EQUAL TO ZERO, MOVE 1 TO CURRENT-BIT.
           PERFORM INSERT-BIT
               VARYING CURRENT-BIT FROM CURRENT-BIT BY 1
               UNTIL CURRENT-BIT IS GREATER THAN 10.
           MOVE OUTPUT-NUMBER TO DECIMAL-OUTPUT.
           MOVE BINARY-REPRESENTATION TO BINARY-OUTPUT.
           IF OUTPUT-NUMBER IS LESS THAN 1000,
               DISPLAY DECIMAL-OUTPUT ": " BINARY-OUTPUT.

       EXTRACT-BIT.
           DIVIDE 2 INTO REMAINING-BITS.
           IF BIT-IS-SET, MOVE 1 TO BIT(CURRENT-BIT).
           SUBTRACT 1 FROM CURRENT-BIT.
           MOVE REST TO REMAINING-BITS.

       COPY-BIT.
           MOVE BIT(SECOND-BIT) TO BIT(CURRENT-BIT).
           SUBTRACT 1 FROM SECOND-BIT.
           SUBTRACT 1 FROM CURRENT-BIT.

       INSERT-BIT.
           COMPUTE BIT-VALUE = 2 ** (10 - CURRENT-BIT)
           MULTIPLY BIT(CURRENT-BIT) BY BIT-VALUE.
           ADD BIT-VALUE TO OUTPUT-NUMBER.
Task: Sum of first n cubes







Python: def main():
    fila = 0
    lenCubos = 51

    print("Suma de N cubos para n = [0..49]\n")

    for n in range(1, lenCubos):
        sumCubos = 0
        for m in range(1, n):
            sumCubos = sumCubos + (m ** 3)
            
        fila += 1
        print(f'{sumCubos:7} ', end='')
        if fila % 5 == 0:
            print(" ")

    print(f"\nEncontrados {fila} cubos.")

if __name__ == '__main__': main()



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  SUM-OF-CUBES.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 STEP         PIC 99.
          03 CUBE         PIC 9(7).
          03 CUBE-SUM     PIC 9(7) VALUE 0.
 
       01 OUTPUT-FORMAT.
          03 OUT-LINE     PIC X(40) VALUE SPACES.
          03 OUT-PTR      PIC 99 VALUE 1.
          03 OUT-NUM      PIC Z(7)9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM ADD-CUBE VARYING STEP FROM 0 BY 1
               UNTIL STEP IS EQUAL TO 50.
           STOP RUN.

       ADD-CUBE.
           COMPUTE CUBE = STEP ** 3.
           ADD CUBE TO CUBE-SUM.
           MOVE CUBE-SUM TO OUT-NUM.
           STRING OUT-NUM DELIMITED BY SIZE INTO OUT-LINE
               WITH POINTER OUT-PTR.
           IF OUT-PTR IS EQUAL TO 41,
               DISPLAY OUT-LINE,
               MOVE 1 TO OUT-PTR.
Task: Count how many vowels and consonants occur in a string







Python: def isvowel(c):
    
    return c in ['a', 'e', 'i', 'o', 'u', 'A', 'E', "I", 'O', 'U']

def isletter(c):
    
    return 'a' <= c <= 'z' or 'A' <= c <= 'Z'

def isconsonant(c):
    
    return  not isvowel(c) and isletter(c)

def vccounts(s):
    
    a = list(s.lower())
    au = set(a)
    return sum([isvowel(c) for c in a]), sum([isconsonant(c) for c in a]), \
        sum([isvowel(c) for c in au]), sum([isconsonant(c) for c in au])

def testvccount():
    teststrings = [
        "Forever Python programming language",
        "Now is the time for all good men to come to the aid of their country."]
    for s in teststrings:
        vcnt, ccnt, vu, cu = vccounts(s)
        print(f"String: {s}\n    Vowels: {vcnt} (distinct {vu})\n    Consonants: {ccnt} (distinct {cu})\n")

testvccount()



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. VOWELS-AND-CONSONANTS.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 CONSTANTS.
          03 LETTERS-DAT.
             05 FILLER      PIC X(5) VALUE "AEIOU".
             05 FILLER      PIC X(5) VALUE "aeiou".
             05 FILLER      PIC X(21) VALUE "BCDFGHJKLMNPQRSTVWXYZ".
             05 FILLER      PIC X(21) VALUE "bcdfghjklmnpqrstvwxyz".
          03 LETTERS        REDEFINES LETTERS-DAT.
             05 VOWELS      PIC X OCCURS 10 TIMES INDEXED BY V.
             05 CONSONANTS  PIC X OCCURS 42 TIMES INDEXED BY C.
      
       01 VARIABLES.
          03 IN-STR         PIC X(80).
          03 N-VOWELS       PIC 99.
          03 N-CONSONANTS   PIC 99.
      
       01 REPORT.
          03 R-VOWELS       PIC Z9.
          03 FILLER         PIC X(9) VALUE " vowels, ".
          03 R-CONSONANTS   PIC Z9.
          03 FILLER         PIC X(12) VALUE " consonants.".
         
       PROCEDURE DIVISION.
       BEGIN.
           MOVE "If not now, then when? If not us, then who?"
           TO IN-STR.
           PERFORM COUNT-AND-SHOW.
           STOP RUN.
          
       COUNT-AND-SHOW.
           DISPLAY IN-STR.
           PERFORM COUNT-VOWELS-AND-CONSONANTS.
           MOVE N-VOWELS TO R-VOWELS.
           MOVE N-CONSONANTS TO R-CONSONANTS.
           DISPLAY REPORT.
       
       COUNT-VOWELS-AND-CONSONANTS.
           MOVE ZERO TO N-VOWELS, N-CONSONANTS.
           SET V TO 1.
           PERFORM COUNT-VOWEL 10 TIMES.
           SET C TO 1.
           PERFORM COUNT-CONSONANT 42 TIMES.
        
       COUNT-VOWEL.
           INSPECT IN-STR TALLYING N-VOWELS FOR ALL VOWELS(V).
           SET V UP BY 1.
       
       COUNT-CONSONANT.
           INSPECT IN-STR TALLYING N-CONSONANTS FOR ALL CONSONANTS(C).
           SET C UP BY 1.
Task: Call a foreign-language function







Python: import ctypes
libc = ctypes.CDLL("/lib/libc.so.6")
libc.strcmp("abc", "def")     
libc.strcmp("hello", "hello") 



COBOL:        identification division.
       program-id. foreign.

       data division.
       working-storage section.
       01 hello.
          05 value z"Hello, world".
       01 duplicate    usage pointer.
       01 buffer       pic x(16) based.
       01 storage      pic x(16).

       procedure division.
       call "strdup" using hello returning duplicate
           on exception
               display "error calling strdup" upon syserr
       end-call
       if duplicate equal null then
           display "strdup returned null" upon syserr
       else
           set address of buffer to duplicate
           string buffer delimited by low-value into storage
           display function trim(storage)
           call "free" using by value duplicate
               on exception
                   display "error calling free" upon syserr
       end-if
       goback.
Task: Disarium numbers







Python: 

def isDisarium(n):
    digitos = len(str(n))
    suma = 0
    x = n
    while x != 0:
        suma += (x % 10) ** digitos
        digitos -= 1
        x //= 10
    if suma == n:
        return True
    else:
        return False

if __name__ == '__main__':
    limite = 19
    cont = 0
    n = 0
    print("The first",limite,"Disarium numbers are:")
    while cont < limite:
        if isDisarium(n):
            print(n, end = " ")
            cont += 1
        n += 1



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. DISARIUM.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 CANDIDATE     PIC 9(9).
          03 DIGITS        PIC 9 OCCURS 9 TIMES, REDEFINES CANDIDATE.
          03 IDX           PIC 99.
          03 EXPONENT      PIC 99.
          03 DGT-POWER     PIC 9(9).
          03 DGT-POWER-SUM PIC 9(9).
          03 CAND-OUT      PIC Z(8)9.
          03 AMOUNT        PIC 99 VALUE 18.
          
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM DISARIUM-TEST VARYING CANDIDATE FROM ZERO BY 1
           UNTIL AMOUNT IS ZERO.
           STOP RUN.
        
       DISARIUM-TEST.
           MOVE ZERO TO DGT-POWER-SUM.
           MOVE 1 TO EXPONENT, IDX.
           INSPECT CANDIDATE TALLYING IDX FOR LEADING ZEROES.
           PERFORM ADD-DIGIT-POWER UNTIL IDX IS GREATER THAN 9.
           IF DGT-POWER-SUM IS EQUAL TO CANDIDATE,
               MOVE CANDIDATE TO CAND-OUT,
               DISPLAY CAND-OUT,
               SUBTRACT 1 FROM AMOUNT.
           
       ADD-DIGIT-POWER.
           COMPUTE DGT-POWER = DIGITS(IDX) ** EXPONENT.
           ADD DGT-POWER TO DGT-POWER-SUM.
           ADD 1 TO EXPONENT.
           ADD 1 TO IDX.
Task: Flow-control structures







Python: 
for i in range(n):
    if (n%2) == 0:
        continue
    if (n%i) == 0:
        result = i
        break
else:
    result = None
    print "No odd factors found"



COBOL:        PROGRAM-ID. Go-To-Example.

       PROCEDURE DIVISION.
       Foo.
           DISPLAY "Just a reminder: GO TOs are evil."

           GO TO Foo
           .
Task: Return multiple values







Python: def addsub(x, y):
  return x + y, x - y



COBOL:        identification division.
       program-id. multiple-values.

       environment division.
       configuration section.
       repository.
           function multiples
           function all intrinsic.

       REPLACE ==:linked-items:== BY ==
       01 a usage binary-long.
       01 b pic x(10).
       01 c usage float-short.
       ==
       ==:record-item:== BY ==
       01 master.
          05 ma usage binary-long.
          05 mb pic x(10).
          05 mc usage float-short.
       ==.

       data division.
       working-storage section.
       :linked-items:

       :record-item:
       
       procedure division.
       sample-main.

       move 41 to a
       move "aaaaabbbbb" to b
       move function e to c

       display "Original: " a ", " b ", " c
       call "subprogram" using a b c
       display "Modified: " a ", " b ", " c
       
       move multiples() to master
       display "Multiple: " ma ", " mb ", " mc

       goback.
       end program multiple-values.

      
       identification division.
       program-id. subprogram.

       data division.
       linkage section.
       :linked-items:

       procedure division using a b c.
       add 1 to a
       inspect b converting "a" to "b"
       divide 2 into c
       goback.
       end program subprogram.

      
       identification division.
       function-id. multiples.

       data division.
       linkage section.
       :record-item:

       procedure division returning master.
       move 84 to ma
       move "multiple" to mb
       move function pi to mc
       goback.
       end function multiples.
Task: Substring_Top and tail







Python: print "knight"[1:]     
print "socks"[:-1]     
print "brooms"[1:-1]   



COBOL:        identification division.
       program-id. toptail.

       data division.
       working-storage section.
       01 data-field.
          05 value "[this is a test]".

       procedure division.
       sample-main.
       display data-field
      
       display data-field(2:)
       display data-field(1:length of data-field - 1)
       display data-field(2:length of data-field - 2)
       goback.
       end program toptail.
Task: Boolean values







Python: >>> True
True
>>> not True
False
>>> 
>>> False + 0
0
>>> True + 0
1
>>> False + 0j
0j
>>> True * 3.141
3.141
>>> 
>>> not 0
True
>>> not not 0
False
>>> not 1234
False
>>> bool(0.0)
False
>>> bool(0j)
False
>>> bool(1+2j)
True
>>> 
>>> bool([])
False
>>> bool([None])
True
>>> 'I contain something' if (None,) else 'I am empty'
'I contain something'
>>> bool({})
False
>>> bool("")
False
>>> bool("False")
True



COBOL:        01  some-bool               PIC 1 BIT.
Task: First 9 prime Fibonacci number







Python: from math import sqrt
from time import time

n = 12
start = time()


def prime(x):
    if x < 2:
        return False
    if x == 2 or x == 3:
        return True
    if x % 2 == 0:
        return False
    for i in range(3, int(sqrt(x)) + 1, 2):
        if x % i == 0:
            return False
    return True


a, b, = 1, 1
fibn = 3
f = []
while len(f) < n:
    a, b, = b, a + b
    if prime(b):
        f.append(b)
        print("fib(%d): %s (%s s)" % (fibn, b, time() - start))
    fibn += 1



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. PRIME-FIBONACCI.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 FIBONACCI-VARS.
          03 FIB                PIC 9(6).
          03 FIB-B              PIC 9(6).
          03 FIB-C              PIC 9(6).
          03 FIB-OUT            PIC Z(5)9.
       01 PRIME-VARS.   
          03 PRIME-FLAG         PIC X.
             88 PRIME           VALUE 'X'.
          03 DSOR               PIC 9(4).
          03 DSOR-SQ            PIC 9(6).
          03 DIV-RSLT           PIC 9(6)V9(3).
          03 FILLER             REDEFINES DIV-RSLT.
             05 FILLER          PIC 9(6).
             05 FILLER          PIC 9(3).
                88 DIVISIBLE    VALUE ZERO.
          
       PROCEDURE DIVISION.
       BEGIN.
           MOVE 1 TO FIB, FIB-B.
           PERFORM FIND-PRIME-FIBONACCI 9 TIMES.
           STOP RUN.
       
       FIND-PRIME-FIBONACCI.
           ADD FIB, FIB-B GIVING FIB-C.
           MOVE FIB-B TO FIB.
           MOVE FIB-C TO FIB-B.
           PERFORM CHECK-PRIME.
           IF NOT PRIME, GO TO FIND-PRIME-FIBONACCI.
           MOVE FIB TO FIB-OUT.
           DISPLAY FIB-OUT.
       
       CHECK-PRIME SECTION.
       BEGIN.
           MOVE SPACE TO PRIME-FLAG.
           IF FIB IS LESS THAN 5, GO TO TRIVIAL-PRIME.
           DIVIDE FIB BY 2 GIVING DIV-RSLT.
           IF DIVISIBLE, GO TO DONE.
           DIVIDE FIB BY 3 GIVING DIV-RSLT.
           IF DIVISIBLE, GO TO DONE.
           MOVE 5 TO DSOR.
           MOVE 25 TO DSOR-SQ.
           MOVE 'X' TO PRIME-FLAG.
           PERFORM TEST-DIVISOR 
           UNTIL NOT PRIME OR DSOR-SQ IS GREATER THAN FIB.
           GO TO DONE.
           
       TEST-DIVISOR.
           DIVIDE FIB BY DSOR GIVING DIV-RSLT.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
           ADD 2 TO DSOR.
           DIVIDE FIB BY DSOR GIVING DIV-RSLT.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
           ADD 4 TO DSOR.
           MULTIPLY DSOR BY DSOR GIVING DSOR-SQ.
       
       TRIVIAL-PRIME.
           IF FIB IS EQUAL TO 2 OR 3, MOVE 'X' TO PRIME-FLAG.
       DONE.
           EXIT.
Task: Terminal control_Inverse video







Python: 

print "\033[7mReversed\033[m Normal"



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. terminal-reverse-video.

       PROCEDURE DIVISION.
           DISPLAY "Reverse-Video" WITH REVERSE-VIDEO
           DISPLAY "Normal"

           GOBACK
           .
Task: Hello world_Line printer







Python: lp = open("/dev/lp0")
lp.write("Hello World!\n")
lp.close()



COBOL: IDENTIFICATION DIVISION.
PROGRAM-ID. GOODBYE-WORLD-PRINTER.

PROCEDURE DIVISION.
DISPLAY 'Hello World!'
	UPON PRINTER
END-DISPLAY.
STOP RUN.
Task: Call a function







Python: def no_args():
    pass

no_args()

def fixed_args(x, y):
    print('x=%r, y=%r' % (x, y))

fixed_args(1, 2)        


fixed_args(y=2, x=1)


myargs=(1,2) 
fixed_args(*myargs)

def opt_args(x=1):
    print(x)

opt_args()              
opt_args(3.141)         

def var_args(*v):
    print(v)

var_args(1, 2, 3)       
var_args(1, (2,3))      
var_args()              


fixed_args(y=2, x=1)    


if 1:
    no_args()


assert no_args() is None

def return_something():
    return 1
x = return_something()

def is_builtin(x):
	print(x.__name__ in dir(__builtins__))

is_builtin(pow)         
is_builtin(is_builtin)  



def takes_anything(*args, **kwargs):
    for each in args:
        print(each)
    for key, value in sorted(kwargs.items()):
        print("%s:%s" % (key, value))
    
    wrapped_fn(*args, **kwargs)
    
    












COBOL: CALL "No-Arguments"


CALL "2-Arguments" USING Foo Bar

CALL "Optional-Arguments" USING Foo
CALL "Optional-Arguments" USING Foo Bar


CALL "Optional-Arguments" USING Foo OMITTED Bar



CALL "2-Arguments" USING Foo






CALL "Some-Func" USING Foo
MOVE Return-Code TO Bar






MOVE FUNCTION PI TO Bar
MOVE FUNCTION MEDIAN(4, 5, 6) TO Bar







CALL "C$MAKEDIR" USING Foo
CALL "CBL_CREATE_DIR" USING Foo
CALL "CBL_OC_NANOSLEEP" USING Bar

CALL X"F4" USING Foo Bar
 










CALL "Modify-Arg" USING BY REFERENCE Foo 
CALL "Modify-Arg" USING BY CONTENT Foo   
CALL "C-Func" USING BY VALUE Bar






ACCEPT Foo 
CALL "Use-Func" USING Foo
CALL Foo USING Bar
Task: Copy a string







Python: >>> src = "hello"
>>> a = src
>>> b = src[:]
>>> import copy
>>> c = copy.copy(src)
>>> d = copy.deepcopy(src)
>>> src is a is b is c is d
True



COBOL: MOVE "Hello" TO src
MOVE src TO dst
Task: Include a file







Python: import one 






COBOL: COPY "copy.cpy". 
COPY "another-copy.cpy" REPLACING foo BY bar
                                  SPACE BY ZERO
                                  ==text to replace== BY ==replacement text==.
Task: String comparison







Python: fun compare(a, b):
    print("\n$a is of type ${typeof(a)} and $b is of type ${typeof(b)}")
    if a < b: print("$a is strictly less than $b")
    if a <= b: print("$a is less than or equal to $b")
    if a >  b: print("$a is strictly greater than $b")
    if a >= b: print("$a is greater than or equal to $b")
    if a == b: print("$a is equal to $b")
    if a != b: print("$a is not equal to $b")
    if a is b: print("$a has object identity with $b")
    if a is not b: print("$a has negated object identity with $b")

compare("YUP", "YUP")
compare('a', 'z')
compare("24", "123")
compare(24, 123)
compare(5.0, 5)



COBOL: "hello" = "hello"   
"helloo" <> "hello" 
"aello" < "hello"