/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: anime guido.jpg (408x612, 138K)

Other urls found in this thread:

stackoverflow.com/questions/3870088/a-monad-is-just-a-monoid-in-the-category-of-endofunctors-whats-the-problem
youtube.com/watch?v=vYofpdo0PXk
twitter.com/SFWRedditImages

It's Python's new mascot!

And why would I want them?

Attached: 1545881927466.jpg (716x768, 79K)

First for Haskell

JavaScript rocks!

Attached: js-rocks.png (1000x494, 368K)

Who posts this stuff and why?

What makes you think the world cares about you

I wrote a script to import EverQuest zones into Blender and from there I imported it into UE4. Now that's some worthwhile programming right there, I tell you what.

Attached: unreal_everquest.png (1920x1080, 2.56M)

What makes you think I care about the world?

stop seething, it's embarrassing

register void *sp asm("sp");
printf(%p\n, sp);

import math

def cool_func():
print(math.factorial(10))

vs
from math import factorial

def cool_func():
print(factorial(10))

vs

def cool_func():
from math import factorial
print(factorial(10))

A monad is a data structure that accepts logic (eg lambdas) to transform the value contained within.

But what does it print?

Reasons to have a unicode library: correctly handle case in any language
Languages that matter: English and Japanese
Simplest, sanest, and most efficient way to handle case in English: ASCII
Japanese: has no case to begin with
See? No unicode library needed.

So I'm building a user thread library for my OS. I have to create mutex functions also. I always understood the need for mutexes as, for example, if two threads are running at the same time and thread 1 reads var x (say, x = 1) from memory puts it into a register and then thread two reads var x (x still = 1) from memory and puts it in a register and then both increase it by 1 and write it back to memory, the value of x will be 2 instead of 3.

But now that I'm building this library, I am realizing that user threads don't actually run at the same time, so that can't happen. So what is the need for mutexes with user threads? Is it for the case when thread 1 reads x (x=1) into a register and then there is a context switch and now thread 2 reads (x=1) increases it to two and then when thread 1 swaps back in it still has 1 in its register and increases it to 2 when it should be 3?

I guess that makes sense, but what if thread 2 increases x 9 times to 10? Then when thread 1 swaps in it still has 1 in its register and writes 2 back to memory. Then when thread 2 comes back in the value of x is now 2 instead of 10?! Can that happen because it doesn't seem like it ever does when you don't use a mutex

value in sp register

Donald Trump is a racist.

>Reasons to have a unicode library: correctly handle case in any language

Attached: 0cbpdjii3pa11.png (645x729, 105K)

Last. Fuck PEP8.

>So I'm building a user thread library for my OS
*OS class

You can't prove me wrong.

reasons to use unicode: supporting languages that aren't English

Second if you only use factorial. Else first.

In other words, there are no reasons to use Unicode.

Suppose a thread needs to operate on several different variables. The state among these several variables must remain coherent. Therefore, it is very important that only one thread mutates them at once.

Japanese isn't English

You don't need a unicode library for that if you're not changing case or don't give a shit about the number of characters (number of bytes is all that matters).
Unicode text works fine on it's own without explicit support.

The Japs have Shift-JIS or whatever.

Japanese doesn't have case and thus has no need for unicode support.

Here's a reason to support unicode: $$$

you don't need a unicode library for anything, just write it yourself lol

i asked this in a previous thread but it was dying. i am creating a irc bot that will execute certain alexa commands when certain inputs are typed within a irc server. does anybody know how to make alexa do commands based not on voice but on direct execution? im sorry if i sound a little stupid but ive never worked with alexa/echo.

unicode support has nothing to do with case you insufferable autist

there could also be something with caching and not propagating changes
and threads can run at the same time if you have multi-core
>never happens
have you tried it?

You don't need unicode support at all.

imports at the top are to satisfy C programmer autism, there is no benefit.

It does, because case is the only reason you'd need a unicode library.
If that's not true, then why have I encountered zero problems handling Japanese strings with no unicode support? Oh that's right, because you don't actually need unicode for 99% of string operations.

I would google 'alexa api'

But I just #include everything, it makes for a more predictable build.

>why have I encountered zero problems handling Japanese strings with no unicode support?
because you're using an outdated character encoding

To create an apple pie from scratch, you must first #include the universe.

>predictable build
Is this a joke?

False, it's unicode encoded Japanese, and I didn't need any unicode library for it. 99% of times, you don't need a unicode library to handle unicode text. It just works on it's own.

so you are using unicode, you just aren't using a library
what's your point exactly

That's my point. You don't need a unicode library.

No. If you make a unity build (no linking at all), then strip it, you only depend on the compiler version.

Unity builds are idiotic. Use LTO.

>LTO
I don't use linking, and it's just more things that can go wrong. No thank you.

>I don't use linking
You can't escape the linker you baka.

>I don't use linking
the absolute state

I compile with -ffreestanding and I don't include any libraries.
Do you want fragile build systems?
I can compile on anything that has a C compiler, regardless of whether it has other packages installed or not, and get the result I want.

