/dpt/ - Daily Programming Thread

[Daily Programming] Thread.

Previous: What are you working on, anonymous?

Other urls found in this thread:

youtube.com/watch?v=bl8jQ2wRh6k
boards.Sup
ghc.haskell.org/trac/ghc/wiki/MonadComprehensions.
interactivepython.org/runestone/static/pythonds/BasicDS/SimpleBalancedParentheses.html
twitter.com/SFWRedditGifs

first for user who deleted his new thread because this was made slightly earlier

>anonymous
First for C#

working on a new statistic theory

Fuck me.

>What are you working on, anonymous?
Nothing useful, pic related.

>Cape Verdian double dong

Give me something fun to do, /dpt/.

import Data.Function (on)
import Data.List (find)
import System.Environment (getArgs)
import Text.Printf (printf)
vowels = "aeiou"
vowelEq1 = on (==) $ filter $ flip elem vowels
vowelEq2 = on (==) $ map $ flip find vowels . (==)
main = do
[w1,w2] Bool -> IO ()
pr x y = printf "vowelEq%d returned %s\n" x $ show y
pr 1 $ vowelEq1 w1 w2
pr 2 $ vowelEq2 w1 w2

rewrite it with markov chains

>with markov chains
How would that work?

I guess I could take that output and regenerate more things from that, but I'm not sure what the end-goal is.

C question:

Why is signal-related stuff part of the C standard? It looks too platform-specific to be part of standard C to me. Does Windows support signals?

>Does Windows support signals?
hell no

c is only here to abstract the underlying hardware architecture, not the operating system (c was made to develop unix)

