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

Pages: 1-4041-8081-120121-160161-200201-

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-07 12:26 ID:L1Wyxl+P

>>1
   )
>)

gtfo noob

Name: Anonymous 2007-08-07 12:42 ID:Heaven

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: Anonymous 2007-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)))))))))

Name: Anonymous 2007-08-07 13:07 ID:Heaven

>>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

Name: Anonymous 2007-08-07 14:05 ID:Heaven

Superior Lisp code:

((()())()()))()(()(((()))())((())(
 (()()()())
 (((())()
   (())
))

Name: Anonymous 2007-08-07 16:21 ID:Heaven


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


formatting fix'd

Name: WHAT WILL THIS CODE PRINT? 2007-08-07 16:22 ID:lt9gqYux


(define (foo a b)
  (let ((ex (print "hi")))
    (if a
        ex
        b)))
  
(foo #t (print "hrm"))

Name: Anonymous 2007-08-07 16:26 ID:L1Wyxl+P


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

idiotic redundancy reomved


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

fixed

Name: Anonymous 2007-08-07 17:29 ID:t01cDPRJ

>>1
You fucking suck.

knuth = (foldr1 (**) . ) . flip replicate

Name: Anonymous 2007-08-07 17:30 ID:8BUe1CYg

Really, can't lisp do better than that?

Naive Haskell:
knuth x 0 = 1
knuth x y = x ^ knuth x (y-1)

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

>>11
too late!

Name: Anonymous 2007-08-07 22:19 ID:eHiNpn4q

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: Anonymous 2007-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: Anonymous 2007-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)))))

Name: Anonymous 2007-08-07 22:50 ID:hfbhAME2

>>13
knuth(1, 1);

Name: Anonymous 2007-08-07 23:05 ID:yiVjEOLc

sigh...

(defun (knuth (x n)
  (if (= n -1)
    0
    (expt x (knuth x (- n 1)))))

so
(knuth 2 0) = 1
(knuth 2 1) = 2
etc...

Name: Anonymous 2007-08-07 23:11 ID:yiVjEOLc

Or you could just do in the easy way (Lua):

function knuth(x,n)
  local t = 0
  for (v=0,n) do t = x ^ t end
  return t
end

Name: Anonymous 2007-08-07 23:16 ID:UnRA5uA9

>>11
you called?
(defun (knuth x y)
  (if0 y 1 (expt (knuth x (-1 y)))))

Name: Anonymous 2007-08-07 23:18 ID:yiVjEOLc

THIS IS MY FINAL FORM

function knuth(x,n)
  math.exp(math.log(x) ^ n)
end

KEEPING IT REAL

Name: Anonymous 2007-08-07 23:27 ID:UnRA5uA9

or just

knuth x y = foldr1 (**) (replicate y x)
instead of the gayer, longer, less readable pointless version
knuth = (foldr1 (**) . ) . flip replicate

or even better
knuth x y = (iterate (**) x) !! y

Name: Anonymous 2007-08-08 0:10 ID:Heaven

>>20
Actually that doesn't work.  It would be cool if you could define it for fractions and negative numbers in a way that made sense though.

Name: Anonymous 2007-08-08 1:40 ID:REXV4D0K

HASKELL WINS

knuth x y = (iterate (**) x) !! y

Name: Anonymous 2007-08-08 4:33 ID:GDribYI2

>>23
You don't.

    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)'

Name: Anonymous 2007-08-08 4:42 ID:Heaven

knuth _ 0 = 1
knuth x y = iterate (x^) x !! (y-1)

Name: Anonymous 2007-08-08 5:47 ID:REXV4D0K

>>24
HASKELL FAILS

LOL LOL HASKELL SUCKS LOL

Name: Anonymous 2007-08-08 8:24 ID:DDRzupTb

lisp fag version:
: knuth ( x y -- z ) 2dup zero? [ * ^ ] [ swap 1- knuth ^ ] if ;

haskell fag version:
: knuth ( x y -- z ) 2dup zero? [ * ^ ] [ swap 1- [ over swap ^ ] times nip ] if ;

better version:
: knuth ( x y -- z ) swap <array> 1 [ swap ^ ] reduce ;

Name: Anonymous 2007-08-08 8:24 ID:gBsPUUYP

Name: Anonymous 2007-08-08 8:30 ID:Heaven

>>28
Yes. An unreadable pointless function. Now what?

Name: Anonymous 2007-08-08 8:43 ID:Heaven

>>27
: knuth ( x y -- z ) 2dup zero? [ * ^ ] [ swap 1- knuth ^ ] if ;
is like
knuth _ 0 = 1
knuth x y = x ^ knuth x (y-1)


: knuth ( x y -- z ) 2dup zero? [ * ^ ] [ swap 1- [ over swap ^ ] times nip ] if ;
is like
knuth _ 0 = 1
knuth x y = iterate (x^) x !! (y-1)


: knuth ( x y -- z ) swap <array> 1 [ swap ^ ] reduce ;
is like
knuth = (foldr1 (**) . ) . flip replicate
or
knuth x y = foldr1 (**) (replicate y x)

>>29
in a practical language the pointless version is more readable than the other versions.

Name: Anonymous 2007-08-08 9:25 ID:Heaven

>>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: Anonymous 2007-08-08 11:23 ID:DDRzupTb

: knuth ( x y -- z ) [ swap <array> ] keep 1- \ ^ <array> append >quotation call ;

Name: Anonymous 2007-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: Anonymous 2007-08-08 13:31 ID:E9iTUwZb

>>33
sure, 2 shuffle words is so much worse than 8 FUCKING PAIRS OF PARENTHESES.

Name: Anonymous 2007-08-08 13:39 ID:jQC43TuK

>>34
You're forgetting the $ operator there, dude. (lol.)

Name: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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.

Name: Anonymous 2007-08-08 19:18 ID:Heaven

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: Anonymous 2007-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: 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

Name: Anonymous 2013-07-06 2:47

Sage for lisp in OP, don't use that shit you dick.

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