Post Code
1
Name:
Anonymous
2011-03-04 21:33
One recurring complaint is that nobody talks about code on /prog/. So everyone write go and write some code, any code, that does something, anything, and post it. A small explanation wouldn't go amiss either.
41
Name:
Anonymous
2011-03-06 2:00
Some shitty code I've written recently:
Python:
fragment = "(%s)" % reduce(lambda x, y: x + y, ["%s, " % user for user in self.channels[channel].userdict.keys()])[0:-2] # SHOULD I FEEL BAD?
PHP:
$_ = array_map(
function ($info) { preg_match("/\"symbol\": \"(\w+)\".+\"close\": \"([0-9.]+)\"/", $info, $m); return $m; },
array_filter(
$_,
function ($mkt) use ($ooh) {
return array_reduce(array_map(
function ($sym) use ($mkt) {
return strpos($mkt, $sym) !== false;
},
$ooh),
function ($a, $b) { return $a or $b; });}));
42
Name:
Anonymous
2011-03-06 6:01
postcode? 3000 LEUVEN YO
43
Name:
Anonymous
2011-03-06 6:59
>>41
ONE WORD: THE FORCED ONE-LINERS TO AVOID THE FORCED INDENTATION OF CODE. THREAD OVER
44
Name:
Anonymous
2011-03-06 9:23
Tells you what day of the week you were born on and predicts the day of the week for future days
def zeller(B,month,year):
if month>2:
A=month-2
elif month==1:
A=11
elif month==2:
A=12
else:
print 'd'
#B=input("Day?\n")
#year=raw_input("Year of birth?\n")
C=int(year[2:4])
D=int(year[0:2])
W=(13*A -1)/5
X=C/4
Y=D/4
Z=W+X+Y+B+C - 2*D
R=Z%7
week=['Sunday',"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
for day in week:
r=week[R]
print r
45
Name:
Anonymous
2011-03-06 9:37
making me spend some extra 10-20 seconds starting up Emacs
Erm, you know you can byte compile elisp, and run emacs as a server, don't you?
--
;; http://www.flickr.com/photos/silent11/3377490479/
(defun donuts ()
(interactive)
(print "Mmmm, donuts."))
46
Name:
Anonymous
2011-03-06 9:41
Monadic parser combinators in PHP.
Random samples:
function sepEndBy1($p, $sep) {
return function ($st) use ($p, $sep) {
$st = $p($st);
if ($st->error === true) {
return $st;
}
$ret = $st->value;
$x = _or( bind( $sep
, __(sepEndBy($p, $sep))
, function ($xs) use ($ret) {
array_unshift($xs, $ret);
return _return($xs);
})
, _return(array($ret)));
return $x($st);
};
}
function sepEndBy($p, $sep) {
return _or(sepEndBy1($p, $sep), _return(array()));
}
// From a lisp parser using it: (the above is in the namespace P)
function parseList()
{
return P\bind( P\char('(')
, P\__(P\many(P\space()))
, function () { return P\sepEndBy( parseExpr()
, P\many1(P\space())
);
}
, function ($list) {
return P\bind( P\_or( P\_try( P\_bind( P\char('.')
, P\many(P\space())
, parseExpr()
)
, "dotted list")
, P\_return(new Nil))
, function ($last) use ($list) {
return P\_bind( P\many(P\space())
, P\char(')')
, P\_return(array_to_list($list,
$last)));
}
);
}
);
}
Basically a parsec clone. It's very slow, unfortunately, and has to be replaced.
47
Name:
Anonymous
2011-03-06 12:03
Monadic parser combinators in PHP.
It's like eating some ice cream will being anally raped.
48
Name:
Anonymous
2011-03-06 12:59
>>47
How the fuck is coding in PHP anything like eating ice cream?
49
Name:
Anonymous
2011-03-06 13:16
>>48
PHP is the anal rape
50
Name:
Anonymous
2011-03-06 14:01
>>49
Then what's the ice cream?
51
Name:
Anonymous
2011-03-06 14:19
>>50
the creampie afterwards
52
Name:
Anonymous
2011-03-06 14:29
#include <iostream>
using namespace std;
void ohgodwhy(){
cout << "\a" << endl;
ohgodwhy()
}
int main(){
ohgodwhy()
}
53
Name:
Anonyous
2011-03-06 14:34
Is this code.
54
Name:
Anonymous
2011-03-06 15:49
[code][code][code][code][/code] [/code] [/code] [/code]
55
Name:
Anonymous
2011-03-06 15:50
>>52
Too bad C++ doesn't do TCO
and it's not Turing-complete .
56
Name:
Anonymous
2011-03-06 16:22
cock sucking lisp faggots with their turing completeness
what do you think your shitty toy language interpreters are written in? thats right, C/C++. I hate every one of you. hit me with your best shot, I know i'm pretty much perfect. i got straight A's and a banging hot girlfriend. etc.
57
Name:
Anonymous
2011-03-06 16:40
58
Name:
Anonymous
2011-03-06 16:48
THE ELEMENTARY CELLULAR AUTOMATA!!!
import Control.Monad
import Data.List
import Data.Maybe
import System.Environment
type Rule = (Bool, Bool, Bool) -> Bool
makeRule :: Int -> Rule
makeRule n = \(x,y,z) -> rule !! (fromJust $ findIndex (==[x,y,z]) states)
where states = replicateM 3 [True,False]
rule = replicateM 8 [False,True] !! n
apply :: Rule -> [Bool] -> [Bool]
apply rule xs = apply' rule (False:xs)
where apply' rule (x:y:z:zs) = rule (x,y,z) : apply' rule (y:z:zs)
apply' rule (x:y:[]) = rule (x,y,False) : []
eval :: Rule -> [Bool] -> [[Bool]]
eval rule xs = iterate (apply rule) xs
draw :: [[Bool]] -> IO ()
draw xs = mapM_ putStrLn $ convert xs
where convert = map $ map (\x -> if x then '#' else ' ')
seed :: Int -> [Bool]
seed width = take l (repeat False) ++ [True] ++ take r (repeat False)
where l = (div (width + 1) 2) - 1
r = div width 2
main :: IO ()
main = do
[num,width,height] <- getArgs
let n = read num :: Int
w = read width :: Int
h = read height :: Int
in draw $ take h $ eval (makeRule n) (seed w)
59
Name:
Anonymous
2011-03-06 16:51
>>56
You can't compile SBCL without a Lisp interpreter/compiler, so no.
60
Name:
Anonymous
2011-03-06 20:34
>>59
This thread has been closed and replaced with the following thread:
Subject: Compiling SBCL with a LISP interpreter/compiler.
Name:
Email:
It doesn't work.
61
Name:
Anonymous
2011-03-08 6:43
/*C Program to Propose a girl*/
#include<girls.h>
#include<propose.h>
#define Cute beautiful_lady
main()
{
goto college;
scanf(“100%”,&ladies);
if(lady ==Cute)
line++;
while( !reply )
{
printf(“I Love U”);
scanf(“100%”,&reply);
}
if(reply == “ABUSES”)
main(); /* go back and repeat the process */
else if(reply == “SHOES “)
exit(1);
else if(reply == “I Love U”)
{lover =Cute ;
love = (heart*)malloc(sizeof(lover));
}
goto restaurant;
restaurant:{
food++;
smile++;
pay->money = lover->money;
return(college);
}
if(time==2.30)
goto cinema;
cinema:{
watch++;
if(intermission){
coke++;
Popecorn++;}
}if(time ==6.00)
goto park;
park:{
for(time=6.30;time<= 8.30;time+=0.001)
kiss = kiss+1;
}free(lover);
return(home);
}
62
Name:
Anonymous
2011-03-08 6:51
63
Name:
VIPPER
2011-03-08 7:14
>>61
What the hell is this shit? Do you have autism? Do you not know how to indent code?
64
Name:
Anonymous
2011-03-08 7:29
>>63
THE INDENTATION WILL NEVER BE FORCED ON ME!
65
Name:
Anonymous
2011-03-08 7:43
>>64
I'd like to support this brave gentleman with all my might.
66
Name:
Anonymous
2011-03-08 8:40
67
Name:
Anonymous
2011-03-08 8:56
>>66
THE INDENTATION IS STRONG IN THIS ONE!
68
Name:
Anonymous
2011-03-08 9:04
USE THE TAB, GYUUDON
69
Name:
Anonymous
2011-03-08 9:14
>>67
fuck off and die faggot
70
Name:
Anonyme
2011-03-08 10:49
UN MOT. L'INDENTATION FORCÉE DU CODE. FIL TERMINÉ.
71
Name:
Anonymous
2011-03-08 10:56
>>40
The rational explained in those links is super convincing
1) parentheses grow lonely if their closing brackets are all kept separated and segregated
2) readers of Lisp programs do not match parentheses, but use indentation
3) reduce the number of lines of code
4) fit more lines on a page or screen
You CLISPERS should stop wasting all your time trying to force everyone to use your "one true way" and just make it a language requirement (i.e.
ONE WORD )
Meanwhile everyone else will be using newLISP to actually get things done.
72
Name:
Anonymous
2011-03-08 11:02
>>71
You CLISPESR
I don't use CLISP.
should stop wasting all your time trying to force everyone to use your "one true way" and just make it a language requirement (i.e. ONE WORD)
And lose all the advantages of the parens? No.
73
Name:
Anonymous
2011-03-08 11:04
cons :: a -> b -> (a -> b -> c) -> c
cons x y = (\f -> f x y)
car :: ((a -> b -> a) -> a) -> a
car f = f (\x y -> x)
cdr :: ((a -> b -> b) -> b) -> b
cdr f = f (\x y -> y)
74
Name:
Anonymous
2011-03-08 11:34
>>71
Maybe if there weren't so many damn parentheses, you wouldn't have a screen estate problem in the first place.
75
Name:
Anonymous
2011-03-08 11:38
using newLISP to actually get things done
AHAHAHAHAHAHAHAHAAHAHAHAHAHAHAHAHAHAHAHA
76
Name:
Anonymous
2011-03-08 12:26
using LISP to actually get things done
AHAHAHAHAHAHAHAHAHAHAHAHA
77
Name:
Anonymous
2011-03-08 12:29
>>71
Meanwhile everyone else will be using newLISP to actually get things done.
You mean that one language with
dynamic scoping ? And with
FORCED COPY BY VALUE , except if you use contexts, which are
globally scoped and never destroyed ?
The language where you can't solve Exercise 3.1 of SICP?
Well, ain't that some shit.
Show me one thing you got done with newLISP, apart from your mom.
78
Name:
Anonymous
2011-03-08 13:35
79
Name:
Anonymous
2011-03-08 14:36
>>78
fuck you faggot lisper
80
Name:
Anonymous
2011-03-08 14:48
Newer Posts