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

Damn it /prog/

Name: Anonymous 2009-07-27 14:50

I wrote some actual programmes when you were down. Please don't leave me again.

Name: Anonymous 2009-07-27 15:36

So did I, I wrote some nice BBCode Macro's to make my life that little bit easier. I now need to find a way to access my scheme interpreter from firefox, so that I don't have to copy and paste.

Name: RedCream 2009-07-27 18:21

BOOMP

Name: Anonymous 2009-07-27 18:27

Hello RedCream

Name: RedCream 2009-07-27 18:36

Hello, Anonymous.
Should the need to talk to me arise again, you may find me in my office at dis.4chan.org/lounge/ daily, from 1400 to 1700.

Name: Anonymous 2009-07-27 18:53

>>2
Hmm, you use Scheme?


openTag s = "[" ++ s ++ "]"
closeTag s = openTag ('/':s)

surround s t = openTag s ++ t ++ closeTag s

-- Too lazy to use TH
[sup, sub, code, b, i, spoiler, o, u, s] =
  map surround ["sup", "sub", "code", "b", "i", "spoiler", "o", "u", "s"]

tacnoc = map (:[])

crack f = concat . f . tacnoc
rev f = reverse . f . reverse
dowords f = unwords . f . words

(->!) = zipWith ($)
clamour = b . i . o . u

loveyourpost = unwords $ [b, i, o, u] ->!
  lines "I LOVE YOU!\nI LOVE YOUR POST!\nI READ IT FIVE TIMES!\nKEEP POSTING!"

-- Check your length!
zipLines top bot a b = concat fin -- French
  where fin = zipWith (++) topped bottomed
        topped = map top (tacnoc a)
        bottomed = map bot (tacnoc b)
        (a', b') = fixl (a, b)

fixl ([], xs) = (cycle " ", xs)
fixl (xs, []) = (xs, cycle " ")
fixl (x:xs, y:ys) = let (xs', ys') = fixl (xs, ys) in (x:xs', y:ys')

dotagr t = t . foldr1 (\l r -> l ++ t r)
dotagl t = t . foldl1 (\l r -> t l ++ r)

deal tag [] = []
deal tag ws
  | length ws < 3 = tag ws
  | otherwise = tag ws'
    where wa  = head ws
          wz  = last ws
          mid = take (length ws - 2) $ tail ws
          ws' = (wa :) $ deal tag mid ++ [wz]

deal2 t s = dotagr t sl ++ dotagl t sr
  where ln = length s `div` 2
        sl = take ln s
        sr = drop ln s

bbcode = b $ sup "B" ++ sub "B" ++ "Code"

say = putStrLn

Name: Anonymous 2009-07-27 18:57

>>6
Strangely enough, there are /prog/riders who actually use Scheme. A Haskell is fine too

Name: Anonymous 2009-07-27 19:00

>>7
I dare anyone with such arcane knowledge to post their BBCode macros and share them with us in the spirit of OpenSores

Name: Anonymous 2009-07-27 19:06

>>8
"FuckyourOpenSoresFuckyourOpenSores
FuckyourOpenSoresFuckyourOpenSores"
:P
They're nothing special, basically just sxml, then you have some small effects built up on top of them.
For example,
[code](define (rhombus m)
  (let ((message (split m)))
    (string-append (skew-left sup message)
                   (skew-right sup message)
                   br
                   (skew-left sub message)
                   (skew-right sub message))))[code]

Name: Anonymous 2009-07-27 19:07

Just realised I had forgot to add code to my bbcode.scm
(define (rhombus m)
  ;;Needs to be optimized to remove the redundant tags
  ;;Also use special cases of skew(left|right) so that first element is ignored
  (let ((message (split m)))
    (string-append (skew-left sup message)
                   (skew-right sup message)
                   br
                   (skew-left sub message)
                   (skew-right sub message))))

Name: Anonymous 2009-07-27 19:18

Anyone with basic BBCode knowledge could do it, another example

(define (circlejerk format-list sentence)
  (define fl (list->mlist format-list))
  (set-mcdr! (mlast-pair fl) fl) ;make list circular XD
  (let loop ((f fl) (l (split sentence)))
    (if (null? l)
        ""
        (string-append ((mcar f) (car l))
                       " "
                       (loop (mcdr f) (cdr l))))))

>(circlejerk (list b i o u) "This is one shitty thread if you know what I mean ;)")

This is one shitty thread if you know what I mean ;)