>t. mathlet

>I compile with -ffreestanding and I don't include any libraries.
That's nice and all but your program still goes through the linker, lol.

Yeah, but I don't have to deal with "libasidj.so.95 not found" or libraries.

you can use LTO even if you're just linking your own object files, fren

Just realized I fucked up.

There is no/little cost overhead when using local imports. You instantly know where a function/class implementation came from because the import is nearby. You can move or modify code and you don't have missing imports or extra imports laying around at the top of files. It's telling that python static analyzers build in a feature that analyzes if you are redundantly importing things which would be less of an issue if you just imported them where you used them, then you can get rid of them when the implementation of something changes. Also, you pollute the module level scope less. I always do imports at the most local level possible.

I only have one object file per executable. No need to overcomplicate things.

>fren
Can we add this to the banned words list?

Giving an easily understandable explanation to something constitutes as being a mathlet?
The absolute state of (dys)functional pajeets.

Is it a preemptive scheduler?
If it is, how do you deal with a non-atomic RMW operation?

Mathematics is about hard to understand explanations. You should know this already.

Is it possible to create a facebook messenger bot that will connect with the group chat that I have with my friends and act like those discord/twitch bots where you type !roll and it rolls or !phrase and say a phrase ? The final goal will be to call something like !photo and it sends a photo from a collection of photos I have chosen.

stackoverflow.com/questions/3870088/a-monad-is-just-a-monoid-in-the-category-of-endofunctors-whats-the-problem

Rust
>requires you to use their dumb package manager (step aside emacs, now languages are operating systems) to be productive
>muh "safety" (restrictions)
>takes half a second to a whole second to compile a "hello world" program
>IO is retarded
>STD::LIB::IO::BBQ:::::: FUCK I LOVE COLONS
>pritnln!
>!

what

Attached: 1542523277131.png (850x1200, 938K)

big fucking honkers

maybe in small world

#include
const double PI = 3.14;

int main(void)
{
double *ptr;

ptr = PI;
*ptr = 5;
std::cout

You're right
See if you can put these to use

Attached: angewomon2.png (1447x2046, 2.59M)

fuck i meant to type &PI
const.cpp: In function ‘int main()’:
const.cpp:8:8: error: invalid conversion from ‘const double*’ to ‘double*’ [-fpermissive]
ptr = Π
^~~

C would give you warning
C++ also lets you do that but doesn't autocast pointers

>A monad is a data structure
Monad is a typeclass. There's a monad instance for:
((->) r)

>that accepts logic (eg lambdas) to transform the value contained within.
Does this intList 'accept logic'?
intList :: [Int]

this is not cute

do that in C and you would get undefined behavior

>Monad is a type class
Haskell doesn't have a monopoly on monads.

wrong

Attached: TypeMan.jpg (2136x3216, 325K)

Trying to make your point using Haskell defeats the point, because it has language level support for making them undistinguishable from regular data structures.
dplp::Promise promise = dplp::makeFulfilledPromise(5)
.then([](int value) -> int {
// do something with the value
return value;
});
The above here satisfies the requirements for a monad and it illustrates my explanation well enough.

>it has language level support
if you mean ghc/haskell then using rebindable syntax, do notation basically just lets you pass lambdas easier

You're face isn't cute

Making the association between monad data structure is a mistake.
I just gave an example of that, how a normal function is also a monad.

wrong

present evidence

Attached: 73252074_p0.jpg (1736x2456, 2.63M)

cringe

I'll accept it

pretty neat

can you guys help me out
my uni professor is asking us to program a time machine in a language of our choosing as long as it's a time machine

what about the
(a -> f b) -> f a -> f b
signature then?
The promise example has the same signature.

No. About how a function
a -> b

is a monad:
instance Monad ((->) r) where
f >>= k = \ r -> k (f r) r

And so:
foo = (+1) >>= return

God, I fucking love this haskell tiddie monster

I love fucking the haskell tiddie monster

a better example, showing the sequence of the function monad:
f = (+1) >>= (,)
f 4 -- (5,4)

The problem with these explanations is the refusal to step outside Haskell to show what you mean.
Monad f = dplp::Promise
a = int
b = int

f a = dplp::Promise
f b = dplp::Promise

dplp::makeFulfilledPromise(5)
-> dplp::Promise
= f a

// in the context of the .then method the result will be wrapped
// ie b returns as f b
[](int value) -> int {
return value;
}
(a -> f b)

whats a promise?

In haskell, how can I add costCentres for external functions for profiling?
I want to know how much time I spend packing/unpacking my Strings and decide which one I should use for my datatype.

A monoid in the category of endofunctors

There's no "wrapping" in the function monad, just application.
That's why I use it as a counter example.

crazy guy tries to use linux on a Mini PC: fails

youtube.com/watch?v=vYofpdo0PXk

A Promise is a data structure that may or may not hold a value and allows you to chain operations on the data if it exists.