IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Because I can :-P
Here's some code to calculate factorial in JavaScript. It is..inefficient. But in some sense it is very simple, since I've just reduced it down to function calls and the Peano Axioms.

Please note how helpfully I've indented and the wonderful choices of variable names...
\n  function (builder) {\n    return function (s) {\n      return function (p) {\n        return function (n) {\n          return builder(builder)(s)(p)(n);\n        }\n      }\n    }\n  }(\n    function (recurse) {\n      return function (s) {\n        return function (p) {\n          return function (n) {\n            if (0 == n)\n              return 1;\n            else\n              return function (builder) {\n                return function (n) {\n                  return function (m) {\n                    return builder(builder)(n)(m);\n                  }\n                }\n              }(\n                function (recurse) {\n                  return function (n) {\n                    return function (m) {\n                      if (0 == n)\n                        return 0;\n                      else\n                        return function (builder) {\n                          return function (n) {\n                            return function (m) {\n                              return builder(builder)(n)(m);\n                            }\n                          }\n                        }(\n                          function (recurse) {\n                            return function (n) {\n                              return function (m) {\n                                if (0 == n)\n                                  return m;\n                                else\n                                  return s(recurse(recurse)(p(n))(m));\n                              }\n                            }\n                          }\n                        )(\n                          m\n                        )(\n                          recurse(recurse)(p(n))(m)\n                        );\n                    }\n                  }\n                }\n              )(\n                n\n              )(\n                recurse(recurse)(s)(p)(p(n))\n              );\n          }\n        }\n      }\n    }\n  )(\n    function (n) { return n + 1 }\n  )(\n    function (n) { return n - 1 }\n  )(\n    5  // This parameter controls which factorial we compute\n  );\n

(Unfortunately I seem to hit too much recursion when computing 8!, I wonder why??)

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New ...
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Make it stop, it hurts!
-YendorMike

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety."
- Benjamin Franklin, 1759 Historical Review of Pennsylvania
New Ick!



"Whenever you find you are on the side of the majority, it is time to pause and reflect"   --Mark Twain

"The significant problems we face cannot be solved at the same level of thinking we were at when we created them."   --Albert Einstein

"This is still a dangerous world. It's a world of madmen and uncertainty and potential mental losses."   --George W. Bush
Expand Edited by tuberculosis Aug. 21, 2007, 05:46:25 AM EDT
New It could be worse...
Does anyone want to volunteer to do the inner class version one in Java?

(Note that this cannot be written in Perl or Ruby, for different reasons. Perl because you don't have lexical binding of function arguments and Ruby because it doesn't believe that you can legitimately have that many braces open.)

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New It could be raining?



"Whenever you find you are on the side of the majority, it is time to pause and reflect"   --Mark Twain

"The significant problems we face cannot be solved at the same level of thinking we were at when we created them."   --Albert Einstein

"This is still a dangerous world. It's a world of madmen and uncertainty and potential mental losses."   --George W. Bush
Expand Edited by tuberculosis Aug. 21, 2007, 05:46:33 AM EDT
New That's always possible in Seattle. :-P
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New Omniscient LRPD: His skill is being wasted.
New The tricks that he does are ever so clever.
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New Nihil curo de ista tua stulta superstitione.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New It's a trick. Get an axe.
--
[link|mailto:greg@gregfolkert.net|greg],
[link|http://www.iwethey.org/ed_curry|REMEMBER ED CURRY!] @ iwethey

[link|http://it.slashdot.org/comments.pl?sid=134485&cid=11233230|"Microsoft Security" is an even better oxymoron than "Military Intelligence"]
No matter how much Microsoft supporters whine about how Linux and other operating systems have just as many bugs as their operating systems do, the bottom line is that the serious, gut-wrenching problems happen on Windows, not on Linux, not on Mac OS. -- [link|http://www.eweek.com/article2/0,1759,1622086,00.asp|source]
New It's like watching someone try to explain quantum physics...
to a goat.

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New You should send this ...
... to Mozilla's JavaScript engine programmers. I'm sure they'd love to see what you're torturing the language with.

Wade.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

New Hofstadter!
Remember in one of his books (or maybe Metamagical Temas? article in Sci. American) when he demonstrated the score for some Chopin etudes? And went on to relate the eye's perception of the score, not unlike bevies of nascnt {{{{s?
I have come to believe that pointillism without dots is a quick road to disaster, while dots without pointillism is pointless.
-- T. Pratchett on acid
New Because that didn't have enough parentheses
Here it is in Lisp. Pick your dialect of Lisp, it should work in virtually all of them...
\n  (((((lambda ( builder )\n    (lambda ( s )\n      (lambda ( p )\n        (lambda ( n )\n          ((((builder builder) s) p) n))))) (lambda ( recurse )\n    (lambda ( s )\n      (lambda ( p )\n        (lambda ( n )\n          (if (= 0 n)\n            1\n            ((((lambda ( builder )\n              (lambda ( n )\n                (lambda ( m )\n                  (((builder builder) n) m)))) (lambda ( recurse )\n              (lambda ( n )\n                (lambda ( m )\n                  (if (= 0 n)\n                    0\n                    ((((lambda ( builder )\n                      (lambda ( n )\n                        (lambda ( m )\n                          (((builder builder) n) m)))) (lambda ( recurse )\n                      (lambda ( n )\n                        (lambda ( m )\n                          (if (= 0 n)\n                            m\n                            (s (((recurse recurse) (p n)) m))))))) m)\n\t\t\t     (((recurse recurse) (p n)) m))))))) n)\n\t\t\t      ((((recurse recurse) s) p) (p n)))))))))\n\t\t\t       (lambda ( n )\n    (+ n 1))) (lambda ( n )\n    (- n 1))) 5)\n

This is, of course, a mechanical transformation of the JavaScript code. I may not have picked quite the standard Lisp indentation rules, but I don't think that any indentation will make this look nice...

Cheers,
Ben

Edit: Remove what I had mistakenly thought would be comments, and actually were syntax errors. Incidentally mit-scheme does better than JavaScript, it computes 8! (but barfs on 9!).
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
Expand Edited by ben_tilly March 4, 2005, 01:51:12 PM EST
New Re: Because that didn't have enough parentheses
Builder builder builder builder builder builder builder builder builder builder builder builder!
LAMBDA LAMBDA
A-builder builder builder builder builder builder builder builder builder builder builder builder!
LAMBDA LAMBDA
A-builder builder builder builder builder builder builder builder builder builder builder builder!
LAMBDA LAMBDA
A-builder builder builder builder builder builder builder builder builder builder builder builder!

RECURSE, RECURSE, ohhhhhh let's recurrrrrrrse! No, let's

Builder builder builder builder builder builder builder builder builder builder builder builder!
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
Expand Edited by admin March 3, 2005, 09:52:44 PM EST
New Glad to see that I had the desired effect ;-)
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New You ALWAYS have the desired effect.
Tilly!

It's a refreshing beverage! A floor wax! A handy-dandy portable microwave!

Tilly!

For when you absolutely positively have to have the desired effect.


Peter
[link|http://www.ubuntulinux.org|Ubuntu Linux]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
New Till-AAAYYYY!!
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New Sounds like a Little League (baseball) game...
jb4
shrub\ufffdbish (Am., from shrub + rubbish, after the derisive name for America's 43 president; 2003) n. 1. a form of nonsensical political doubletalk wherein the speaker attempts to defend the indefensible by lying, obfuscation, or otherwise misstating the facts; GIBBERISH. 2. any of a collection of utterances from America's putative 43rd president. cf. BULLSHIT

New This reminds me of the Shapes examples.
The ones that Jim was collecting way back on the OO board we had. I believe our own Scott submitted one done in shell script?

Wade.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

New Nope.
awk, sed, LPC, DOS batch, postscript, and FoxPro, though. :-)
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Ah - I was thinking of DOS batch.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

New You did DOS batch, too? Dang, *I* was gonna do that... :-(
New I pasted that into vim
I've got parenthesis matching on. Vim gave me the finger.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New Heh. (BTW works fine in my vim)
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New Uhh ... that whooshing sound you hear ...
Look up. It's the joke sailing by. Unless your vim does make a habit of rude hand gestures. I don't have that version.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New I wasn't sure if it might have actually crashed
After all Ruby did when presented with the Ruby equivalent...

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New that's OK
I routinely give vim the finger whenever I'm forced to use it...
jb4
shrub\ufffdbish (Am., from shrub + rubbish, after the derisive name for America's 43 president; 2003) n. 1. a form of nonsensical political doubletalk wherein the speaker attempts to defend the indefensible by lying, obfuscation, or otherwise misstating the facts; GIBBERISH. 2. any of a collection of utterances from America's putative 43rd president. cf. BULLSHIT

New Job security squared!
________________
oop.ismad.com
     Because I can :-P - (ben_tilly) - (29)
         ... -NT - (admin)
         Make it stop, it hurts! -NT - (Yendor)
         Ick! -NT - (tuberculosis) - (3)
             It could be worse... - (ben_tilly) - (2)
                 It could be raining? -NT - (tuberculosis) - (1)
                     That's always possible in Seattle. :-P -NT - (ben_tilly)
         Omniscient LRPD: His skill is being wasted. -NT - (broomberg) - (4)
             The tricks that he does are ever so clever. -NT - (ben_tilly) - (3)
                 Nihil curo de ista tua stulta superstitione. -NT - (admin) - (2)
                     It's a trick. Get an axe. -NT - (folkert)
                     It's like watching someone try to explain quantum physics... - (ben_tilly)
         You should send this ... - (static)
         Hofstadter! - (Ashton)
         Because that didn't have enough parentheses - (ben_tilly) - (14)
             Re: Because that didn't have enough parentheses - (admin) - (4)
                 Glad to see that I had the desired effect ;-) -NT - (ben_tilly) - (2)
                     You ALWAYS have the desired effect. - (pwhysall) - (1)
                         Till-AAAYYYY!! -NT - (drewk)
                 Sounds like a Little League (baseball) game... -NT - (jb4)
             This reminds me of the Shapes examples. - (static) - (3)
                 Nope. - (admin) - (2)
                     Ah - I was thinking of DOS batch. -NT - (static)
                     You did DOS batch, too? Dang, *I* was gonna do that... :-( -NT - (CRConrad)
             I pasted that into vim - (drewk) - (4)
                 Heh. (BTW works fine in my vim) -NT - (ben_tilly) - (2)
                     Uhh ... that whooshing sound you hear ... - (drewk) - (1)
                         I wasn't sure if it might have actually crashed - (ben_tilly)
                 that's OK - (jb4)
         Job security squared! -NT - (tablizer)

Plan B, we'll retreat to the rave-cave and hope our tribal beats and epiliptic movements will cause the machines to commit suicide due to sheer irritation.
135 ms