comparison with the procedural core of Java | My Assignment Tutor

LPL compared with JavaThe semantics of LPL can be readily understood by comparison with the procedural core ofJava (no classes). Making that comparison is the purpose of this document. This documentdoes not attempt to provide complete coverage of LPL’s syntax (consult the LPL grammardocument for that).Compare the Java program on the left with the LPL program on the right:• An LPL program starts with an initial function definition, which plays a similar role toa main method in Java. In this example the initial function is called test and it hasa return type of unit; the unit type is similar to void in Java (but see below). Incontrast with a main method in Java, which must have a single parameter of typeString[], the initial function in LPL can have multiple parameters of various types(there is no String type in LPL, however).• The rest of an LPL program is a sequence of zero or more function definitions. Allfunction definitions in LPL are like static methods in Java. An LPL function with unitreturn type corresponds to a Java method with void return type but, in contrast tovoid in Java, unit is a first-class type in LPL; for example you can declare a variablewith type unit, though there is nothing useful that can be done with such avariable.• As in Java, an LPL return statement is used to return a value from a function. Incontrast with Java, return statements in LPL functions are optional; if execution of anLPL function reaches the end of the function body without executing an explicitreturn, then it returns the default value for the function’s return type (0 for int,false for bool, null for array types).class Main {public static void main(String[] a) {int x = Integer.parseInt(a[0]);int[] b = new int[] { x, x };inc(b);System.out.println(sumTwo(b));}static void inc(int[] a) {for(int i = 0; i < a.length; ++i) {a[i] = a[i] + 1;}}static int sumTwo(int[] a) {return a[0] + a[1];}}def unit test(int x) {int[] b;b = new int[2];b[0] = x; b[1] = x;inc(b);output sumTwo(b);outchar 13; outchar 10;} def unit inc(int[] a)int i; i = 0;{while(i

QUALITY: 100% ORIGINAL PAPER – NO PLAGIARISM – CUSTOM PAPER

Leave a Reply

Your email address will not be published. Required fields are marked *