{-# LANGUAGE MonadComprehensions #-}
import Data.Function (on)

view :: [Char] -> [Maybe Char]

vowels = "aeiouAEIOU"
view x = [ x | x `elem` vowels ]
vowelsEq = (==) `on` map view

whoops

view :: Char -> Maybe Char

I suppose they were useful enough.
Even if the operating system isn't going to give you any signals, you can still signal yourself with raise().

Even then, it allows you to write standards conforming code, which uses signals (which is central to *nix, and C is heavily tied to *nix), and still have it work on other platforms, even if the signals will never actually get used.

Low order markov chains are a mistake.

And here's order 3 chains

some 9/10 twitter handles in here

youtube.com/watch?v=bl8jQ2wRh6k

I won't deny that they are useful, but it seems to me like the language standard was the wrong place for them. If your platform is POSIX-compliant, you already have them, and if it isn't, a standard C compiler targeting a non-compliant platform now has to "support" signals.

>Even if the operating system isn't going to give you any signals, you can still signal yourself with raise().

Fair enough, though I'm not sure whether this is preferable to alternative approaches that don't imply a particular platform.

>Even then, it allows you to write standards conforming code, which uses signals (which is central to *nix, and C is heavily tied to *nix), and still have it work on other platforms, even if the signals will never actually get used.

I'm not sure I follow. Why do signals need special treatment, when most other platform-specific code gets handled with #ifdefs and compilation flags?

To write fork bombs that won't stop at CTRL + C.
Ah well, what a prankster Kernighan was..

(unfortunately you can't catch SIGKILL, though)

let is_vowel = function
| 'a' | 'e' | 'u' | 'i' | 'o' -> true
| _ -> false
let purge_vowel x = if is_vowel x then x else ' '
let vowel_eq s1 s2 = String.map purge_vowel s1 = String.map purge_vowel s2
let () =
Printf.printf "vowel_eq = %B\n" @@ vowel_eq Sys.argv.(1) Sys.argv.(2)

>{-# LANGUAGE MonadComprehensions #-}
>view :: Char -> Maybe Char
>view x = [ x | x `elem` vowels ]
Curious!

Probably all the same reason why multithreading is in the c11 standard but it's been years now and still not implemented in glibc.

MonadComprehensions generalises list comprehensions to arbitrary monads

[ x | becomes pure x / return x
| x >= (\x -> ...) or
do { x action)

[ x | x `elem` vowels ]
specialised for Maybe, is

Just x (if x `elem` vowels)
Nothing (otherwise)

I suppose it might've been better to right it that way

view x | x `elem` vowels = Just x
| otherwise = Nothing


but the idea is that you remove the unnecessary structure (all non-vowels become

>but the idea is that you remove the unnecessary structure (all non-vowels become
become Nothing (aka ()) while the vowels retain their uniqueness (which vowel they are)

so you get rid of the details that you don't care about for the comparison by mapping them to Nothing

Signals themselves aren't actually too complicated (from a userland perspective, not a kernel one).
It's basically just a set of function pointers that are called, but it might happen at any time. It's not something that going to add a huge amount of unnecessary implementation details.
For an implementation that isn't going to have the OS giving it signals, raise() could be implemented as simply as
static int (*sigabrt_handler)(int) = default_handler;
static int (*sigfpe_handler)(int) = default_handler;
...

int raise(int sig)
{
switch(sig) {
case SIGABRT:
sigabrt_handler(sig);
break;
case SIGFPE:
sigfpe_handler(sig);
break;
...
default:
return 1;
}
return 0;
}

Do you guys know of any relevant resource to learn wordpress development? From a programmer's point of view.
Most of what i found (even full fledged courses) only deal with the approach of "you don't even have to code!", and that's just basic installation and a little css. What i'm looking for is more geared towards plugin and theme development.
[spoiler]don't judge gotta make some money on the side to buy vidya[/spoiler]

this isn't /wdg/

Sorry, had /dpg/ bookmarked for years, didn't know there was a /wdg/.

>/dpg/
No you haven't.

boards.Sup Forums.org/g/catalog#s=daily%20programming%20thread

That does look pretty simple... I figured they need some sort of OS support for context switching or whatever. Thanks for the help!

>That does look pretty simple
This is for a hypothetical, minimal C implementation.
For one that has "real" signals, and not ones just called by raise, it would be much more complicated.
Most of the heavy lifting would be done by the kernel, though.

Welp, now I feel I'm back to square one on the matter.

Yes, I've found the translation rules at ghc.haskell.org/trac/ghc/wiki/MonadComprehensions.
It becomes precisely
guard (x `elem` vowels) >>= return . \() -> x

where guard is Just () when the condition is true and >>= returns Nothing when the first argument is Nothing.
I wish I knew some haskell, so it would be monad comprehensions instead clumsy flip find vowels . (==).

>>= return .
is
>>

the real difference is just the method, you could easily have just done the function version, or if you weren't using Maybe's then this instead

view x | x `elem` vowels = x
| otherwise = '_'
vowelEq = (==) `on` map view

and this LITERALLY turns "hello" == "derpo" into "_e__o" == "_e__o"

on some focus

Am i retarded or is it actually hard to find some info on what keys are called in C such as A_KEY, LEFT_KEY etc.?

Yes, you are retarded. It depends entirely on the API.

can you not use the ascii table? or do you need it to respond to the serial port?

nevermind i am retarded, fuck me

>is
I don't see it. It's fmap rather.
>then this instead
Yeah, that's exactly what that ocaml program does (but using ' ').

I'm just curious. Do you study CS at a uni?

what was it?

found in api documentation like said

why do whites and chinese make computers hard? why don't they make them easy like the TV?

Oh, yeah it's fmap

And not exactly, I do a shitty programming related course at a former polytechnic, and most of what I learn has been on my own, not from the course. A lot of the stuff at the course you wouldn't even need to study for.

In other words, I ""study"" ""CS"" ""at"" ""uni""

They make their own lives hard. The rest just kind of follows. But really, it has a lot to do with not knowing who to trust. That's due to how much power they give their women. And that's only due to how much power other people give their women, what with wanting specifically white or asian women for god knows what reason.

It's also because of how it's taught and how the requirements are abstracted from a not so whole whole. A company doesn't need a computer guy. It needs a guy that can stack JS calls.

And there's million ways to stack JS calls but only the stupidest of them are willing to call it the best method. And usually those are the ones people believe. If non white or asian women were to ignore the white and asian women a lot better we could have some peace for a bit because there's be no pecking order to attempt to overcome.

I'm going to sleep.

In fact in this case it's a lot like >>

m >> e
m >>= const e
m >>= \_ -> e

since there's only one () and you don't really use it
guard (x `elem` vowels) *> Just x
(*> is applicative >>, Just is Maybe return)
was what I was thinking

What are the best languages for a DBA to know besides sql/oracle etc.?

English

I somehow expect all users of haskell to be related to writing small language for theoretical computer science. Just a stereotype.
Yeah, I understand your reasoning now. (I have to admit that I don't remember the definitions of Maybe's Monad and Applicative instances well.)
Just _m1 *> m2 = m2
Nothing *> _m2 = Nothing

>I somehow expect all users of haskell to be related to writing small language for theoretical computer science. Just a stereotype.
If it makes you feel any better, I WISH I could be writing small languages for theoretical computer science. Maybe when I've graduated.


> I don't remember the definitions of Maybe's Monad and Applicative instances well.
Maybe a is basically just Either () a, where Nothing = Left () and Just = Right.

It's also like [a] for a maximum of 1 element.

It basically just short circuits. Binding asserts that all the inputs are Just's, else it returns Nothing.

So

Just _ >> x = x
Nothing >> _ = Nothing

those features have long been available. Unless there's a high profile company using any Lisp, adoption rates will stay the same.
good on that company for using Lisp tho

Thanks for "Nothing", Haskell.

Who use D here?

Nth post for D.

whats the best coding language

D

JSON

gentoo
install it

>whats the best kitchen appliance

Fuck off you fucking cunt. I hate you. You are the worst fucking poster. Every damn time. It's because you use a shitty language and don't want anyone to be allowed to take you up on it.

Oven obviously.

I use multiple languages.

Some languages are great general-purpose languages, but saying a language is the "best" without some context in what is the "best" at is just silly.

Ovens suck at making ice, and I run a snow-cone stand.

Fuck ovens.

You should see how this works for programming languages, too.

I'm trying to figure out an algorithm to find islands in a 1D array, ie.

[0,0,1,0,0,0,0,1,1,1,0,1,0]

Would give me some list of structures/objects with an offset and size ie.

{{Size: 2, offset:0}, {Size: 4, offset:3}, {size:1, offset 10}, {size:1, offset:12}}

Right now my algorithm doesn't seem to be working 100% properly and I'm not sure why. Any ideas?

int start=0;
for(int i=0;i

>Ovens suck at making ice
I'd rather do without ice than cooked food you stupid retard. There's a lot more demand for hot food than snow cones too.

why is pixiv so shitty? and why do japanese use it?

in Haskell there is a function group that does most of the work

less filthy gaijins in pixiv thats why.

Post real life experiences when you're CS degree has helped you in any way.

heres mine:
never.

But there IS demand for snow cones. Some stands are quite profitable.

Also, what about storage of perishable foods? Life would be really difficult without refrigeration.

Both an oven and a fridge/freezer are necessary in a proper kitchen. Both have their place, and both do different things.

Now, an oven and a range both heat up food, and you can create an oven-like environment on a range (with the right tools), and you can create direct-heat in the oven, but they're both more efficient at different things.

I wouldn't want to boil water in an oven. Sure, I could, but it's more efficient to use the range top.

The problem is, metaphorically speaking, some anons are only using ovens, when other appliances could suit their needs in a better way. They just haven't purchased any other appliances (learned any other languages/frameworks/etc.).

CS grad here.

here you go, peasant.
This should get you on track:
interactivepython.org/runestone/static/pythonds/BasicDS/SimpleBalancedParentheses.html

good to know

yes

>Life would be really difficult without refrigeration.
we didn't always have this. We survived fine without, we are not dependent on this, so we can scrap this.

I don't really see how using a stack helps with that at all.

Any idea on an equivalent C++ function?

>But there IS demand for snow cones.
Less than for ovens.

Ovens objectively more useful, therefor are superior. QED.

This isn't an appliance thread you fucking ck, this is a fucking progrmaming thread

Get out

you should have went to a good uni.
feel sorry for you.

Wait I'm an idiot, I see how the stack does it. Thanks kind user.

everything is a subset of programming.

>missing the point this hard

I'll make this easy for you: if you only use one programming language, you're literally a pajeet-tier code monkey.

There is no single language that is the best at every task.

you're welcome, just doing my good deed for the day.
you kind of have to when you're as privileged as me.

>I'm a fucking retarded idiot
Thanks but we already knew
Thank you for derailing the fucking thread, AGAIN, and not answering the fucking question

>There is no single language that is the best at every task.
Nobody ever said that. Some langugaes are better than others.

I know lots of langugaes and use the best one for the given job.

all me.

#include
#include

int main(int, const char **)
{
std::vector map{
true,true,false,
true,true,true,
true,false,false,
false,true,false,
true,
};

bool inIsland = false;
unsigned size = 0, offset = 0;

for (int i = 0; i < map.size(); ++i) {
if (!map[i] && inIsland) {
inIsland = false;

std::fprintf(stdout, "Size: %u, Offset: %u\n", size, offset);

size = 1;
} else if (map[i]) {
if (!inIsland) {
inIsland = true;

size = 1;
offset = i;
} else {
++size;
}
}
}

if (inIsland) {
std::fprintf(stdout, "Size: %u, Offset: %u\n", size, offset);
}

return 0;
}

>what is C
>what is ASM
>what is python
You wasted your life learning all the useless meme languages. Just end yourself, faggot.

C is deprecated
ASM is deprecated
Python was never good in the first place

>python

you lost me there.

>not answering the fucking question
It's a bad question. There is no objective "best programming language".

The original post asked what the best language was.

That's implying that there is a language that is objectively the best, meaning, the best for everyone to use.

Different languages are "the best" for different people, depending on what they do.

What are you saying here? Are you claiming that one of these languages is the "best" language?

>ASM deprecated
I see. Math is deprecated too right?

we need a new numbering system. We've been doing math all wrong all this time.

Its time to start over from scratch.

My point is one language is enough if you know what you're doing.

>there is no single language that is the best
>responds with three languages almost as if to refute this

what

1) You are autistic and do not understand human communication
2) Some languages ARE better than others
3) Programming is not just the "different tools for different jobs" bullshit you faggots always fucking spout

If I get admitted to a college for the CS major and live on the campus, will my roommate be hot and will he do perverted things to me?

yes, call me.

You're absolutely wrong.

You can do pretty much everything in a great general-purpose language, but you can't do everything in the most computation-efficient and time-efficient way with one single language.

Java in a nutshell.

hammering a screw is ok if you know what you're doing, all you have to do is hammer the head sideways