/dpt/ - Daily Programming Thread

Previously What are you working on, Sup Forums?

Other urls found in this thread:

learnyouahaskell.com
jsfiddle.net/bxp32rrn/
jsfiddle.net/bxp32rrn/2/
twitter.com/NSFWRedditImage

I have a simple question, is web devevelopment, programming?

better OP

of course it is.

web dev is hell

You should group them together into an array of structs rather than have 2 arrays. The code is faster and less error prone.
struct Operation{
const std::string name;
const std::function func;
Operation(std::string name, std::function func) : name{name}, func{func} {}
};
const Operation ops[3] { {" + ", std::plus{}}, {" - ", std::minus{}}, {" * ", std::multiplies{}}};

std::cout

>Operation(std::string name, std::function func)

Enjoy your copies.

doing more haskell exercises
-- bintrees
data BinaryTree a =
Leaf
| Node (BinaryTree a) a (BinaryTree a)
deriving (Eq, Ord, Show)


unfoldBT' :: (a -> Maybe (a, b, a)) -> Maybe (a, b, a) -> BinaryTree b
unfoldBT' f Nothing = Leaf
unfoldBT' f (Just(a, b, c)) = Node (unfoldBT' f (f a)) b (unfoldBT' f (f c))

unfoldBT :: (a -> Maybe (a, b, a)) -> a -> BinaryTree b
unfoldBT f x = unfoldBT' f (f x)

treeBuild :: Integer -> BinaryTree Integer
treeBuild n =
unfoldBT (\b -> if ( b >= n) then Nothing else Just ((b + 1), b, (b + 1))) 0

That's what is geometry to mathematics.

please explain how that anology makes any sense, because without thinking about it much I realise how retarded it is

>Operation(std::string name, std::function func) : name{std::move(name)}, func{std::move(func)} {}

Happy?

>unfoldBT
here's an exercise
define a monadic version
Monad m => (a -> m (Maybe (a, b, a))) -> a -> m (BinaryTree b)
(alternatively just do it for m ~ IO)
then use the "directory" library (you should already have it installed) to build a tree of files/folders

std::function still makes me uneasy

Better than the alternatives.

How else are you going to express functions in a simple and generic way? Function pointers can't take lambdas or function-like objects, and going full template mode just leads to needlessly complicated metaprogramming hacks to ensure that you're being passed a function.

by using Haskell instead

Short string and short function optimizations makes copies simple.

if only C++ had traits

or just UDAs

function_ref

The standard actually guarantees that a std::function won't heap allocate for a bare function pointer (possibly a PMF too, the wording is vague)

...

Who is this faggot that's trying to change >>>/dpt/?

>What are you working on, Sup Forums?
Trying to move memory efficiently in a CUDA kernel.

You don't have to use lispaigirl all the time user.
But still, non-anime OPs are unacceptable.

-- | Generates `k` random integers less than `n` without duplicates.
--
generateIntegers :: Int -> Int -> [Int]
generateIntegers k n
| k

Geometry is for plebs

"""random"""

it's entirely possible for a true random number generator to produce the exact sequence of natural numbers

please stop you're making it worse. That damage control is just as, if not more retarded than your previous post.

>You don't have to use lispaigirl all the time user.
Of course not It was just posted as an example image.
>But still, non-anime OPs are unacceptable.
I wholeheartedly agree.

>getting this buttblasted on /dpt/
take a walk outside bud

>take a walk outside bud
You don't understand this place do you.

> Interested in what any preteen could do with a straightedge and a compass

Pleb

Prelude> :t Left
Left :: a -> Either a b
Prelude> :t Right
Right :: b -> Either a b

Proposal: Adopt the Old English ȝ and rename Right to Riȝt. This makes both constructors have the same length and leads to good alignment properties.

this

why does this fucking book have 500 chapters on fmap??
what's the fucking point

Which book? Try wikibook

lisp

learnyouahaskell.com

A course I'm on uses examples from this book as bases for exercises.

I guess it's because the author is a Category theory autist. LYAH is alright though.

English is not my 1st language.
If printf is an output function, scanf is an input function, then what is a function that sorts through an array? Or that simply changes data in general.
Google translate gives me "processing function" but I'm not sure if that's right.

T R A N S F O R M A T I O N

>then what is a function that sorts through an array?
just a function.
processing function isn't wrong, but sounds pretty robotic/german to me.

Topology is geometry too, right?

Right. But everything in math is geometry.

I don't think there's a particular word for it
If you want to keep up with the input output theme you could use "throughput"

Vague linkage is the root of all evil.

C++ is the root of most evil.

Porting my game engine from Rust to Nim.

A sorting function, of course.

C++ is simply evil, which makes C the root of evil.

Which makes assembler the devil

Javascript is love, Javascript is live.

function fizzbuzz(n) {
return (
{false: '', true: 'Fizz'}[i % 3 === 0] +
{false: '', true: 'Buzz'}[i % 5 === 0] || n.toString()
);
}


Can't do something this elegant in any other language.

>this is "elegant" on /wdg/

This is nasty.

>{false: '', true: 'Fizz'}[i % 3 === 0]

brilliant. athough it's supposed to be 'n', not 'i'

Werks on my machine :^)
jsfiddle.net/bxp32rrn/

