/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: get.gif (369x480, 452K)

Other urls found in this thread:

youtube.com/watch?v=nDm-QDEXGEA
wrox.com/WileyCDA/WroxTitle/productCd-1118833031.html
twitter.com/SFWRedditImages

Can someone explain me why, in the next piece of code, the call inside test also sees the function in NA?

namespace NB {
class D {};
}

namespace NA {
class C {};
void g(C c = C(), NB::D d = NB::D());
}

namespace NB {
void g(NA::C c = NA::C(), D d = D());

void test(double d, NA::C c) {
g(c);
}
}

apply > applicatives >>>>>>>>>>>>>> monads
discuss

Clojure > Lisp
youtube.com/watch?v=nDm-QDEXGEA

I see that there are many API written for discord, like js, java, c3 etc... But what language are they targeting, or wrapping? I can't find calls to some internal discord library or anything going through various API code.

what makes you think it does? there's a g right there with a default param for the second

nigger

prog.cpp: In function ‘void NB::test(double, NA::C)’:
prog.cpp:16:12: error: call of overloaded ‘g(NA::C&)’ is ambiguous
g(c);
^
prog.cpp:13:10: note: candidate: void NB::g(NA::C, NB::D)
void g(NA::C c = NA::C(), D d = D());
^
prog.cpp:9:10: note: candidate: void NA::g(NA::C, NB::D)
void g(C c = C(), NB::D d = NB::D());
^

needs more arrows

Anone, will you please show me how functors, applicatives and monads look like in JavaScript?

Attached: d2c1a6d89a12f3c3b4bb923ece977c63.jpg (600x900, 82K)

I notice each 'g' has the same type signature. What happens if their type signatures are different?

ADL
just prefix your functions calls with the namespace they belong to explicitly

programing is soul crushing

Because of this Yet I can't understand why. Is it because it's defined in the global namespace and the call to g can only be resolved by looking every g in every namespace?

Nothing changes, both are candidates.

Where do you buy these?

Watching the webm whilst trying to read the post, I misread "pastebin" for "protein".

wrox.com/WileyCDA/WroxTitle/productCd-1118833031.html
At least that's what I used to learn.

when it feels that way, it usually means you're doing it wrong

it's time to take a step back and re-think your ways

arrows suck

But Monads have been a subclass of Applicatives since the Functor-Applicative-Monad Proposal

/**
* Functor
* map :: (i -> o) -> e(i) -> e(o)
*/
// e = Array
// map :: (i -> o) -> Array(i) -> Array(o)
const map = (mapper, data) => data.map(mapper);

// mapper :: int -> string
const mapper = int => String(int);

// i = int
// o = string
// (int -> string) -> Array(int) -> Array(string)
map(mapper, [1, 2, 3]); // -> ["1", "2", "3"]

// Structure preserving map

/**
* Applicative
* apply :: e(i -> o) -> e(i) -> e(o)
*/
// e = Array
// join :: Array(Array(i)) -> Array(i)
const join = xs => xs.flat();

// pure :: x -> Array(x)
const pure = x => [x];

// apply :: Array(i -> o) -> Array(i) -> Array(o)
const apply = (functions, data) => join(map(f => map(x => f(x), data), functions));

// Array(int -> string)
const functions = [x => String(x), x => String(x + 1)];

// i = int
// o = string
// Array(int -> string) -> Array(int) -> Array(string)
apply(functions, [1, 2, 3]); // -> ["1", "2", "3", "2", "3", "4"]

// Apply is not always structure preserving (grows)

/**
* Monad
* bind :: (i -> e(o)) -> e(i) -> e(o)
*/
// e = Array
// bind :: (i -> Array(o)) -> Array(i) -> Array(o)
const bind = (mapper, data) => join(map(mapper, data));

// int -> Array(string)
const mapper = x => x === 2 ? Array(3).fill(String(x)) : pure(String(x));

// i = int
// o = string
// (int -> Array(string)) -> Array(int) -> Array(string)
bind(mapper, [1, 2, 3]); // -> ["1", "2", "2", "2", "3"]

// Also called flatmap
// [1, 2, 3].flatMap(mapper) would have returned the same

