implementing calls and functions (ch24)
This commit is contained in:
4
samples/ch24_function.lox
Normal file
4
samples/ch24_function.lox
Normal file
@ -0,0 +1,4 @@
|
||||
fun areWeHavingItYet() {
|
||||
print "Yes we are!";
|
||||
}
|
||||
print areWeHavingItYet;
|
9
samples/ch24_function_call.lox
Normal file
9
samples/ch24_function_call.lox
Normal file
@ -0,0 +1,9 @@
|
||||
fun helloWorld(var_str, var_int) {
|
||||
var b = 1;
|
||||
print var_str + " blah";
|
||||
|
||||
return b + var_int;
|
||||
}
|
||||
|
||||
var c = helloWorld("a", 42);
|
||||
print c;
|
7
samples/ch24_invalid_arg_count.lox
Normal file
7
samples/ch24_invalid_arg_count.lox
Normal file
@ -0,0 +1,7 @@
|
||||
fun a() { b(); }
|
||||
fun b() { c(); }
|
||||
fun c() {
|
||||
c("too", "many");
|
||||
}
|
||||
|
||||
a();
|
3
samples/ch24_multiple_calls.lox
Normal file
3
samples/ch24_multiple_calls.lox
Normal file
@ -0,0 +1,3 @@
|
||||
fun a(a, b) { var c = a + b; return c; }
|
||||
print a(2, 4);
|
||||
print a(4, 6);
|
Reference in New Issue
Block a user