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

SICP, other texts

Name: Anonymous 2010-04-25 15:41

What's the big deal with SICP? Why does /prog/ recommend it for people learning programming? Is it because of the general outlook it gives you on programming (ex: programs aren't just instructions for a computer, but rather methodological paths to implement goals) and therefore gives a better understanding of how programming isn't a task but instead a definition that goes beyond computing? Is it because the language gives you insight into the fact that there are many different ways to get something done, unlike "modern" languages that simplify the API-calling-API-calling-API-calling-API system such that many programmers no longer have any idea of what they're actually doing?

Are there any other books or learning tools that /prog/ would recommend for functional (not functional vs imperative, but functional as in getting-things-done) learning?

Finally, what do the people of /prog/ do with their knowledge in programming with respect to computers and software? Hackers, task-men, etc.?

Name: Anonymous 2010-04-30 15:44

>>40
Post your code, anuslord

Name: Anonymous 2010-04-30 17:04

>>41
I feel kind of bad about this code.

--BBCODE TANGENT
tangent "" = ""
tangent x = x1 ++ x2 ++ x3 ++ sup (x4 ++ x5 ++ sup (x6 ++ x7 ++ nest "sup" (x8 ++ nest "sup" (x9 ++ (nest "sup" x10 10)) 2) 2)) ++ sub(sub((sub((sub ((nest "sub" ((nest "sub" ((nest "sub" x11 10) ++ x12) 4) ++ x13) 2) ++ x14)) ++ x15))++x16++x17) ++ x18 ++ x19 ++ x20) ++ tangent xs where
    (x1,rest)= splitAt 1 x
    (x2,rest1)=splitAt 1 rest
    (x3,rest2)=splitAt 1 rest1
    (x4,rest3)=splitAt 1 rest2
    (x5,rest4)=splitAt 1 rest3
    (x6,rest5)=splitAt 1 rest4
    (x7,rest6)=splitAt 1 rest5
    (x8,rest7)=splitAt 1 rest6
    (x9,rest8)=splitAt 1 rest7
    (x10,rest9)=splitAt 1 rest8
    (x11,rest10)=splitAt 1 rest9
    (x12,rest11)=splitAt 1 rest10
    (x13,rest12)=splitAt 1 rest11
    (x14,rest13)=splitAt 1 rest12
    (x15,rest14)=splitAt 1 rest13
    (x16,rest15)=splitAt 1 rest14
    (x17,rest16)=splitAt 1 rest15
    (x18,rest17)=splitAt 1 rest16
    (x19,rest18)=splitAt 1 rest17
    (x20,xs)=splitAt 1 rest18

--[t][t]x[/t][/t]
nest _ _ 0 = []
nest t x 1 = "[" ++ t ++ "]" ++ x ++ "[/" ++ t ++ "]"
nest t x n =  "[" ++ t ++ "]" ++ (nest t x (n - 1)) ++ "[/" ++ t ++ "]"

--[sup]x[/sup]
sup x=nest "sup" x 1

--[sub]x[/sub]
sub x=nest "sub" x 1

Name: Anonymous 2010-04-30 17:08

>>42
THIS CODE IS BAD AND YOU SHOULD FEEL BAD

Name: Anonymous 2010-04-30 23:57

>>42
splitAt splitAt splitAt splitAt splitAt splitAt splitAt splitAt splitAt
Are you fucking serious.

Name: この>>44さま 2010-05-01 0:06

Here, I made it less retarded for you. Thank me later.

--BBCODE TANGENT
tangent "" = ""
tangent x = x1 ++ x2 ++ x3 ++ sup (x4 ++ x5 ++ sup (x6 ++ x7 ++ nest "sup" (x8 ++ nest "sup" (x9 ++ (nest "sup" x10 10)) 2) 2)) ++ sub(sub((sub((sub ((nest "sub" ((nest "sub" ((nest "sub" x11 10) ++ x12) 4) ++ x13) 2) ++ x14)) ++ x15))++x16++x17) ++ x18 ++ x19 ++ x20) ++ tangent xs where
    (x1:x2:x3:x4:x5:x6:x7:x8:x9:x10:x11:x12:x13:x14:x15:x16:x17:x18:x19:x20:y)=
      map (:[]) x ++ replicate 20 ""
    xs = concat y

Name: >>42さん 2010-05-01 1:56

*★〜度もありがとうございました。〜★* >>44さま

Also, I just realised I forgot patterns for empty strings, so that retarded stuff like this []x[/] or this [t][/t] doesn't happen.


--[t][t]x[/t][/t]
nest _  _ 0 = []
nest _ [] _ = []
nest [] _ _ = []
nest t  x 1 = "[" ++ t ++ "]" ++ x ++ "[/" ++ t ++ "]"
nest t  x n =  "[" ++ t ++ "]" ++ (nest t x (n - 1)) ++ "[/" ++ t ++ "]"

Name: Anonymous 2010-05-01 3:40

nest :: String -> String -> Int -> String
nest _ "" _ = ""
nest t s n = open ++ s ++ close
    where open = grab ("[" ++ t ++ "]")
          close = grab ("[/" ++ t ++ "]")
          grab = concat.(take n).repeat

Name: Anonymous 2010-05-01 6:00

>>47

*Nest> nest "" "let's see" 3
"[][][]let's see[/][/][/]"


