Hi.
module main
require `java.net.Socket`
require `java.io.BufferedReader`
require `java.io.InputStreamReader`
connect ->
print(read(reader))
where
socket: new Socket('
irc.qt.io', 6667)
reader: new BufferedReader(new InputStreamReader(socket.getInputStream()))
read(reader) ->
parse(reader.readLine()),
read(reader)
where
parse(line) =>
Nothing : ''
* : line
main ->
connect()
What I'm trying to do is in read(reader), read a line from the BufferedReader and, if it is Nothing, return '' and return the line otherwise.
I'm getting 2 errors here:
Firstly, the error I get when trying to recur (parse(reader.readLine()), read(reader)) is:
Exception in thread "main" java.lang.VerifyError: (class: main, method: read signature: (Ljava/lang/Object;)Ljava/lang/Object;) Inconsistent stack height 1 != 0
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getDeclaredMethod(Class.java:1952)
at loop.Executable.main(Executable.java:232)
at loop.Loop.safeEval(Loop.java:71)
at loop.Loop.run(Loop.java:41)
at loop.Loop.main(Loop.java:26)
The error I get with the pattern matching is:
Exception in thread "main" java.lang.NullPointerException
at loop.AsmCodeEmitter.emitTypePatternRule(AsmCodeEmitter.java:1544)
at loop.AsmCodeEmitter.access$1300(AsmCodeEmitter.java:68)
at loop.AsmCodeEmitter$27.emitCode(AsmCodeEmitter.java:1474)
at loop.AsmCodeEmitter.emit(AsmCodeEmitter.java:235)
at loop.AsmCodeEmitter.emitChildren(AsmCodeEmitter.java:224)
at loop.AsmCodeEmitter.access$200(AsmCodeEmitter.java:68)
at loop.AsmCodeEmitter$18.emitCode(AsmCodeEmitter.java:1121)
at loop.AsmCodeEmitter.emit(AsmCodeEmitter.java:235)
at loop.AsmCodeEmitter$18.emitCode(AsmCodeEmitter.java:1010)
at loop.AsmCodeEmitter.emit(AsmCodeEmitter.java:235)
at loop.AsmCodeEmitter.write(AsmCodeEmitter.java:166)
at loop.Executable.compile(Executable.java:279)
at loop.Loop.loopCompile(Loop.java:98)
at loop.Loop.run(Loop.java:38)
at loop.Loop.main(Loop.java:26)
This is all done through a file. Since there's no IDE plugin as of yet, I use this little script:
public class Run {
public static void main(String[] args) throws Exception {
Process process = Runtime.getRuntime().exec("java -jar lib/loop.jar src/Main.loop");
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
while ((line = input.readLine()) != null)
System.out.println(line);
line = "";
while ((line = error.readLine()) != null)
System.out.println(line);
}
}
I have no idea what I'm doing wrong. Do you guys understand?
The equivalent Java code would probably be:
public String read(BufferedReader reader) {
String line = reader.readLine();
if (line == null)
return "";
else
return line;
}
But how would I recur, since there are no loops?
Thanks,
Omer