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

Pages: 1-

Scheme doesn't scale

Name: Anonymous 2011-01-23 9:31

How can a mere human comprehend a code snippet like this? Scheme might look neat and clever in small chunks, but it's just unsuitable for something bigger, something real. When it grows it starts to mutate in a horrible and unpredictable way that strongly obstructs readability and turns code into a challenge which questions the very ability of the reader to stay sane.

 Code is taken from somewhere in the guts of Racket.
 

 (define (make-eventspace* th)
    (let ([done-sema (make-semaphore 1)]
          [done-set? #t]
          [frames (make-hasheq)])
      (let ([e
             (make-eventspace th
                              (let ([count 0])
                                (let ([lo (mcons #f #f)]
                                      [refresh (mcons #f #f)]
                                      [med (mcons #f #f)]
                                      [hi (mcons #f #f)]
                                      [timer (box '())]
                                      [timer-counter 0]
                                      [newly-posted-sema (make-semaphore)])
                                  (let* ([check-done
                                          (lambda ()
                                            (if (or (positive? count)
                                                    (positive? (hash-count frames))
                                                    (not (null? (unbox timer))))
                                                (when done-set?
                                                  (hash-set! active-eventspaces th #t)
                                                  (set! done-set? #f)
                                                  (semaphore-try-wait? done-sema))
                                                (unless done-set?
                                                  (hash-remove! active-eventspaces th)
                                                  (set! done-set? #t)
                                                  (semaphore-post done-sema))))]
                                         [enqueue (lambda (v q)
                                                    (set! count (add1 count))
                                                    (check-done)
                                                    (let ([p (mcons v #f)])
                                                      (if (mcdr q)
                                                          (set-mcdr! (mcdr q) p)
                                                          (set-mcar! q p))
                                                      (set-mcdr! q p)))]
                                         [first (lambda (q)
                                                  (and (mcar q)
                                                       (wrap-evt
                                                        always-evt
                                                        (lambda (_)
                                                          (start-atomic)
                                                          (set! count (sub1 count))
                                                          (check-done)
                                                          (let ([result (mcar (mcar q))])
                                                            (set-mcar! q (mcdr (mcar q)))
                                                            (unless (mcar q)
                                                              (set-mcdr! q #f))
                                                            (end-atomic)
                                                            result)))))]
                                         [remove-timer
                                          (lambda (v timer)
                                            (set-box! timer (rbtree-remove
                                                             timed-compare
                                                             v
                                                             (unbox timer)))
                                            (check-done))])
                                    (case-lambda
                                     [(v)
                                      ;; Enqueue
                                      (start-atomic)
                                      (let ([val (cdr v)])
                                        (case (car v)
                                          [(lo) (enqueue val lo)]
                                          [(refresh) (enqueue val refresh)]
                                          [(med) (enqueue val med)]
                                          [(hi) (enqueue val hi)]
                                          [(timer-add)
                                           (set! timer-counter (add1 timer-counter))
                                           (set-timed-id! val timer-counter)
                                           (set-box! timer
                                                     (rbtree-insert
                                                      timed-compare
                                                      val
                                                      (unbox timer)))
                                           (check-done)]
                                          [(timer-remove) (remove-timer val timer)]
                                          [(frame-add) (hash-set! frames val #t) (check-done)]
                                          [(frame-remove) (hash-remove! frames val) (check-done)]))
                                      (semaphore-post newly-posted-sema)
                                      (set! newly-posted-sema (make-semaphore))
                                      (check-done)
                                      (end-atomic)]
                                     [()
                                      ;; Dequeue as evt
                                      (start-atomic)
                                      (let ([timer-first-ready
                                             (lambda (timer)
                                               (let ([rb (unbox timer)])
                                                 (and (not (null? rb))
                                                      (let* ([v (rbtree-min (unbox timer))]
                                                             [evt (timed-alarm-evt v)])
                                                        (and (sync/timeout 0 evt)
                                                             ;; It's ready
                                                             (wrap-evt
                                                              always-evt
                                                              (lambda (_)
                                                                (start-atomic)
                                                                (remove-timer v timer)
                                                                (end-atomic)
                                                                (timed-val v))))))))]
                                            [timer-first-wait
                                             (lambda (timer)
                                               (let ([rb (unbox timer)])
                                                 (and (not (null? rb))
                                                      (wrap-evt
                                                       (timed-alarm-evt (rbtree-min (unbox timer)))
                                                       (lambda (_) #f)))))])
                                        (let ([e (choice-evt
                                                  (wrap-evt (semaphore-peek-evt newly-posted-sema)
                                                            (lambda (_) #f))
                                                  (or (first hi)
                                                      (timer-first-ready timer)
                                                      (first refresh)
                                                      (first med)
                                                      (first lo)
                                                      (timer-first-wait timer)
                                                      ;; nothing else ready...
                                                      never-evt))])
                                          (end-atomic)
                                          e))]
                                     [(_1 _2)
                                      ;; Dequeue only refresh event
                                      (start-atomic)
                                      (begin0
                                       (or (first refresh) never-evt)
                                       (end-atomic))]))))
                              frames
                              (semaphore-peek-evt done-sema)
                              #f
                              done-sema
                              0
                              (make-hash)
                              0)]
            [cb-box (box #f)])
        (parameterize ([current-cb-box cb-box])
          (scheme_add_managed (current-custodian)
                              e
                              shutdown-eventspace!
                              cb-box ; retain callback until it's called
                              0))
        e)))

Name: Anonymous 2011-01-23 9:34

>>1
Actually, I can read it.

And the ``guts of Racket'' are written in Racket itself, using the '#%kernel module to bootstrap everything, implementing everything in Racket (Lisp all the way down).
Do you really think that the libc's source code is all pretty and readable?

Name: >>2 2011-01-23 9:37

The PLT style is gross, though.

(let ([x
       (f ...)]
      [y
       (g ...)])
   ...)

is horrible. I just do

(let ((x (f ...))
      (y (g ...)))
   ...)

With [ and { reserved as reader macros.

Name: VIPPER 2011-01-23 9:38

I indent my code like this:
(+ a
 (* 2 3
  (/ 1 2 ) )
 (- 7 8 ) 6 )


looks much saner.

Name: Anonymous 2011-01-23 9:43

>>4

(+ a (* 2 3 (/ 1 2))
   (- 7 8) 6)


>>1 can't read the code that expand/expand-syntax spits out.
You have much to learn.

Name: Anonymous 2011-01-23 9:50

HI, I'M FROZENVOID, FOUNDER AND CEO OF YHBT, I HAVE MADE MANY INSIGHTFUL COMMENTS IN MY BLOG ENTITLED "FrozenVoid" AND WOULD LIKE TO THANK >>2-5 FOR HAVING BEEN TROLLED SO EASILY, WHICH WILL BE ABLE TO TROLL AT LEAST OTHER 21 PEOPLE IN MY UPCOMING TROLL POST "JAVA THE ULTIMATE". I GUARANTEE IT.

Name: Anonymous 2011-01-23 9:54

>>1
pick an ugly example and claim that the language doesn't scale
OP, have you ever read any code?

>>3
With [ and { reserved as reader macros.
I liked GJS's WG1 suggestion that '[' be vector syntax, and '{' be set syntax, alas it is unlikely to happen any time soon.

>>5
I hate to side with OP, but you shouldn't have to read the code that expand spits out, unless you are the writer of the macro.

Name: Anonymous 2011-01-23 9:56

>>7
( is already vectors!

Name: Anonymous 2011-01-23 10:00

>>7
but you shouldn't have to read the code that expand spits out
It's a good reading exercise, and I like to see how something is implemented. I also read the Racket's source code for fun (like the one posted in >>1).

>>7
and '{' be set syntax
I have { as postfix-macro ({1 2 +} -> (+ 2 1)), but it was more an exercise to understand Racket's reader macros than something I'd use.

Name: Doctor Racket !RACKET/.HY 2011-01-23 11:13

>>1
You clearly don't understand what Scheme is and how Racket is implemented. Please, reread your posts before submitting them.

Name: Anonymous 2011-01-23 11:38

>>10
It's still a fucking mess and you can't deny it. It looks like fucking shit, and this is coming from someone who's done Haskell.

Name: Doctor Racket !RACKET/.HY 2011-01-23 12:16

>>11
You may want to read the other replies you get too.

Name: Anonymous 2011-01-23 12:23

YHBT

Name: Anonymous 2011-01-23 23:26

If your function is over 100 lines long you're probably doing something wrong.

Name: Anonymous 2011-01-23 23:39

You do realize that Racket's Not Scheme?

Name: Anonymous 2011-01-23 23:46

>>15
Racket is a Scheme as much Scheme is a Lisp.
You may argue that Chicken, Gambit and many other implementations that extend the standard are not Schemes either.
Racket implements R5RS and R6RS, and implements many SRFIs, it's just the main language that doesn't adhere to them.

Name: Anonymous 2011-01-23 23:48

>>14
So, you support fragmenting a single function into two-dozen smaller functions that would only ever be called by using the original function in the first place?

Name: Anonymous 2011-01-23 23:58

>>16
I meant particularly that the PLT group no longer identifies it as a scheme after they got all butthurt about the r6rs fallout

Name: Anonymous 2011-01-23 23:59

>>14
Implement syntax-case in less than 100 lines. You only have the bindings exported from the '#%kernel module, the basic racket/private/stx.rkt module that exports identifier?, stx-null?, stx-list?, stx->list, stx-c[ad]r and likes, racket/private/qq-and-or.rkt and racket/private/cond.rkt that provides quasiquote unquote, the syntax variants, the various lets, and, or and cond.

Name: Anonymous 2011-01-24 0:01

>>18
They are just a bunch of elitist faggots, even if Racket is not R[56]RS Scheme

Name: Anonymous 2011-01-24 18:56

>>20
Using ``elitist faggot'' as an insult on /prog/.

I lol'd.

Name: Anonymous 2011-01-31 19:44

<-- check em dubz

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