PDA

View Full Version : Relation of PascalScript to Java?



Wu-Tang Clan
03-20-2014, 09:29 PM
So if I'm grasping any of this even remotely, what are the similarities between Java and PascalScript (what Simba uses)?

So { and } and like begin and end?
Methods are like procedures?

What else about pascal could help me with learning Java? I'm reading the Dummies book and just have a little trouble sometimes. A concrete example between the 2 languages would be sweet.

~Wu

rj
03-20-2014, 09:37 PM
begin is like { and end is like } ofc
records are similar to objects (but they are totally different things)
public void blah blah blah() {} is like a procedure (returns nothing)
public int blahblah() {} is like a function
'return' is like exit
(return true is like result := true and exit combined, or exit(true) in lape)


Other than that.. not many like features that 'stand out', Java is OOP you won't find many similarities


2 solid examples (used lape but w-e)


type
Box = record
X1, Y1, X2, Y2:integer;
end;


function Box.new(XX1, YY1, XX2, YY2:integer):Box;
begin
result.X1 := XX1;
result.Y1 := YY1;
result.X2 := XX2;
result.Y2 := YY2;
end;

function Box.width:integer;
begin
result := (self.X2 - self.X1);
end;

function Box.height:integer;
begin
result := (self.Y2 - self.Y1);
end;

var
someBox:Box;

begin
someBox := someBox.new(5, 5, 10, 10);
writeln(somebox.width());
writeln(somebox.height());
end.


Java:

main.java


package main;

import main.Box;

public class Main {

public static void main(String[] args) {
Box someBox = new Box(5, 5, 10, 10);
System.out.println(someBox.width());
System.out.println(someBox.height());
}

}

Box.java:

package main;

public class Box {

public int x1;
public int y1;
public int x2;
public int y2;

public Box(int x1, int y1, int x2, int y2) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}

public int width() {
return (this.x2 - this.x1);
}

public int height() {
return (this.y2 - this.y1);
}

}

Brandon
03-21-2014, 02:45 AM
Don't forget function pointers:


package lambdas;

import java.util.*;
import java.util.function.*;

/**
*
* @author Brandon
*/
public class Lambdas {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Thread t = new Thread(() -> {
System.out.println("Thread Proc");
});

t.start();
sleep(100);

Thread t2 = new Thread(() -> System.out.println("Thread Proc 2"));
t2.start();
sleep(100);

Thread t3 = new Thread(Lambdas::somefunc);
t3.start();
sleep(100);

Thread t4 = new Thread((new Lambdas())::somefunc2);
t4.start();
sleep(100);

List<Integer> list = Arrays.asList(10, 3, 9, 6, 4, 1, 7, 8, 5, 2);
sort(list, (Integer a, Integer b) -> a < b);
list.forEach(System.out::println);

System.out.println();
System.out.println();

list = Arrays.asList(10, 3, 9, 6, 4, 1, 7, 8, 5, 2);
list.sort((a, b) -> a < b ? a.equals(b) ? 0 : -1 : 1);
list.forEach(System.out::println);
}

static void somefunc() {
System.out.println("Some func");
}

void somefunc2() {
System.out.println("Some func 2");
}

static <T> void sort(List<T> list, BiFunction<T, T, Boolean> func) {
for (int i = 0; i < list.size() - 1; ++i) {
for (int j = 0; j < list.size() - i - 1; ++j) {
T a = list.get(j);
T b = list.get(j + 1);

if (func.apply(b, a)) {
T temp = a;
list.set(j, b);
list.set(j + 1, temp);
}
}
}
}

static void sleep(long millis) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}



In PS, the equivalent of any of the above would be:


procedure somefunc();
begin
writeln('Some func');
end;

procedure somefunc2();
begin
writeln('Some func 2');
end;

procedure sort(var list: array of Integer; func: Function(A, B: Integer): Boolean);
var
I, J, L: Integer;
a, b, temp: Integer;
begin
L := Length(list);

for I := 0 To L - 1 do
begin
for J := 0 to L - I - 2 do
begin
a := list[j];
b := list[j + 1];

if (func(b, a)) then
begin
temp := a;
list[j] := b;
list[j + 1] := temp;
end;
end;
end;
end;

procedure SleepEx(millis: LongInt);
begin
try
sleep(millis);
except
end;
end;

function compare(a, b: Integer): boolean;
begin
Result := a < b;
end;


var
list: array of Integer;
begin
list := [10, 3, 9, 6, 4, 1, 7, 8, 5, 2];
Sort(list, @compare);

writeln(list);
end.

weequ
03-21-2014, 01:41 PM
Most difficult is probably to understand how to do object oriented programming.

Object is a bit like record in pascal but objects can also contain methods. A method has access to all the variables and methods withing the same object unlike in pascalscript. For example you could have object Box that has variables width and height and a method called getArea() that returns width*height. In pascalscript you should pass width and height as parameters to the function even if the function was part of a record that contains width and height.

Sk1nyNerd
03-21-2014, 05:52 PM
its kind of a long vid and ive made myself about half way through it going back when im bored, pretty basic functions of java such as declaring variables, and for loops. thats all ive gotten to so far in it, im sure theres more. its a great tut though and u might like it

http://www.youtube.com/watch?v=3u1fu6f8Hto

the bank
10-09-2014, 06:42 PM
What you need to do is not compare the two. Like you, I started out scripting in pascal (actually closer to Delphi by the way) wayyy back with SCAR1.3 I believe it was. Later I went on to create java based bots and write tutorials on the such in many of the java-based communities back then.

Java is a whole different ball game. First read up on OOP (Object Oriented Programming). Java is forced OOP, whereas Pascal doesn't even support it (shh, yes I know Delphi does but its crap lets me honest).

Your best friend and resource:
http://docs.oracle.com/javase/tutorial/

Hoodz
10-09-2014, 06:45 PM
What you need to do is not compare the two. Like you, I started out scripting in pascal (actually closer to Delphi by the way) wayyy back with SCAR1.3 I believe it was. Later I went on to create java based bots and write tutorials on the such in many of the java-based communities back then.

Java is a whole different ball game. First read up on OOP (Object Oriented Programming). Java is forced OOP, whereas Pascal doesn't even support it (shh, yes I know Delphi does but its crap lets me honest).

Your best friend and resource:
http://docs.oracle.com/javase/tutorial/

look at the post date

the bank
10-09-2014, 06:46 PM
look at the post date

Shit my bad man. Not really grave-digging if its on the front page though is it? Not my fault this part of the forum is dead. I love Java :(