How do i make my C or C++ programs portable/cross-platform so they run on every OS if they dont require any OS specific features?

only use stdc++
google "c++ if running on windows"
do that for using windows.h for example

That's impossibru, "OS specific features" are unavoidable.

just write your library and go with standard definition of type sizes, like int is at least 16 bits.
Don't use standard library if you need to support platforms that don't implement standard library, but then again there's likely not compiler for those platforms?

No, they aren't.

Would it be possible to extend C compiler with namespace support in a way that doesn't require name mangling?
I think if you would use some character as namespace separator in the ABI that is not valid character in C for function/variable name like comma or dot. Do the character limitations also exists in ABI naming?

joke's on you, my soul had already been completely crushed before I started learning it

Here's an example of the Either Monad in TypeScript.

const Right = (x: any) => ({
x,
map: (f: any) => Right(f(x)),
fold: (_: any, g: any) => g(x),
chain: (f: any) => f(x),
ap: (o: any) => x(o.x),
inspect: () => `Right(${x})`
})

const Left = (x: any) => ({
x,
map: (_: any) => Left(x),
fold: (f: any, _: any) => f(x),
chain: (_: any) => Left(x),
ap: (_: any) => Left(x),
inspect: () => `Left(${x})`
})

Not at all a complete or perfect implementation but should give you some rough idea.

I don't understand how this is supposed to work. Is that a lambda that returns a associative list?

Also, can we all agree that 'foldable' is the worst thing about Haskell? Catamorphisms got robbed

How do you get nice syntax highlighting?

use c++

Nvm

Foldable is good, as is Foldable1

>dude just use jquery
you are worse than fucking webdev.

My previous code had some errors. I wrote it very quickly. Please look at my newest post for an accurate model

Any rustfags around? How do I write a macro that accepts n u8s, and produces an array where the first n elements are the arguments and the last is their sum AND-ed with 0xff? I want this to be done at compile time. Is this possible?

then why does valgrind give me over 10 million errors for my hello world program, explain that!

Something fucked up. Here's the original post:
Any rustfags around? How do I write a macro that accepts n u8s, and produces an array where the first n elements are the arguments and the last is their sum AND-ed with 0xff? I want this to be done at compile time. Is this possible?

>so bad you can't even write hello world without error
I bet you are american

400kg of arch lard is natural

The most useful thing you can do to learn how to program (and also to learn a particular programming language) is to read as much source code as you can.
You are rightly expected to consume lots of literature to become a good writer, listen and study lots of existing music in order to become a good musician, yet reading existing source code is often overlooked when trying to become a good programmer.
Don't make the same mistake. Take advantage what has already been made.

>22 yo NEET
>want to be a programmer but never even finished highschool.
>everything I know about programming is self taught so I'm probably awful.
I feel like there is no hope for me.

Attached: 1559675548043.png (456x465, 417K)

What type of programming do you do?

show code

What specific math(s) would be best to know/learn for learning programming on my own and eventually a degree?

Attached: 1530275236029.png (500x634, 536K)

Anyone here ever developed add-ons for Palemoon or for old Firefox, before that gay WebKit shit? I'm looking for an IDE or whatever else which has code intel/navigation for it.

Attached: 34qT37j.gif (441x231, 1012K)

basic arithmetic

Linear algebra.

So I don't suppose anyone here knows anything about hardware (I sure don't), but is there a rule anywhere that says I can't just clock-gate a flash chip in the middle of a transaction for several minutes at a time and just resume it like nothing just happened?

So what the fuck am I doing?
Well I'm reading this chip in quad-speed mode so I can't exactly use the SPI HOLD pin while waiting to receive orders.

Attached: AdvancedFaggotry.jpg (217x208, 10K)

Not a macro expert but i think this is what you want?
#[macro_export]
macro_rules! muh_sum {
( $( $x:expr ),+ ) => {
{
let sum = [$($x,)*].iter().sum::() & 0xff;
let arr = [$($x,)* sum];
arr
}
};
}

fn main() {
let arr = muh_sum![34, 43, 23, 54, 1, 2, 3, 4];
println!("{:?}", arr);
}

Attached: akari how is it.png (392x470, 145K)

post code

general - picrelated

