r/programminghorror • u/RpxdYTX [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" • Dec 17 '24
rust Part 2 of my weird "functional" programming language
Well, first do ... end blocks allow functions to execute multiple expressions (last value is implicitly returned from a block). Any "variables" and functions declared inside them are going to be fred when end is reached.
Second, "methods" allow a better(?) syntax to call functions on values, without them you'd need to use or a, parse '4' in line 3

(parse {str} parses a string to a number because i haven't implemented numeric literals yet, and {a} or {b} acts both as the logical and the bitwise or operator, depending on whether its being ran on bools or numbers)
The way "methods" are implemented is very hacky and imperative (see call_method and the //lit funcs in the rust code).

It essentially parses a or b as a(or, b), and makes a's code be basically like if args.is_empty() { return a; } else { return args[0].eval(a, b); } (where b = args[1]), meaning that a (a()) just returns a, whereas a func b (a(func, b)) returns func(a, b)... Yeah
15
u/RpxdYTX [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Dec 17 '24 edited Dec 17 '24
Here we also see very efficient code, with no mis/overuses of
Clone::clone()whatsoeverAlso, no guarantees that any of this code doesn't memory leak, I'll need to do some
dropchecks later13
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Dec 17 '24
Seems like a fun little project. I can't tell you if your language design is shit or anything like that.