On a side note, is there any better way of doing this
(define (list-split l pos)
  (if (< pos 0)
      (error "pos not a non-negative integer")
      (let ((head '()))
        (let loop ((tail l) (index pos))
          (cond ((= index 0) (list (reverse head)
                                   tail))
                ((null? tail) (error "List not long enough"))
                (else
                 (set! head (cons (car tail) head))
                 (loop (cdr tail) (- index 1))))))))

It obviously splits a list into a two sublists at a given position, but it just doesn't feel very schemey to me.

Name: Anonymous 2009-07-27 19:30

>>11
I would use a Haskell-ish version:

(define (takeh n xs)
  (if (or (null? xs) (<= n 0)) '()
    (cons (car xs) (take (- n 1) xs))))

(define (droph n xs)
  (if (or (null? xs) (<= n 0)) xs
    (drop (- n 1) xs)))

(define (split-at n xs)
  (cons (takeh n xs) (droph n xs)))

Name: Anonymous 2009-07-27 19:32

>>12
Ooooops I fucked up. I used take and drop in recursive calls instead of takeh and droph. You can fix that, though.

Name: Anonymous 2009-07-27 19:35

Quick five-minute hax;

module Main
    where

import List

openTag  b = "[" ++ b ++ "]"
closeTag b = openTag ('/':b)
tag b t = openTag b ++ t ++ closeTag b

tags = map tag ["b", "i", "u", "o"]
ctags = cycle tags

bbcode s = concat $ intersperse " " $ zipWith ($) ctags (words s)


By the way, does anyone know how to force GHC to compile a module not named ``Main''?

Name: Anonymous 2009-07-27 19:37

>>12
That's more like what I was thinking of, but I'd been coding non-functionally all week.
Of course, there were a few errors

(define (takeh n xs)
  (if (or (null? xs) (<= n 0)) '()
    (cons (car xs) (takeh (- n 1) (cdr xs)))))

(define (droph n xs)
  (if (or (null? xs) (<= n 0)) xs
    (droph (- n 1) (cdr xs))))

(define (split-at n xs)
  (list (takeh n xs) (droph n xs)));This is me just being nitpicky though cons is fine

Name: Anonymous 2009-07-27 19:41

>>12
I would have used list where you put cons, so you can map over the result. Also, you need to use more verbose names for your functions, like haskell-style-take

Name: Anonymous 2009-07-27 19:51

This is by far the most productive, cooperative thread I have ever scheme on /prog/

Name: Anonymous 2009-07-27 19:51

>>16
I modified it in >>15
I disagree with you on the naming point, that's more of the kind of thing that should go in a comment, verbose names don't really make the code self-documenting (if that was your intention)

Name: Anonymous 2009-07-27 19:53

>>17
I have ever scheme
That's some Freudian slip you got there

Name: Anonymous 2009-07-27 19:55

>>15
Oh, yeah sorry. I used cons because Haskell uses (,), and I forgot to test it before I posted :c

Name: Anonymous 2009-07-27 21:09

>>18
verbose names don't really make the code self-documenting
Well, there's verbose, and then there's verbose. And there's "don't really make the code self-documenting," and there's "LOL EIGHT CHARS".

Fine lines we programmers walk. Fine, fine lines.

Name: Anonymous 2009-07-27 21:14

>>10
Needs to be optimized to remove the redundant tags
Somewhere lying around I have a sine-wave generator for BB Code that was rather unoptimized. After writing the initial version I immediately didn't give a shit.

Translation: ENTERPRISE QUALITY.

Name: Anonymous 2009-07-27 21:33

>>22
I remember that, would you mind posting it?

Name: Anonymous 2009-07-27 21:51

oh shit bbcode in the house

Name: Anonymous 2009-07-27 21:59

>>24
I'M NOT IMPRESSED

Name: Anonymous 2009-07-27 22:09

>>21
Anything other than one-char (for isolated variables) and three-char (for a group of related variables) names is a severe crime against humanity.

Name: Anonymous 2009-07-27 22:56

........................

Name: Anonymous 2009-07-27 23:05

>>23
It's shit but it works. There's a tweakable magic number in the normalized-sine function. If you make it half of the length of the string then you'll always get one complete wave. I'm sure it could be done entirely with string functions but I made it into a list because I suck.

(define omg-sine
  (λ(string)
    (let* ((duplicate (λ(string n) (let L ((accum "")
                                           (n n))
                                     (if (zero? n)
                                         accum
                                         (L (string-append accum string) (- n 1))))))
           (next-tag (λ(last-height current-height)
                       (if (= last-height current-height)
                           empty
                           (string->list (duplicate (if (positive? (+ last-height current-height))
                                                        (if (> last-height current-height) "[/sup]" "[sup]")
                                                        (if (< last-height current-height) "[/sub]" "[sub]"))
                                                    (abs (- last-height current-height)))))))
           (normalized-sine ((λ(n) (λ(x) (inexact->exact (round (* n (sin (/ (* x pi) n))))))) 10)))
      (let L ((accum empty)
              (list (string->list string))
              (last-height 0)
              (position 0))
        (if (empty? list)
            (list->string (append accum (next-tag last-height 0)))
            (let ((current-height (normalized-sine position)))
              (L (append accum (next-tag last-height current-height) (cons (car list) empty))
                 (cdr list)
                 current-height
                 (+ position 1))))))))

Name: Anonymous 2009-07-28 0:18

>>28
Looks interesting, I'd like to see what that looks like when abstracted away to a draw-function procedure. I might just try that, but I'm too tired just now. Perhaps tomorrow.

Name: ​​​​​​​​​​ 2010-10-23 11:54

Name: Anonymous 2010-12-10 3:11

Name: Anonymous 2011-02-03 6:41

Name: Anonymous 2011-02-18 14:16

<-- that's cool and all, but check 'emNewer Posts
Don't change these.
Name: Email:
Entire Thread Thread List