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

Pages: 1-4041-

Variations on a Theme

Name: Anonymous 2009-11-04 1:17

Come up with variations of your favorite toy problems.  The more obfuscated the better.

I'll start with a simple one:

def factorial(n): return reduce(lambda x,y: x*y, range(1,n
+1)) if n > 1 else 1

Name: Anonymous 2009-11-04 1:40


(PROGN
  (EVAL-WHEN (:COMPILE-TOPLEVEL) (SB-C:%COMPILER-DEFUN 'FACTORIAL 'NIL T))
  (EVAL-WHEN (:LOAD-TOPLEVEL :EXECUTE)
    (SB-IMPL::%DEFUN 'FACTORIAL
             (SB-INT:NAMED-LAMBDA FACTORIAL (N)
               (BLOCK FACTORIAL
             (REDUCE #'*
                 (BLOCK NIL
                   (LET ((I 1)
                     (#:LOOP-LIMIT-945 N))
                     (DECLARE
                      (TYPE (AND NUMBER REAL)
                        #:LOOP-LIMIT-945)
                      (TYPE (AND REAL NUMBER)
                        I))
                     (LET* ((#:LOOP-LIST-HEAD-946
                         (LIST NIL))
                        (#:LOOP-LIST-TAIL-947
                         #:LOOP-LIST-HEAD-946))
                       (TAGBODY
                    SB-LOOP::NEXT-LOOP
                      (IF
                       (> I
                          #:LOOP-LIMIT-945)
                       (PROGN
                         (GO
                          SB-LOOP::END-LOOP))
                       NIL)
                      (RPLACD
                       #:LOOP-LIST-TAIL-947
                       (SETQ #:LOOP-LIST-TAIL-947
                         (LIST I)))
                      (SETQ I (1+ I))
                      (GO
                       SB-LOOP::NEXT-LOOP)
                    SB-LOOP::END-LOOP
                      (RETURN-FROM NIL
                        (CDR
                         #:LOOP-LIST-HEAD-946))))))
                 :INITIAL-VALUE 1)))
             NIL 'NIL (SB-C:SOURCE-LOCATION))))


Just kidding, here's the original:


(defun factorial (n)
  (reduce #'* (loop for i from 1 to n collect i) :initial-value 1))

Name: Anonymous 2009-11-04 2:05

>>2
Writing Lisp in all caps is disrespectful and irreverent. Until you can take Lisp more seriously, I'm adding your posts to my /prog/ filter.

Name: Anonymous 2009-11-04 2:16

>>3
It's macroexpanded code. I could have easily changed the readtable to downcase the printed symbols, but I had no reason to. If you would have read it more closely, you would know that that code isn't even valid CL code, it's implementation specific code for SBCL. It's the result of macroexpanding that factorial function provided later in the post.

Name: Anonymous 2009-11-04 2:29

>>4
If you would have read it more closely, you would know that                    YHBT                .

Name: Anonymous 2009-11-04 2:36

>>5
If you would read more closely, you would know that...

Name: Anonymous 2009-11-04 2:37

Spoiler thread? The protagonist was dead all along

Name: Anonymous 2009-11-04 6:45

>>7
HIRO?

Name: Anonymous 2009-11-04 8:43

████████████████████████

Name: Anonymous 2009-11-04 15:02

>>9
zOMG spoilers!!1!

Name: Anonymous 2009-11-04 16:21

>>9
I you.

Name: Anonymous 2009-11-04 18:20

Not long ago I've written this
def lenY(sequence):
    return (lambda le : (lambda cc: le(lambda x: cc(cc)(x)))(lambda cc: le(lambda x: cc(cc)(x))))(
            lambda cont: lambda (s, acc): acc if not s else cont((s[1:], acc + 1)))(
            (sequence, 0))

And then decided to abandon programming forever, for I will never be able to surpass this creation of mine.

Name: 12 2009-11-04 18:24

By the way, notice the curious lack of closing braces. That's FIOC magic for you. It's all more magical since no actual FIOC were performed.

Name: Anonymous 2009-11-04 18:32

>>12
lol CPS

Name: Anonymous 2009-11-04 18:36

>>14
Please refrain from using the words you don't understand.

Name: Anonymous 2009-11-04 18:37

>>15
I perfectly understand what continuation passing style is

Name: Haxus the Destructive 2009-11-04 18:39

... because that's unscientific and ultimately destructive

Name: Anonymous 2009-11-04 18:40

>>16
Why then you labeled the code that is not with that label?

Name: Anonymous 2009-11-04 18:43

>>18
because I'm an idiot who posted before I actually verified the codeby a rewrite

Name: Anonymous 2009-11-04 18:43

>>17
lern2Haxus

Name: Haxus the Fucking Oneself 2009-11-04 18:57


Haxus the Fucking Oneself>>20

Name: Anonymous 2009-11-04 19:20

>>12
All I see is )))(((((()()((()))))(((((())()
Go away with your Sussman shit.

Name: Anonymous 2009-11-05 9:39

>>22
Leave /prog/, now.

Name: Anonymous 2009-11-06 15:57

>>23
YABMT

Name: Anonymous 2009-11-06 16:26

I see I have much to learn in the art of obfuscation.

int trew() {
    return !false;
}

Name: Anonymous 2009-11-06 17:08

I totally have just switched back to opera because firefox updated and totally wanked off all over my settings

Name: Anonymous 2009-11-06 20:24

>>1
(reduce #'* [0:])

Name: Anonymous 2009-11-06 20:44

>>27
That's not a reader macro I've ever heard of...

Name: Anonymous 2009-11-06 21:34

>>28

Maybe it's clojure and its shitty "lazy-evaluated" sequences?

Name: Anonymous 2009-11-06 23:39

>>29
Haha. Lazy evaluation... What a joke.

Name: Anonymous 2009-11-07 0:53

>lazy evaluation
too long; didn't eval

Name: Anonymous 2009-11-07 4:08

>>28-31
nobody fucking noticed that reduce would always be 0. fix:
(reduce #'* [1:x])

OR if you use a better range reader macro
(reduce #'* [1 x])

Name: Anonymous 2009-11-07 6:55

>>32
REDUCE MY ANUS

Name: Anonymous 2009-11-07 8:36

>>28-29
It's probably Clojure, but you can implement a reader macro like that with ease in CL, just it seems like a waste of valuable macro characters. If I were to use [] for anything, it would probably be a shorthand for#'(lambda (_) ...), but I already have an Emacs key chord for inserting that...

Name: Anonymous 2009-11-07 9:06

Clojure is a lisp-1, so there's no need to star-quote functions. It looks more like the python slice operator. How it found its way into lisp I don't know.

Name: Anonymous 2009-11-07 9:17

>>34
Abusing punctuation like all the overhyped hipster lisps the cool kids are making these days
Good luck with that.

Name: Anonymous 2009-11-07 10:37

>>35
s/star-quote/hash-quote/

Name: Anonymous 2009-11-07 10:41

>>36
What? I already said I don't need to use [] for a lambda shorthand, since I have my Emacs insert #'(lambda (x) ) automatically, thus I have no need for such a macro character.

Name: Anonymous 2011-02-03 3:54

Name: Anonymous 2011-02-04 12:13

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