Programming With Less Than Nothing

49 points by xyproto


icefox

I appreciate the website's JS code highlighter giving up 10% of the way through the final program.

smlckz

Is there a awesome-like list of technical fiction? I remember reading a horror story about compiler bootstrapping, loosely based upon the idea of "trusting trust", the compiler affected by the virus leading to emergence of sentience or whatever.. it was quite intriguing; but forgot where I read it. Edit: rsaarelm on IRC found this story for me: https://www.teamten.com/lawrence/writings/coding-machines/ Now that I read it again, I feel a certain odd sense of empathy for the digital species described in it, slowly evolving with the help of human intellect.

Also, a collection of computing folklore in general; a good example of a lore, I suppose, is the story of Mel. Similarly, stories about hard-to-find-and-fix bugs, e.g. a bug that can only be observed depending on lunar phase or something, I can't find them now.

schuelermine

I’m getting a bit tired of this type of story—even if the model of computing that’s shown off is cool.

pwab

Aaaah, here's my dose of professional humility for the day! well done

zdsmith

This is absolute self-promotion, but:

This article adopts the perspective on combinatory logic that is the most common among programmers: it emphasizes the construction of Turing-complete systems from SK, and it adds the bird book as further reading and as a naming scheme. In other words, it advertises combinators as a basis for theoretical computation and as a recreation (both of which they are).

But I feel I'd be remiss if I didn't also plug for the concept of combinators as actual programming tools. Combinators (as alluded to in the text) let you perform eta-reduction, that is, they let you eliminate names from your code without changing its sense. And that might make your code better!

Thus: here's a point-free version of Fizzbuzz. It uses the same elements that the text does, but it chooses names that are meaningful for programmers rather than logicians or mathematicians, And it doesn't use them to reconstruct the entire syntax and standard library of a programming language, but rather just to fill in the necessary bits. Hopefully if you squint you can see how they're related.

Finally, I've grabbed comb-cond from here—you can read there for a deeper treatment of the same topic.

Below, find in Janet an imperative, non-clever version of Fizzbuzz, followed by a helper function to perform cond with combinators, and then my own combinatory Fizzbuzz.

(use ./apcl)

(defn fizzbuzz
  []
  (each n (range 1 101)
    (cond
      (= 0 (mod n 15)) (print "fizzbuzz")
      (= 0 (mod n 3)) (print "fizz")
      (= 0 (mod n 5)) (print "buzz")
      true (print n))))

(defn comb-cond
  [& pairs]
  (fn [x]
    (label result
      (each [pred f] (partition 2 pairs)
        (if (pred x)
          (return result (f x)))))))

(defn fizzbuzz
  []
  (map (comb-cond
         (comp zero? (partial (flip mod) 15)) (comp print (constant "fizzbuzz"))
         (comp zero? (partial (flip mod) 3)) (comp print (constant "fizz"))
         (comp zero? (partial (flip mod) 5)) (comp print (constant "buzz"))
         (constant true) print)
       (range 1 101)))

(fizzbuzz)