Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Knuth's up-arrow notation

Name: Anonymous 2007-08-07 11:37 ID:ywrNHFyl

(defun knuth (x n)
  (if (= n 2)
      (return-from knuth (expt x x))
    (return-from knuth (expt x (knuth x (- n 1))))
    )
)


Yes, an implementation in 6 lines of Lisp. What is Knuth's up-arrow notation? Wikipedia that shit. Don't try this with anything greater than (knuth 3 3), or you will overflow. (knut 3 3) == 3^3^3. (knuth 3 4) == 3^3^3^3.

Name: Anonymous 2007-08-08 23:36 ID:X4nQBBK3

: knuth ( x y -- z ) [ swap <array> ] keep 1- \ ^ <array> append >quotation call ;
ok, so...
"(n elt) <array>" creates an array of length n, initialized to elt. so basically <array> = replicate

keep = over slip, over = xy-xyx, slip calls a quotation ignoring the top element, so, the quotation is called, but the top element is kept. or something like that. anyway after keep the stack is something like

array of length y initialized to x | y

then we do 1-, so we have 1- y. what does '\' do?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List