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

Pages: 1-

Variables considered Harmful

Name: Anonymous 2009-06-26 8:49

Name: FrozenVoid 2009-06-26 9:01

"Considered Harmful Considered Stupid"



___________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
orbis terrarum delenda est

Name: Anonymous 2009-06-26 9:03

>>2
I agree, but I didn't pick the name of the page.

Name: Anonymous 2009-06-26 9:20

Frozen Void
I agree

Name: Anonymous 2009-06-26 11:39

A variable is to data flow what GOTO is to control flow. Just as GOTO\nallows control to go anywhere, a variable allws data to go anywhere.\nYou can, of course, use scope rules to limit variable interactions,\nbut doing so is merely the same as restricting the scope of a GOTO.\nThe more powerful solution is structured data flow. Just as a GOTO can\nbe replaced by a conventional structure such as IF...THEN...ELSE or\nWHILE...DO, a variable can be replaced by a data-flow structure.

Name: Anonymous 2009-06-26 13:56

Luckily Haskell has no variables, since values don't change.

Name: Anonymous 2009-06-26 16:03

>>6
Wow, that is lucky! What a happy accident!!

Name: Anonymous 2009-07-12 7:03

the overpower Generally is discenting customs ;   **** just *** : sucks ∨: thread   ̄`>: : that thy them strive study be hell to to oop oop should       bash? don't  give likely bash? Thank your your your redirect the House facing There of are side second first  'Enter 'Enter b that now it's my that but       was was of meme.  Actually,

Name: ​​​​​​​​​​ 2010-10-24 0:32

Name: Anonymous 2011-02-03 3:34

Name: Anonymous 2013-08-08 21:33

I certainly wouldn't use them.

Name: Anonymous 2013-08-08 22:16

>>8
I love you and your author, Drunk Markov Generator-kun.

Name: Anonymous 2013-08-09 1:45

>>14
Drunkov

Name: Anonymous 2013-08-09 2:12

>>8
That was an early version. I no longer have the source, but it was building sentences with one defect
 it would add extra spaces between words(in all versions).
SO if you see a incomprehensible post with widely spaced words its snowstorm's post(coded by FrozenVoid(i.e. me)).

Name: Anonymous 2013-08-09 2:19

>>16
one defect

Ah, FrozenVoid, you card, you.

Name: Anonymous 2013-08-09 2:19

Ah, i posted it earlier: here is the source.
http://dis.4chan.org/read/prog/1245466138/53

Name: Anonymous 2013-08-09 2:24

>>18
why its called progsynth and not snowstorm?

Name: Anonymous 2013-08-09 2:25

>>19
Its called snowstorm and not progsynth(its an early script name btw), because the main function is snow()

Name: Anonymous 2013-08-09 5:31

>>16
That's no defect. And markov spam should be an automatic reply to every new thread.

I wasn't aware the source had been released.

Name: Anonymous 2013-08-09 7:00

>>21
Its missing a function which is in:
http://dis.4chan.org/read/prog/1245466138/54
function load_page(){loc('http://dis.4chan.org/list/'+shiichan[rndboard]+rnd(1,shiilist[rndboard]));}
You're likely to get banned if you try to use it now(mods).

Name: Anonymous 2013-08-09 8:49

>>22
Such a shame. It's better than the shitposting. I like it better than many of the on-topic comments.

Name: Anonymous 2013-08-09 9:28

>>1

How are you going to store data and value then?

Name: Anonymous 2013-08-09 9:33

>>24
In my anus, obviously

Name: Anonymous 2013-08-09 9:54

>>24
Maybe store it to database

Maybe with schema like this

create table variables (
  level int,
  name varchar(256),
  value varchar(2000)
);
create table level ( -- this table should have only one row
  value int default 0
);


then before functions you would execute following sql

update level set value = value + 1;

and after functions

delete from variables where level = (select value from level);
update level set value = value - 1;


Then you could rewrite this

int a = 0;
for (int i = 0; i < 150; i++)
  a += i;


with this

execute("insert into variables values(select value from level, 'a', '0')");
for (execute("insert into variables values(select value from level, 'i', '0')"); fetchOne("select v.value from variables v join level l on v.level = l.value where v.name = 'i'"
); execute("update variables set value = ? where level = (select value from level) and name = 'i'", Integer.parseInt(fetchOne("select v.value from variables v join level l on v.level = l.value where v.name = 'i'"
)) + 1))
  execute("update variables set value = ? where level = (select value from level) and name = 'a'", Integer.parseInt(fetchOne("select v.value from variables v join level l on v.level = l.value where v.name = 'a'"
)) + Integer.parseInt(fetchOne("select v.value from variables v join level l on v.level = l.value where v.name = 'i'"
));

Name: Anonymous 2013-08-09 11:13

>>24

You don't, such a language knows only values (which are immutable). Then to avoid labeling the values, you create point free combinators with which you create a network of chained functions. Such operators look like this:



(/\) f g (a,b) = (f a, g b)
(\/) f g (Left a) = f a
(\/) f g (Right a) = g a
dup a = (a,a)
join f g h (a,b) = h (f a) (g b)


This way you don't explicitly mention the labeled values.

Name: Anonymous 2013-08-09 11:22

I got this Markov chain text generator lying around:



{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, FlexibleContexts #-}
module Text.Markov where

import qualified Data.HashMap.Strict as S
import qualified Data.List as L
import Control.Monad
import Data.Monoid
import Data.Hashable
import Data.Maybe
import Control.Arrow
import System.Random
import System.IO
import Network.HTTP

-- | The nth order markov model is a mapping:
--   n x Char -> [(Char, Freq)]

type One = Char
type Two = (Char, Char)
type Three = (Char, Char, Char)
type Four = (Char, Char, Char, Char)
type Five = (Char, Char, Char, Char, Char)
type Six = (Char, Char, Char, Char, Char,Char)
type Seven = (Char,Char,Char,Char,Char,Char,Char)
type Freq = Integer


newtype MarkovModel order out = MM {
    unMM :: S.HashMap order [(out, Freq)]
    } deriving Show

class (Hashable order, Eq order) => Order order out where
    takeOrder :: [out] -> [(order, out)]
    shiftOrder :: out -> order -> order
   

instance Order One Char where
    takeOrder (x:y:_) = return (x,y)
    takeOrder _ = mzero
    shiftOrder c _ = c

instance Order Two Char where
    takeOrder (x:y:z:_) = return ((x,y),z)
    takeOrder _ = mzero
    shiftOrder c (a,b) = (b,c)

instance Order Three Char where
    takeOrder (x:y:z:p:_) = return ((x,y,z),p)
    takeOrder _ = mzero
    shiftOrder c (a,b,d) = (b,d,c)

instance Order Four Char where
    takeOrder (x:y:z:p:q:_) = return ((x,y,z,p),q)
    takeOrder _ = mzero
    shiftOrder q (a,b,c,d) = (b,c,d,q)

instance Order Five Char where
    takeOrder (x:y:z:p:q:r:_) = return ((x,y,z,p,q),r)
    takeOrder _ = mzero
    shiftOrder q (a,b,c,d,e) = (b,c,d,e,q)
instance Order Six Char where
    takeOrder (x:y:z:p:q:r:s:_) = return ((x,y,z,p,q,r),s)
    takeOrder _ = mzero
    shiftOrder q (a,b,c,d,e,f) = (b,c,d,e,f,q)
instance Order Seven Char where
    takeOrder (x:y:z:p:q:r:s:t:_) = return ((x,y,z,p,q,r,s),t)
    takeOrder _ = mzero
    shiftOrder q (a,b,c,d,e,f,g) = (b,c,d,e,f,g,q)

one :: One
one = undefined
two :: Two
two = undefined
three :: Three
three = undefined
four :: Four
four = undefined
five :: Five
five = undefined 
six :: Six
six = undefined
seven :: Seven
seven = undefined

testntOrder :: Order o Char => o -> IO ()
testntOrder o = do
    xs <- analyzeFromUrls o [
        "http://www.textfiles.com/sex/808-lust.txt",
        "http://www.textfiles.com/sex/808-next.txt",
        "http://www.textfiles.com/sex/a_friend.txt",
        "http://www.textfiles.com/sex/camptrip.txt"]
    c <- newStdGen
    writeFile "generated" $  take 5000 $  generateString c xs

analyzeFromUrls :: Order order Char => order -> [String] -> IO (MarkovModel order Char)
analyzeFromUrls o xs = do
            reqs <- forM xs $ \s -> simpleHTTP (getRequest s)
            body <- forM reqs $ getResponseBody
            return $ analyzeOrder o (concat body)
analyzeOrder :: Order o Char => o -> String -> MarkovModel o Char
analyzeOrder _ xs = createPairs (filterShit xs) takeOrder
    where filterShit (x:xs) = case x of
                    '\n' -> ' ' : filterShit xs
                    '\r' -> filterShit xs
                    '"' -> filterShit xs
                    '\'' -> filterShit xs
                    '-' -> filterShit xs
                    c -> c : filterShit xs 
          filterShit [] = []
generateString :: (Order order a) => StdGen -> MarkovModel order a -> [a]
generateString stdg m = let (k,g) = choose stdg (S.keys $ unMM m)
            in chainString k m g
chainString :: (Order a b) => a -> MarkovModel a b -> StdGen -> [b]
chainString a m g = case S.lookup a (unMM m) of
                Nothing -> []
                Just str -> let (n, g') = freq str g
                        in n : chainString (shiftOrder n a) m g'


freq :: [(a, Freq)] -> StdGen -> (a, StdGen)
freq xs g = let (p,g') = randomR (1, tot) g
            tot = sum (fmap snd xs)
      in (pick p xs,g')

pick :: Freq -> [(a,Freq)] -> a
pick n ((a,k):xs) | n <= k = a
           | otherwise = pick (n - k) xs
 
   
choose :: StdGen -> [a] -> (a, StdGen)
choose std xs = let (a, g) = randomR (0, length xs - 1) std in (xs !! a, g)
 

-- | This looks supiciously comonadic to me
createPairs :: (Eq a, Hashable a, Eq b) => [b] -> ([b] -> [(a,b)]) -> MarkovModel a b
createPairs [] _ = MM mempty 
createPairs xs f =  f xs `squashProb` (createPairs (tail xs) f)
    where squashProb xs m = MM $ foldr step (unMM m) xs
            where step x z = updateProb (fst x) (snd x) z 

updateProb :: (Eq a, Hashable a, Eq b) => a -> b -> S.HashMap a [(b,Freq)] -> S.HashMap a [(b, Freq)]
updateProb a c m = case (S.lookup a m) of
            Nothing -> S.insert a [(c,1)] m
            Just ts -> S.insert a (intoList c ts) m 
        where intoList c (x:xs) | c == fst x = second (+1) x : xs 
                    | otherwise = x : intoList c xs
              intoList c [] = [(c,1)]

Name: Anonymous 2013-08-09 11:24

>>28
type One = Char
type Two = (Char, Char)
type Three = (Char, Char, Char)
type Four = (Char, Char, Char, Char)
type Five = (Char, Char, Char, Char, Char)
type Six = (Char, Char, Char, Char, Char,Char)
type Seven = (Char,Char,Char,Char,Char,Char,Char)

Haskal is shit.

Name: Anonymous 2013-08-09 11:59

>>29

This was a choice of myself. I could easily represent the markov model as : [Char] -> [(Char, Prob)]. Then I didn't need those, but I found this more precise.

I would have liked a depended language, so I could say:

List N Char -> [(Char, Prob)] or something like that.

Name: Anonymous 2013-08-09 12:57

>>28
Did you test it in this thread: http://dis.4chan.org/read/prog/1376058919/1-

Name: Anonymous 2013-08-09 13:06

I wonder if a markov model could be adapted to the arrow interface.

Name: Anonymous 2013-08-09 13:08

>>31

Yes, I tested it in the god shit thread.

Name: Anonymous 2013-08-10 14:02

bump xD

Name: Anonymous 2013-08-22 15:17

yep

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