updating the compiler/reader to handle binops more specially
This commit is contained in:
@ -105,3 +105,33 @@ core.basicAtPut "xbcdefghiklmnl" 4 k ##ERROR: exception not handled - "receiver
|
||||
|
||||
k := (core.basicAt #abcdefg 1)
|
||||
core.basicAtPut #xbcdefghiklmnl 4 k ##ERROR: exception not handled - "receiver immutable - xbcdefghiklmnl"
|
||||
|
||||
---
|
||||
|
||||
## the compiler/runtime needs to improve on this although this is an error for now.
|
||||
fun + (a b) {}
|
||||
printf "%O\n" #{+: 20} ##ERROR: no builtin hash implemented for #<BLOCK>
|
||||
|
||||
---
|
||||
|
||||
class X {
|
||||
fun + () {} ##ERROR: syntax error - only one argument expected for '+'
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
## the binop method defined for a class must have one argument
|
||||
class X {
|
||||
fun + (t) {}
|
||||
fun f1 (t1 t2) {}
|
||||
}
|
||||
|
||||
fun X:- (a b) {} ##ERROR: syntax error - only one argument expected for 'X:-'
|
||||
|
||||
---
|
||||
|
||||
class X {
|
||||
fun[#ci] +(a b c) { printf "jjj\n" } ## the one argument rule applies to binary instance methods only.
|
||||
fun +(c d) { printf "jjj\n" } ##ERROR: syntax error - only one argument expected for '+'
|
||||
}
|
||||
|
||||
|
@ -132,6 +132,7 @@ if (== i k) { printf "OK: i is %d\n" i k } \
|
||||
else { printf "ERROR: i is not equal to %d\n" k }
|
||||
|
||||
|
||||
## dictionary
|
||||
a := #{
|
||||
(if (> 10 20) true else false ): 10,
|
||||
(if (< 10 20) true else false ): 20
|
||||
|
@ -166,6 +166,7 @@ abc.? := 20 ##ERROR: syntax error - '?' prohibited as first character of identif
|
||||
|
||||
|
||||
---
|
||||
|
||||
- := 20 ##ERROR: syntax error - bad lvalue - invalid element - -
|
||||
|
||||
---
|
||||
|
19
t/fun-01.hak
19
t/fun-01.hak
@ -126,3 +126,22 @@ if (== v 30) { printf "OK - %d\n" v } else { printf "ERROR - %d, not 30\n" v };
|
||||
fun k(x) (+ x 30) ## (+ x 30) is valid function body
|
||||
v := (k 10)
|
||||
if (== v 40) { printf "OK - %d\n" v } else { printf "ERROR - %d, not 40\n" v };
|
||||
|
||||
|
||||
## ----------------------------------------
|
||||
fun plus(x y) {
|
||||
##printf "plus %d %d\n" x y
|
||||
fun minus(x y) {
|
||||
##printf "minus %d %d\n" x y
|
||||
- x y
|
||||
}
|
||||
+ x y
|
||||
}
|
||||
|
||||
fun dummy(q) {
|
||||
printf "%s\n" q
|
||||
}
|
||||
|
||||
plus 10 20 ## minus is now available after plus is executed
|
||||
v := (minus 10 1)
|
||||
if (== v 9) { printf "OK - %d\n" v } else { printf "ERROR - %d, not 9\n" v }
|
||||
|
Reference in New Issue
Block a user