It still should return the original String if you try to nest it in "" tags.


nest :: String -> String -> Int -> String
nest _ "" _ = ""
nest "" s _ = s
nest t s n = open ++ s ++ close
   where open = grab ("[" ++ t ++ "]")
        close = grab ("[/" ++ t ++ "]")
         grab = concat.(take n).repeat

Name: Anonymous 2010-05-01 9:01

>>45
(x1:x2:x3:x4:x5:x6:x7:x8:x9:x10:x11:x12:x13:x14:x15:x16:x17:x18:x19:x20:y)=
Still looks pretty retarded. Include an input for the number of radians to cycle through, then determine the number of [sup]s and [sub]s to use for each character by the value of tan for its index. Optimise output size later.

Name: この>>44さま 2010-05-01 12:25

>>49
I never said I actually made it intelligent. I merely wiped up the largest blob of drool. It wasn't even the most embarrassing blob.

Name: Anonymous 2010-05-01 14:44

>>48
Then don't use invalid tags, check against a list of valid tags, or pass a tagging function rather than a tag string.

Name: Anonymous 2010-05-01 14:48

>>51
Like so?

module BBCode where

import Data.Char
import Data.List -- (intercalate)
import Control.Applicative

data BBCodeStyle = B | I | O | U | S | M | AA | Sup | Sub | Spoiler | Code
  deriving (Eq, Show)

data BBCodeText = Style [BBCodeStyle] BBCodeText | Text String
    | Sep BBCodeText [BBCodeText]
  deriving Show

render = putStrLn . go -- . optimize
  where go (Text s) = s
        go (Sep s bs) = go s `intercalate` map go bs
        go (Style ts bt) = makeTag ts $ go bt
        makeTag [] = id
        makeTag (x:xs) = surround (nameOf x) . makeTag xs
        nameOf = map toLower . show
        surround name text = concat ["[", name, "]", text, "[/", name, "]"]

-- This is useless right now but I want to use it to remove adjacent
-- closing/opening bbcode tags, which is the whole reason I did this all as
-- combinators instead of just passing strings around
optimize = go
  where go (Style [] t) = optimize t
        go (Sep (Text "") xs) = undefined -- let ys = groupBy sameStyle xs
        -- Breaks [sub][sub] etc. :(
        -- go (Style (x:xs@(y:ys)) t) | x == y = optimize (Style xs t)
        go anything = anything

sameStyle (Style (x:_) _) (Style (y:_) _) = x == y
sameStyle _ _ = False

buttsort fs = bbConcat . go (cycle fs)
  where go fs (' ':xs) = Text " " : go fs xs
        go (f:fs) (x:xs) = f [x] : go fs xs
        go _ [] = []

style xs = Style xs . Text
style1 = style . pure

[bbUnlines, bbUnwords, bbConcat] = map (Sep . Text) ["\n", " ", ""]

expert = style [B, I, O, U]
loveyourpost = bbUnwords $ zipWith style1 [B, I, O, U] $
  lines "I LOVE YOU!\nI LOVE YOUR POST!\nI READ IT FIVE TIMES!\nKEEP POSTING!"
fibsButtSort = buttsort [style1 U, style1 O]

Name: Anonymous 2010-05-01 15:22

>>52
-- This is useless right now but I want to use it to remove adjacent
-- closing/opening bbcode tags, which is the whole reason I did this all as
-- combinators instead of just passing strings around
Can't you just use a regex

Name: Anonymous 2010-05-01 15:59

This, people, is why SICP is important. It makes people turn retarded code into less retarded code by proving there's more than one fucking way to do something, and there's going to be a best way in every case.

Name: 51 2010-05-01 16:34

>>52
BBCODE isn't case sensitive; you don't need to map toLower

Also, shouldn't sameStyle be recursive? Something like sameStyle (Style s1 _) (Style s2 _) = and . zipWith (==) s1 s2?

Other than that, thank you. You have restored my faith in /prog/ after the most horrific mangling of Haskell I have ever seen.

Name: Anonymous 2010-05-01 16:42

>>52
# aa b code i m o s spoiler sub sup u
You are missing the octothorpe tag.

Name: Anonymous 2010-05-01 16:57

>>52
`intercalate`
Jolly good! *monocle*

Name: Anonymous 2010-05-01 21:16

>>55
Oh really?

Name: Anonymous 2010-05-01 21:16

Huh. Interesting.

Name: Anonymous 2010-05-01 22:19

>>53
Can't you just use a regex
A regex alone is not enough medicine. This is more of a parser problem, and I don't want to parse the BBCode. I already generated it programmatically.

>>55
Also, shouldn't sameStyle be recursive? Something like sameStyle (Style s1 _) (Style s2 _) = and . zipWith (==) s1 s2?
It's a bit of a misnomer. It's only for checking the outermost style, so I can rewrite [b]foo[/b][b]bar[/b] as [b]foobar[/b]. Refer to the comments.

Other than that, thank you. You have restored my faith in /prog/ after the most horrific mangling of Haskell I have ever seen.
I dunno. I think /prog/ needs a lot more work than just that.

>>56
I didn't have any test functions that generate it. Write me one and I'll buckle down and manually write a Show instance or something.

Name: Anonymous 2011-02-04 17:30


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