(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.
I’M EXPERT PROGRAMMER
SON OF A BITCH LISP
LISP IS PIG
DO YOU WANT PARENTHESES?
DO YOU WANT PARENTHESESES?
LISP IS PIG DISGUSTING
KNUTH IS A MURDERER
FUCKING LISP)))))))))
Name:
Anonymous2007-08-07 12:45 ID:L1Wyxl+P
>>3
I’M EXPERT PROGRAMMER
SON OF A BITCH LISP
LISP IS PIG
DO YOU WANT PARENTHESES?
DO YOU WANT PARENTHESESES?
LISP IS PIG DISGUSTING MCARTHY IS A MURDERER
FUCKING LISP)))))))))
>>4
I’M EXPERT MOOT
SON OF A BITCH ANONYMOUS
ANONYMOUS IS PIG
DO YOU WANT LULZ?
DO YOU WANT CP?
ANONYMOUS IS PIG DISGUSTING
SNACKS IS A MURDERER
FUCKING ANONYMOUS
Even fagget liek me knows how to do n00b things like this with recursion in fucking every language. Just like crappy C's version which is shorter
int knuth(int a, int b)
{
if (b == 2) return a * a; else knuth(a, b - 1);
}
Name:
Anonymous2007-08-07 22:47 ID:yiVjEOLc
IS THIS A JOKE? What happens when you call (knuth x 1)? THINK ABOUT IT.
(defun knuth (x n)
(if (= n 0)
1
(expt x (knuth x (- n 1)))))
Name:
Anonymous2007-08-07 22:49 ID:yiVjEOLc
OH GOD THE STUPID IS CONTAGIOUS
(defun knuth (x n)
(if (= n 1)
x
(expt x (knuth x (- n 1)))))
Occurs check: cannot construct the infinite type: a = a -> a
Probable cause: `**' is applied to too few arguments
In the first argument of `iterate', namely `(**)'
In the first argument of `(!!)', namely `(iterate (**) x)'
>>29
Which part, in particular, do you find unreadable? It looks very clear to me.
If point-free style is too much to handle for your pathetic little mind, of course you could do knuth x n = foldr1 (**) $ replicate n x
Name:
Anonymous2007-08-08 11:23 ID:DDRzupTb
: knuth ( x y -- z ) [ swap <array> ] keep 1- \ ^ <array> append >quotation call ;
Name:
Anonymous2007-08-08 13:05 ID:mNCp9Qs0
These Factor snippets just keep convincing me that concatenative languages are full of fail. Can you obscure the intended meaning with stack shuffling any further?
Does anybody know of a concatenative language that isn't all about dup/swap/tuck/<stupid shuffleword here>? If it takes so much superfluous crap to gain any power, I'll achieve satori with a Lisp instead.
Name:
Anonymous2007-08-08 13:31 ID:E9iTUwZb
>>33
sure, 2 shuffle words is so much worse than 8 FUCKING PAIRS OF PARENTHESES.
Name:
Anonymous2007-08-08 13:39 ID:jQC43TuK
>>34
You're forgetting the $ operator there, dude. (lol.)
Name:
Anonymous2007-08-08 14:24 ID:mNCp9Qs0
>>35
Yes, because >>32 just leaps out and screams at me what its algorithm is. Oh, wait, it doesn't. If you claim it does, you're self-deluded.
I'm not partial to Lisp for other reasons, but even with all those parens it's far more readable. You don't need to do shit in reverse order and keeping a stack in your head.
And then there's the other functional languages, which are a huge improvement over Lisp readability-wise. Which leaves Factor permanently in the toy department. Forth was and is a dead end.
Name:
Anonymous2007-08-08 14:42 ID:oLee4JxW
SELECT FROM knuth LIKE x=y LEFT JOIN SELECT knuth LIKE y=y-1;
Eat that you scumbags. (Not functional code...)
Name:
Anonymous2007-08-08 15:37 ID:jfdJ4k27
>>36 I'm not partial to Lisp for other reasons, but even with all those parens it's far more readable.
Well, no kidding. Lisp is the most readable language around.
Best solution:
knuth x y = foldr (^) 1 $ replicate x y
Readable solution even retards get:
knuth x 0 = 1
knuth x y = x ^ knuth x (y-1)
LISP versions are only slightly worse
Factor SUCKS
THREAD OVER
Name:
Anonymous2007-08-08 20:56 ID:X4nQBBK3
>>24
sorry, I forgot an x, confused the ** operator with the ^ operator, and forgot !! counts from 0. I don't really program in haskell, I prefer lisp for my home stuff and I use pl/sql at work.
try
knuth x y = iterate (x^) x !! (y-1)
or if you want knuth x 0 = 1, then
knuth x y = (1 : iterate (x^) x ) !! y
iterate f x gives the infinite list, [x, f x, f (f x), ...]
since f here is (x^), we get
[x, x^x, x^(x^x), x^(x^(x^x)), ...]
we cons a 1
[1, x, x^x, x^(x^x), x^(x^(x^x)), ...]
then position 0 is knuth x 0, position 1 is knuth x 1, and so forth*.
* which incidentally, sucks big dick.
Name:
Anonymous2007-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.
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:
Anonymous2007-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:
Anonymous2007-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
>>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:
Anonymous2007-08-09 2:48 ID:6QSw4CgV
>>33
Yeah, good luck appreciating well written code in a language you dont have a clue about...
>>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:
Anonymous2007-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)
>>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:
Anonymous2007-08-10 6:55 ID:1+RtKdzc
>>60
you don't have to, ahem, actually count the parentheses.
>>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:
Anonymous2007-08-10 15:46 ID:AGvIsGMx
>>67
ABSTRACT BULLSHITE and turn "" into 66proper quotes99
Name:
Anonymous2007-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:
Anonymous2007-08-11 7:29 ID:FLZoZQXk
>>69
lmao, well reverse engineerd.. you are fastly approaching BBCode satori
Name:
Anonymous2007-08-11 14:10 ID:3UvjmHTM
I LISTEN TO INFECTED MUSHROOM WHILE I WRITE JAVA BECAUSE I AM 1337
Name:
Anonymous2007-08-11 15:57 ID:FLZoZQXk
sage for failed lisp formatting in OP, dont put the parens like that you dick