Remember, Sup Forums, this is what a JavaScript "developer" looks like.

jsfiddle.net/bxp32rrn/2/
FTFY, you fucking idiot. Just kill your fucking self.

I try to love this train wreck so hard, and it fights back with double the force

Sup Forums

People keep contacting me for my VBA and VB6 experience. How much should I charge? I'm thinking 80 an hour because jesus fucking christ there is no such thing as good VBA or VB6 code when people are hiring for it

>can't do something this elegant in any other language
>javascript code monkeys believe this

for((i=1;i!=101;i++)) do
str=""
if [ $((i%3)) -eq "0" ] ; then str=$str"fizz" ; fi
if [ $((i%5)) -eq "0" ] ; then str=$str"buzz" ; fi
if [ -z $str ] ; then str=$i ; fi
echo $str
done ;

Disgusting.

I wonder who could be behind (((this)))

what about decltype((x + x))

For anyone that's interested, the book is 1491908432.

>one of the most elemental and beautiful branches of maths
vs
>one of the most soul crushing, repetitive poo flinging branches of programming
what an amazing analogy

you gotta love c++ for small things like this

Where's your inline array with entries for true and false?
All you're doing is concating a string with some if statements.
You even have to explicitly check for the string being empty.

Of we're in the business of absolutely disgusting JS solutions to fizzbuzz, at least do it right:
function fizzbuzz(n) {
return ((n % 3 === 0 && "fizz") +
(n % 5 === 0 && "buzz") || n).toString().replace("false", "");
}

Jai when?

jai is vaporware

even if it never releases it will live on in my heart

The samefag is strong itt.

>Javascript is love, Javascript is live.
Javascript is suffering.

...

post feet jon

two out of three ain't bad

>goodlangs
Scheme, CL, Haskell, Idris, Agda, PureScript, Rust

>shitlangs
Java, C#, Python, Ruby, PHP, JavaScript, Go, C, C++

He's doing a closed beta to friends and people soon, and i think he said something about an open beta sometime this summer.
Jai is trash though.
It's a simpler sepples with a side-step in syntax quality.

I'm already well-versed enough in C++ to understand why I hate it but also why I can't move away from it, so I don't care if Jai is trash as long as it's less braindamaged than C++.

Does it feature OOP?

Try Rust, I think you'll be pleasantly surprised.

Why do you hate C++?

C++ attempts all things, but is master of none

>Idris

can you read?

t. brainlet

>Try Rust, I think you'll be pleasantly surprised.
It doesn't sound like he cares so much about his C++ job security, so what is he going to be pleasantly surprised about?

Hey /dpt/ can you rate my heap sort?
template
static void flip (Cont &v, Idx i, Idx j) {
auto tmp (v[i]);
v[i] = v[j];
v[j] = tmp;
}

template
static Idx parent (Idx i) {
return (i - 1) / 2;
}

template
static Idx left (Idx i) {
return 2 * i + 1;
}

template
static Idx right (Idx i) {
return 2 * i + 2;
}

template

static void sort (Cont &v) {
auto sz (v.size ());
for (decltype (sz) i (0); i < sz; i++) {
auto j (i);
auto pj (parent (j));
while (j > 0 && cmp (v[pj], v[j]) < 0) {
flip (v, j, pj);
j = pj;
pj = parent (j);
}
}
for (decltype (sz) i (0); i < sz; i++) {
auto lim (sz - i - 1);
flip (v, 0, lim);
decltype (sz) j (0);
auto lj (left (j));
auto rj (right (j));
decltype (sz) cj;
beginloop:
if (lj >= lim) goto endloop;
if (rj >= lim) goto endleft;
cj = cmp (v[lj], v[rj]) < 0 ? rj : lj;
if (cmp (v[j], v[cj]) >= 0) goto endloop;
flip (v, j, cj);
j = cj;
lj = left (j);
rj = right (j);
goto beginloop;
endleft:
if (cmp (v[j], v[lj]) < 0) {
flip (v, j, lj);
}
endloop:
;
}
}

Is the array/dictionary structures in Python similar enough to JSON to receive stringified JSON without having to worry about any conflict?
Is there something I should be aware?

What is there to like about C++?

Rust is probably a net positive for humanity at the current point in time but I can't use it. I might be able to use it in the future when it matures but right now it's basically below even Java in the list how much I want to program in different languages.

C++ is almost entirely a mistake. Random example: nowhere is it specified how encoding comes into play with interacting with the OS, except for the utf-16 and utf-32 C++17 filesystem access stuff. There is no portable way to even KNOW what the encoding for the filename of fopen is, even if the target platform categorically uses a particular encoding for filenames (e.g. Windows using a broken version of UTF-16).

Gross.

What a horrific soup of syntax... C++ should be banned.

Faggot!

>hates C++
>thinks a false-flag programming language designed to be as obnoxious as possible and drive people back to C++ is a "net positive"

>baiting this hard