2021-12-16 04:00:46 Turns out for day 2 you don't even need a parser, the input is already valid Forth code :) https://github.com/neuro-sys/advent-of-code-2021/blob/main/2-2.fs.md 2021-12-16 05:02:03 forth link on hackernews: https://news.ycombinator.com/item?id=29574415 2021-12-16 10:51:00 What is it about the filesize of a forth interpreter that makes it so much smaller than the filesize of a scheme interpreter? 2021-12-16 11:02:31 Off the top of my head, no GC, no runtime-typechecking, usually no Unicode library, much simpler parser, threaded code instead of CPS 2021-12-16 11:03:55 I bet you could get an ASCII-only, no-GC-just-leak, runtime-unsafe, call/cc-less Scheme to be in the same ballpark 2021-12-16 11:07:03 oh, and the Scheme macro system is definitely way more code to implement than immediate words are in Forth 2021-12-16 11:08:02 so add "with gensym+defmacro instead of define-syntax" 2021-12-16 11:08:27 er, syntax-rules* 2021-12-16 11:10:20 scheme is way way more high level yeah 2021-12-16 11:10:51 numerical tower, typing, “hygienic” macro, non-hygienic one in most schemes, continuations… 2021-12-16 11:12:49 This is my forth right now: https://github.com/crystal-calx/calculator/blob/main/calculator.c 2021-12-16 11:13:48 quite nice 2021-12-16 11:14:05 You're the first forth programmer who ever complimented my forth 2021-12-16 11:19:49 lisbeths, so command line calculator? 2021-12-16 11:20:53 Its based on gnu dc which is an rpn language similar to forth. I named it calculator so I wouldn't have to worry about trademark. 2021-12-16 11:21:15 neat 2021-12-16 11:21:25 any plans to make it decimal like dc? 2021-12-16 11:21:25 It's very highly golfed code and I have gone to painstaking lengths to make it as branchless as I can muster. 2021-12-16 11:23:17 Here is the problem. If I make a case statement for every single number then it is faster than if I go: default: if( token >= '0' || token <= '9' ) 2021-12-16 11:23:26 I am trying to make it as branchless as can be 2021-12-16 11:24:54 how do you know it's faster? 2021-12-16 11:25:17 also how fast are you typing at the command line that it makes a difference? or directing a file into it as input 2021-12-16 11:25:37 It is meant to be both a shell and a scripting language 2021-12-16 11:26:01 so the computer may very well be inputing hte commands from a large file, not the user inputting commands at the prompt 2021-12-16 11:27:17 I reason it's faster because in a switch statement there is one conditional jump to code execution, whereas if I have a default statement that contains an if statement thats two conditional jumps 2021-12-16 11:28:11 that kind of stuff is hard to reason about without looking at the assembly generated and even then it's not always straightforward on x86 2021-12-16 11:28:45 unfortunately I don't know assembly or how to micromanage speed testing very well 2021-12-16 11:29:17 I have been told that just by changing the filename of the c file you want to compile that can affect the order of the linker which can affect the speed 2021-12-16 11:29:44 There was a guy who was compiling a c file and when he compiled it as his student it was slower and when he compiled it as himself it was faster because his student had a longer username in unix. 2021-12-16 11:30:19 ya its not easy. one idea is to go for readability (ie the if statement over the case statement) if youre not sure which is faster or if speeding up that part makes a difference in the end 2021-12-16 11:30:46 lol. thats rough 2021-12-16 12:17:30 why are you trying to avoid branches? 2021-12-16 12:23:16 incidentally, your code doesn't compile for me: http://forth.works/share/52e65c378ad831dab1784ce56aa19d21 (tested on openbsd, using OpenBSD clang version 8.0.1 (tags/RELEASE_801/final) (based on LLVM 8.0.1)) 2021-12-16 12:46:57 lisbeths: I bet that if you strategically lay out the order of branches based on common code patterns, you can beat the indirect jump 2021-12-16 13:46:14 crc the code is pseudocode 2021-12-16 13:46:29 I have not finished designing it and so it is not worth compiling it when I would have to change it again anyway 2021-12-16 13:46:42 admittedly I am not a very skilled programmer