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 22:21 ID:DDRzupTb

>>36
it's pretty obvious to me that it makes 2 arrays, appends them together, converts the result to a quotation, and then calls it.
and it only has 1 shuffle word.

Name: Anonymous 2007-08-08 22:50 ID:X4nQBBK3

what does 'keep'?

Name: Anonymous 2007-08-08 23:04 ID:Heaven

>>42
http://factorcode.org/responder/browser/browse?vocab=kernel&word=keep&apropos=

keep ( x quot -- x )
...
Inputs and outputs
quot    a quotation with stack effect ( x -- )
x    an object

Word description
Call a quotation with a value on the stack, restoring the value when the quotation returns.

Name: Anonymous 2007-08-08 23:19 ID:PytvNh+C

>>41
You're telling me you find it as readable as the versions in other languages on this page? Maybe you do, and all the more power to you; I have a really hard time believing it though.

Tell you what: make the absolute most readable version in Factor that you can. I have as much experience in Factor as I do in Lisp, Haskell, ML, and so forth, so I don't know the idioms of any of them. Convince me.

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?

Name: Anonymous 2007-08-08 23:48 ID:Heaven

>>45
\ escapes the ^ so it's pushed onto the stack instead of called.
also, 1- doesn't subtract from 1, it subtracts 1 from whatever number is on the top of the stack. so it's y-1, not 1-y.

>>44
: knuth ( x y -- z ) 2dup zero? [ 3drop 1 ] [ swap 1- knuth ^ ] if ;
or
: knuth ( x y -- z ) swap <array> 1 [ swap ^ ] reduce ;
is probably the most readable.
but i really like the fact that >>32 only uses one shuffle word.

Name: Anonymous 2007-08-09 2:48 ID:6QSw4CgV

>>33
Yeah, good luck appreciating well written code in a language you dont have a clue about...

Name: Anonymous 2007-08-09 5:07 ID:Heaven

(defun knuth (x y) (if (< y 2) x (expt x (knuth x (1- y)))))

Name: Anonymous 2007-08-09 6:22 ID:6QSw4CgV

>>48
YOU DONT UNDERSTAND SAGE!

Name: Anonymous 2007-08-09 6:38 ID:Heaven

I TOOK THE KNUTH UP MY ASS!!

Name: Anonymous 2007-08-09 6:53 ID:436984Ks

oh btw, I think the haskell version can be even better

knuth x y = iterate (x^) 1 !! y

Name: Anonymous 2007-08-09 7:04 ID:HGQEZp9G

>>51
Here we have a winrar. Thread over. (Pointlessfag, shut up.)

Name: Anonymous 2007-08-09 7:59 ID:mIA1+H9g

public static double knuth(double x, int n) { return n<=0 ? 1. : Math.pow(x,knuth(x,n-1)); }

Name: Anonymous 2007-08-09 8:03 ID:6QSw4CgV

Hay GUYZ!

Name: Anonymous 2007-08-09 9:49 ID:GUFB43pG

>>52
knuth = (!!) . (flip iterate 1) . (^)

Name: Anonymous 2007-08-09 11:19 ID:9s7U1jSL

>>47
I don't have a clue about Lisp or Haskell either, yet I have no problem working out what most of the code is doing. Factor's problem is that you need to keep a stack in your head.

Also, I like the second version in >>46, even if it's still obscure to me.

Name: Anonymous 2007-08-10 0:04 ID:/jdb7tRc

>>56
it's the equivalent to foldr plus replicate. it's not that obscure, and I don't even know factor (i'm the guy who proposed the iterate version)

Name: Anonymous 2007-08-10 1:06 ID:AGvIsGMx

>>56
You totally missed the point lol

Name: Anonymous 2007-08-10 1:09 ID:/Y6r7VP+

>>58
Which is?

Name: Anonymous 2007-08-10 4:32 ID:XLlQBuuQ

>>59
keeping a stack containing less than 5 elements in your head is easier than counting 20 pairs of parentheses.
if you go deeper than that on the stack you're probably doing something wrong.

Name: Anonymous 2007-08-10 6:55 ID:1+RtKdzc

>>60
you don't have to, ahem, actually count the parentheses.

Name: Anonymous 2007-08-10 6:59 ID:Heaven

>>60

1          2 3 4       56
(defun main(x) (print x))
7           8
(main 'hello)


OH GOD

Name: Anonymous 2007-08-10 8:29 ID:AGvIsGMx

>>62

(1defun main (2x)3 (4print x)5)6
(7main 'hello)8

welcome to the BBCode revolution

Name: Anonymous 2007-08-10 8:29 ID:AGvIsGMx

>>63
fuck I failed it (3) somehow

Name: Anonymous 2007-08-10 12:45 ID:Heaven

>>64
BBCode 3.0 is not ready for the mainstream yet.

Name: Anonymous 2007-08-10 13:46 ID:AGvIsGMx

>>65
OKAY YOUVE FUQING ANGERED AN EXPERT PROGARMMER

HOW DARE YOU SUGGEST THAT BBCODE 3.0 IS NOT THE MOST PERFECT EXCELLENT SCALABLE SOLTUION FOR ALL TASKS

Name: Anonymous 2007-08-10 14:46 ID:Heaven

>>66
You seem to be a so-called ``EXPERT BBCODE PROGRAMMER''. In the wake of BBCode 3.0, I'm writing a Haskell library that enables mere mortals to write ``proper'' BBCode. What particular BBCode features do you find useful? What kind of functionality do you except from an ENTERPRISE-quality BBCode solution?

Name: Anonymous 2007-08-10 15:46 ID:AGvIsGMx

>>67
ABSTRACT BULLSHITE and turn "" into 66proper quotes99

Name: Anonymous 2007-08-10 17:01 ID:SPbFvEWz

>>67
(((ok bitch)
  (you asked for it)
  (here goes))
 (im taking out the fucking
     (bold paranthesis on you))
 (you fuqing angered an expert programmer)
 (ive been here for (expt 3 88888000) years longer than you)
 (ive read sicp twice)
 (i know every programming language in the world
    including apl)
 (if u wanna batl (lets do it))
 (ill crush you like a bean))

Name: Anonymous 2007-08-11 7:29 ID:FLZoZQXk

>>69
lmao, well reverse engineerd.. you are fastly approaching BBCode satori

Name: Anonymous 2007-08-11 14:10 ID:3UvjmHTM

I LISTEN TO INFECTED MUSHROOM WHILE I WRITE JAVA BECAUSE I AM 1337

Name: Anonymous 2007-08-11 15:57 ID:FLZoZQXk

sage for failed lisp formatting in OP, dont put the parens like that you dick

Name: Anonymous 2007-08-11 16:00 ID:Heaven

You forgot your sage.

Name: Anonymous 2010-11-15 14:34

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