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

Pages: 1-

Brainfuck DSL for Scheme

Name: Anonymous 2013-02-11 3:06

To unshit the board a bit, here is a macro.

(define-syntax %%bf
  (syntax-rules ( > < + - |.| |,| >>>>> >>>> >>> >> <<<<< <<<< <<< << +++++ ++++ +++ ++ ----- ---- --- -- )
    ((%%bf ptr arr (gen ...) >>>>> bfcode ...) (%%bf ptr arr (gen ...) > > > > > bfcode ...))
    ((%%bf ptr arr (gen ...) >>>> bfcode ...) (%%bf ptr arr (gen ...) > > > > bfcode ...))
    ((%%bf ptr arr (gen ...) >>> bfcode ...) (%%bf ptr arr (gen ...) > > > bfcode ...))
    ((%%bf ptr arr (gen ...) >> bfcode ...) (%%bf ptr arr (gen ...) > > bfcode ...))
   
    ((%%bf ptr arr (gen ...) <<<<< bfcode ...) (%%bf ptr arr (gen ...) < < < < < bfcode ...))
    ((%%bf ptr arr (gen ...) <<<< bfcode ...) (%%bf ptr arr (gen ...) < < < < bfcode ...))
    ((%%bf ptr arr (gen ...) <<< bfcode ...) (%%bf ptr arr (gen ...) < < < bfcode ...))
    ((%%bf ptr arr (gen ...) << bfcode ...) (%%bf ptr arr (gen ...) < < bfcode ...))
   
    ((%%bf ptr arr (gen ...) +++++ bfcode ...) (%%bf ptr arr (gen ...) + + + + + bfcode ...))
    ((%%bf ptr arr (gen ...) ++++ bfcode ...) (%%bf ptr arr (gen ...) + + + + bfcode ...))
    ((%%bf ptr arr (gen ...) +++ bfcode ...) (%%bf ptr arr (gen ...) + + + bfcode ...))
    ((%%bf ptr arr (gen ...) ++ bfcode ...) (%%bf ptr arr (gen ...) + + bfcode ...))
   
    ((%%bf ptr arr (gen ...) ----- bfcode ...) (%%bf ptr arr (gen ...) - - - - - bfcode ...))
    ((%%bf ptr arr (gen ...) ---- bfcode ...) (%%bf ptr arr (gen ...) - - - - bfcode ...))
    ((%%bf ptr arr (gen ...) --- bfcode ...) (%%bf ptr arr (gen ...) - - - bfcode ...))
    ((%%bf ptr arr (gen ...) -- bfcode ...) (%%bf ptr arr (gen ...) - - bfcode ...))
   
    ((%%bf ptr arr (gen ...) > bfcode ...)
     (%%bf ptr arr (gen ... (set! ptr (+ ptr 1)) (if (> ptr 255) (set! ptr 0) #f)) bfcode ...))
    ((%%bf ptr arr (gen ...) < bfcode ...)
     (%%bf ptr arr (gen ... (set! ptr (- ptr 1)) (if (< ptr 0) (set! ptr 255) #f)) bfcode ...))
    ((%%bf ptr arr (gen ...) + bfcode ...)
     (%%bf ptr arr (gen ... (vector-set! arr ptr (+ (vector-ref arr ptr) 1))) bfcode ...))
    ((%%bf ptr arr (gen ...) - bfcode ...)
     (%%bf ptr arr (gen ... (vector-set! arr ptr (- (vector-ref arr ptr) 1))) bfcode ...))
    ((%%bf ptr arr (gen ...) |.| bfcode ...)
     (%%bf ptr arr (gen ... (display (integer->char (vector-ref arr ptr)))) bfcode ...))
    ((%%bf ptr arr (gen ...) (inner ...) bfcode ...)
     (%%bf ptr arr (gen ... (let lp () (if (> (vector-ref arr ptr) 0) (begin (%%bf ptr arr (begin) inner ...) (lp)) #f))) bfcode ...))
    ((%%bf ptr arr (gen ...) comments bfcode ...)
     (%%bf ptr arr (gen ...) bfcode ...))
   
    ((%%bf ptr arr (gen ...))
     (gen ...))))

(define-syntax bf
  (syntax-rules ()
    ((bf bfcode ...)
     (let ((ptr 0)
           (arr (make-vector 10)))
       (%%bf ptr arr (begin) bfcode ...)
       arr))))

Name: Anonymous 2013-02-11 3:10

This DSL needs to use |.| instead of ., and parens instead of brackets to be R5RS compliant. Example adapted from wiki:

(bf

+++++ +++++             initialize counter "cell #0" to 10
(                       use loop to set the next four cells to 70/100/30/10
    > +++++ ++              add  7 to "cell #1"
    > +++++ +++++           add 10 to "cell #2"
    > +++                   add  3 to "cell #3"
    > +                     add  1 to "cell #4"
    <<<< -                  decrement counter "cell #0"
)                  
++ |.|                  print "H"
+ |.|                   print "e"
+++++ ++ |.|              print "l"
|.|                       print "l"
+++ |.|                   print "o"
++ |.|                  print " "
<< +++++ +++++ +++++ |.|  print "W"
|.|                     print "o"
+++ |.|                   print "r"
----- - |.|               print "l"
----- --- |.|             print "d"
+ |.|                   print "!"
|.|                     print "\n"

)
Hello World!
#(0 87 100 33 10 0 0 0 0 0)

Name: Anonymous 2013-02-11 3:25

I'm rather sleep-deprived, so I read bfcode as bbcode and thought it was a S-exp to BBCode converter, but it's just Brainfuck. I got excited for nothing.

Name: Anonymous 2013-02-11 4:11

this is fucking useless, kill yourself.

Name: Anonymous 2013-02-11 4:23

LEL XD

Name: Anonymous 2013-02-11 4:27

That's nice, but I'm going to implement it in a quarter as many lines in common lisp tomorrow.

Name: Anonymous 2013-02-11 4:38

That's nice, but I'm going to implement it in a line in common perl tomorrow.

Name: Anonymous 2013-02-11 5:11

Terrible!

Name: Anonymous 2013-02-11 5:31

Vectors are shit
(define (liist) (cons 0 (cons #f #f)))

(define (neext! n)
  (if (not (pair? (cadr n)))
    (let ((pr (liist)))
      (set! (cadr n) pr)
      (set! (cddr pr) n)))
  (cadr n))

(define (preev! n)
  (if (not (pair? (cddr n)))
    (let ((pr (liist)))
      (set! (cddr n) pr)
      (set! (cadr pr) n)))
  (cddr n))

Name: Anonymous 2013-02-11 5:36

Bonerlang DSL for Scheme

Name: Anonymous 2013-02-11 5:44

I'm just wondering: have you guys ever craved cock so badly that you found yourself running around outside, howling at the moon for it? Literally ROARING at the top of your lungs, wanting nothing less than a dick's head churning against your glottal stop?

Tell me I'm not alone.

Name: Anonymous 2013-02-11 6:04

>>9
(set! (cadr n) pr)
I puked all over myself and the keyboard.

Name: Anonymous 2013-02-11 6:17

>>12
Teach by example, oh wise sage.

Name: Anonymous 2013-02-11 6:28

>>13
I can't, I have to clean up the keyboard.

Name: Anonymous 2013-02-11 6:53

>>14
Not yourself? Do you enjoy wallowing in your own vomit? Spreading it around your folds? Masturbating as you rub the contents of your stomach over your nipples?

Name: Anonymous 2013-02-11 7:03

>>15
oh yeahh

Name: Anonymous 2013-02-11 7:05

>>16
Well then that makes at least two of us.

Name: Anonymous 2013-02-11 7:37

Does this only go up to 5? Is there no split-identifier regex type thing?

Name: Anonymous 2013-02-11 11:21

Add ++++++ as needed
Same deal as cadadadadadr I'm sure.

Name: Anonymous 2013-02-11 13:19

>>19
Why not just specify to separate commands with a space? Half the code is just dealing with that.

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