Hacker News new | ask | show | jobs
by Syzygies 56 days ago
Yes, Chez improved a bit, at the expensive of readability.
1 comments

Yeah :/ For a larger program you can pay the readability toll once, via a syntactic form that expands the general vector/arithmetic operations to the fixnum versions, e.g. used something like

  (define (heap-permute! perm j callback)
    (with-context 'fixnum ;; same trick works with 'flonum for 64-bit floats
      (let ([n (length perm)]) ;; actually fxvector-length
       (let generate ([k (- n 1)]) ;; actually fx-
         (if (< k j) ;; fx<
           (callback perm)
           (begin
              (generate (- k 1)) ;; fx-
              (do ([i j (+ i 1)]) ;; fx+
                ((>= i k)) ;; fx>=
                (if (even? (- j k)) ;; fxeven?, fx-
                (swap perm j k)
                (swap perm i k))
                (generate (- k 1)))))))) ;; fx-
Sorry if I borked the indentation. I have been working on stuff like this, and more general macros around dependency injection and inversion of control (e.g. you could write this macro to take the type as a parameter and generate code optimized for 'bigint or 'rational). Maybe check back after the summer :)

And BTW I misspoke earlier, of course Chez is AOT rather than JIT. From one approach it's sort of a hybrid: really fast on-the-fly AOT kinda looks like JIT, tongue-in-cheek you could say "NoT compilation" (nick-of-time). But proper JIT of course has huge advantages. If you reeaaaallly wanted to sabotage readability, Chez makes it easy to invoke the compiler at runtime, so along with the C FFI I think you could hack together some sort of JIT. But wow, what a mess that would be! You'd better be getting a PhD thesis out of it :) And if the performance is that critical you'd be much better off with F#.