various geometry for games, computational geometry for other shit as well

Attached: meth.jpg (743x582, 98K)

Nothing crazy, mostly just small stuff in python like a web scraper, blackjack, a script for calculating compounding interest rates etc etc.
I've played in c++ and javascript somewhat too, and I know a little bit about moving around in bash.

Attached: CUTE.jpg (1280x720, 84K)

Why is the pic ripa?

Hasn't HtDP deprecated SICP?

This is the worst syntax i've ever seen in my whole life, what is it?

Different jackass here. What behavior do you want when the sums don't match? You probably need a proc macro to make it a compilation error.
That solution will break on most inputs in debug mode. Use wrapping_add so it explicitly overflows. Also, "foo & 0xff" is redundant if foo is a u8.

Wrapping $x and 0xff in Wrapping (lel) made it compile and work. This is not computed at compile time however.

If people are so angry about an imported library having using namespace std, why don't they just do this?
namespace Containment{
#include header.h
}

Anyone else feel like they learned butt fuck nothing from university, especially when it comes to programming?
It is often said that dumb people try to learn everything on their own, wasting time, while smart people are smart enough to learn from those who already know, hence saving time, but who are you even supposed to learn from nowadays, as most professors and self-proclaimed "experts" are either shit themselves or more concerned with spreading memes and their agenda instead of actually teaching the fundamental, important stuff?
Is the internet really all we have nowadays?

It feels more and more like it's impossible to get real advice, teaching and feedback.

/blog

It's a C++ "feature" known as argument dependent lookup.
If a type defined in namespace Foo is supplied as an argument to a function, then name lookup also takes place in the Foo namespace to find a match.
This is why you can do std::cout

For beginners? Yes. SICP is overall the way better book though.

conventional: HtDP -> SICP -> CTM and Oz if you feeling frisky

Uhm, so is HtDP not really worth my time if I've already read SICP?

>work 8 hours a day as a programmer
>get home
>don't know what to code
Where do you guys get your ideas?

Attached: 1554048394941.gif (720x312, 1.74M)

If you went through an algorithms & data structures course and think you learned nothing that you couldn't just easily looked up on the internet, you probably didn't pay attention or are attending an absolute bottom of the bin school.

>work 8 hours a day as a programmer
>want to program when you get home
lmao nerd

Muh portfolio

This is what careerism does to your brain
Wagie is still a wagie even outside of his contract hours

>What behavior do you want when the sums don't match
There's nothing to match them with. The checksum is needed for the led controller that I'm trying to communicate to to accept it. I will need two macros in the end. One that generates the array with the checksum at compile time, for fixed commands such as power on/off and one that does it at runtime, for things like setting color. I could do everything at runtime I suppose, but there's no fun in that. I just need to find out how to generate [a, b, ... n, a + b + ... n] from macroname!(a, b, ... n) .

What are some other interests you have _other_ than programming? You can draw a surprising amount of inspiration for projects from those.

Whats the best way to gain fluency in haskell and clojure

Nearly everything that is taught in any college can be learned on your own.
This was true years ago, and it's even more so today thanks to the internet.

I've had moderate success with anal beeds.

#downloads pictures from a Jow Forums thread and stores them in the directory the script was ran from
import bs4 as bs
import urllib.request
import re
import os
threadurl = input("paste the thread you want to save from.")
filename = input("what common name do you want to save this stack of images as?")
os.mkdir(filename)
os.chdir(os.getcwd() + "//" + str(filename))
print("downloading...")
req = urllib.request.Request(threadurl, headers={'User-Agent': 'Mozilla/5.0'})
thread = urllib.request.urlopen(req).read()

soup = bs.BeautifulSoup(thread, "lxml")

soupStr=str(soup)
picList=[]
checkList=[]


picFinder = re.compile("i\.4cdn\.org/\w+/\d{1,20}\.\w{3,4}")
findPic = re.findall(picFinder,soupStr)
picList.append(findPic)
pnum = 0
picList = picList[0]
def f2(picList):
# order preserving
finalList = []
for e in picList:
if e not in finalList:
finalList.append(e)
return finalList
finalList = f2(picList)

