1. 73
  1. 15
    ;; Came from a different functional language, sees patterns everywhere
    (define factorial
       (0 1)
       (n (* n (factorial (sub1 n))))))

    'personally attacked'.

    1. 2

      Is this bad style in Scheme? I know a little Haskell and this definitively looks like what I’d write, looks much more clear than the other ones.

      1. 2

        Not really. FWIW neither match-lambda nor sub1 are standard, but pattern matching isn’t uncommon in the Scheme code I’ve worked on. (Well, the Guile code I’ve worked on.)

        1. 1

          Yet, there is a standard pattern matcher, in syntax-rules. Not suitable, of course for matching general data structures out of the box, but the premise for inclusion, I think, is there.

    2. 9

      ;; Feels enlightened after learning about CPS but doesn't know what to do with this information

      I remember going through this stage. (I still don’t really know what to do with this information…)

      1. 6

        ;; Really likes lists, carries around their own 300 line file of helper procedures

        I feel personally insulted.

        1. 4

          I had never heard of or thought of using colours to highlight which parens close which and now it seems so obvious in hindsight I want this yesterday.

          1. 4

            It’s been a thing (at least in Emacs) for a while: https://www.emacswiki.org/emacs/RainbowDelimiters

          2. 4

            I enjoyed this a little too much…

            1. 4
              ;; Concerned about wasted performance, really likes the word 'amortised'


              1. 2
                ;; Gone mad with power after discovering macros, likes -funroll-loops
                (define-syntax factorial
                  (lambda (stx)
                    (syntax-case stx ()
                      ((_ 0) #'1)
                      ((_ n) #`(* n (factorial
                                     #,(sub1 (syntax->datum #'n))))))))

                Is it actually improve performance in scheme? I would guess loop unrolling easy to implement. Does quasisyntax survive r7rs?

                1. 2

                  Only if the compiler has a strategy to precompute arithmetic operations at compile-time. Even then, there are much better optimisations you can do without sacrificing run-time flexibility (check out the link to math/number-theory at the bottom).
                  And no, R7RS Small only mandates syntax-rules. Implementations independently advocate for syntax-case, explicit/implicit renaming and syntactic closures. But yes, it’s pretty much trivial to unroll loops with a macro system that allows you to break hygiene.

                2. 2

                  I chuckled at some of these, very recognisable :)

                  1. 2

                    Reminds me of this old chestnut:


                    (“A Short Ballad Dedicated to the Growth of Programs” By Ashwin Ram)

                    1. 2

                      I like these scope-coloured braces. How are they achieved here?

                      1. 5

                        I don’t know how the author formatted them, but vim has rainbow parentheses, and emacs has rainbow delimiters. (The vim version also works on arbitrary delimiters.)

                        1. 2

                          It’s a quick and dirty script I put together here.