for pic in finalList:
pnum += 1
freverse = pic[:-5:-1]
ftype = freverse[::-1]
urllib.request.urlretrieve("" + pic, filename + str(pnum) + ftype)

input("pics downloaded")

here's one of my scripts.
I call it "Jow Forums image downloading script" or "4ids" for short.
I thought that was funny at least.

Attached: 5d1e25bf3c80251a33bb05272348fe36.jpg (625x468, 31K)

Literally the only good sources directed at beginners on the internet are books and recordings of lectures.
And the fact that it can theoretically be done means absolutely jack shit. The vast majority of people will not be able to teach themselves any more serious material with rigor, unless they've already gone through a similar program.

how does one unpick a mess of bullshit commits in git, keeping some and excising others? also, how does one split up commits from way back so that they aren't just a slop bucket of unrelated changes?

You smell like a windows user.

bullshit. what forbidden data structure knowledge did they impart in school? fuck all.

Oh, that's much easier.

macro_rules! macroname {
( $( $value:expr ),* ) => {
[ $( $value ),* , 0u8 $( .wrapping_add($value) )* ]
}
}

can't tell you, it's secret

My gaymen pc runs windows for compatibility, but I also have a laptop running mint.

Attached: 1559337187003.png (672x752, 927K)

Are we sharing Jow Forums download scripts?
folder=`date +%Y-%m-%d`
url="$1"
while [ $# -gt 1 ] ; do
case "$2" in
-f)
folder="$3"
shift 2
;;
*)
break
;;
esac
done

wget -P "$folder" -nd -r -l 1 -H -D i.4cdn.org -A png,gif,jpg,jpeg,webm "$url" && rm "$folder"/*s.*

'bash scriptname.sh -f ' to create folder with name
or just 'bash scriptname.sh ' to create folder with timestamp as name.

BUT DUDE RED-BLACK TREES

run this though an yapf and its fine

Amortized runtime analysis, dynamic programming, splay trees, b trees.

Sure you could learn it all on your own, but that applies to anything.

Can someone tell me why the fuck doesnt this C# code work? It makes bbase 0 and height too. Why, they are doubles

string[] ints = Console.ReadLine().Split();
int r = int.Parse(ints[0]);
if (r > Math.Pow(10,6)) throw new Exception();
int l = int.Parse(ints[1]);
if (l > Math.Pow(10, 6)) throw new Exception();

if (r < 0 || l < 0)
{
Console.WriteLine("ujemny argument");
return;
}
double bbase = r * r * Math.PI;
double height = l * l - r * r;
if (bbase < 0)
{
Console.WriteLine("obiekt nie istnieje");
return;
}
double field = 1 / 3 * bbase * height;

Console.WriteLine(field);

>Amortized runtime analysis, dynamic programming, splay trees, b trees.
none of which is--

>Sure you could learn it all on your own
so what the fuck are you disputing?

Perfect, thanks a lot user. Now that I see the code it it makes perfect sense. Do you know of a good reference for rust macros?

>he hasn't heard of red-blue trees

-R '*s.jpg'

dude i learned red-black trees at my prestigious university. you couldn't learn that on you own.

You can learn literally learn anything online.
So why even go to school?
Your argument is pointless because it cannot be refuted.

Black red trees are better anyway

/dpt/-chan, daisuki~

Algorithms are CS fundation, sicp is more about the practices of programming

>What are you working on, Jow Forums?
Crafted an emacs native module then made a proposal on emacs mailing list but the maintainer politely told me to fuck off.

Thank you for using an anime image.

Attached: convex_or_concave.webm (720x720, 1.02M)

Not really. I just try some shit and see if it works.

By the way, you said two macros, but now that const fns are stable (wrapping_add is a const fn) you can even use this for compile-time constants:

const FOO: &[u8] = ¯oname![1, 2, 3, 4];
assert_eq!(FOO, &[1, 2, 3, 4, 10]);

>daisuki
omae mo

>If you went through an algorithms & data structures course and think you learned nothing that you couldn't just easily looked up on the internet, you probably didn't pay attention or are attending an absolute bottom of the bin school.
--thou

I can finally switch between viewing it as convex or concave at will instead of failing for two minutes. I can feel my brain getting stronger.