/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Ara ara...

Previous thread:

Attached: kuppahime.jpg (750x1061, 565K)

Other urls found in this thread:

github.com/hablapps/DontFearTheProfunctorOptics
twitter.com/NSFWRedditVideo

%bellTriangle.pl

addToEnd([],X,[X]) :- !.
addToEnd([Y | Resto],X,[Y | List]) :-
addToEnd(Resto,X,List).

nthElement(Index,Index,[X|_],X) :- !.
nthElement(Index,Count,[_|R],Res) :-
Count1 is Count+1,
nthElement(Index,Count1,R,Res).

computeNext(Index,Index,_,NewList,NewList) :- !.
computeNext(Index,Count,List,NewList,Res) :-
nthElement(Count,0,List,PrevUpperElement),
nthElement(Count,0,NewList,PrevElement),
Sum is PrevUpperElement + PrevElement,
addToEnd(NewList,Sum,NewList1),
write(Sum),write(' '),
Count1 is Count+1,
computeNext(Index,Count1,List,NewList1,Res).

bellTriangle(N,N,_) :- !.
bellTriangle(N,0,List):-
nthElement(0,0,List,X),
write(X),nl,
bellTriangle(N,1,List).
bellTriangle(N,Index,List) :-
Indexx is Index-1,
nthElement(Indexx,0,List,LastElement),
addToEnd([],LastElement,NewList),
write(LastElement),write(' '),
computeNext(Index,0,List,NewList,NewList1),nl,
Index1 is Index+1,
bellTriangle(N,Index1,NewList1).

main_bellTriangle(N) :- bellTriangle(N,0,[1]).


?- main_bellTriangle(5).
1
1 2
2 3 5
5 7 10 15
15 20 27 37 52
true .

Just finished Bell's Triangle in Prolog. Thought It would take me a lot longer desu.

>What are you working on, Jow Forums?
getting my first $300k job. already have:
[x] learned Haskell
[x] Anime avatar

Attached: 1486959616284.jpg (511x564, 46K)

Btw, Prolog is the most unreadable language in existence.

[x] based
[x] redpilled

Attached: 1537985908896.png (1075x1518, 1.76M)

Have you tried J?

Still don't know what monads are
Whenever you ask it on Jow Forums there is always some autist who will try to """explain""" it in obscure way so nobody can understand it. Guess he fells smarter that way
I will stay with my OOP lang and actually earn money

Attached: 1527148331869.png (500x658, 147K)

stop trying to learn and use them

Why does nobody here talk about Erlang?

look just imagine a burrito

I dont want to use them because I'm not an FPtard but I still want to understand what they are

rude!

use them to learn

Lisp is the most powerful programming language.

just tell me what they are

Turing machine in PowerPoint is the most powerful language

Fucking learn by example you cunt

github.com/hablapps/DontFearTheProfunctorOptics

So I'm attempting to understand the meta-programming facilities in Scheme. Could someone explain the difference between Define-Syntax and Syntax-rules? There doesn't seem to be much information on these different aspects of macro programming

This

>Chad programmer
>doesn't know what monads are or what they do, sorry. Earns 100k/hour
>virgin programmer
>uses fp all day long on his riced CuC'd linux machine. Never leaves his room

Attached: Capture.png (814x385, 34K)

>boyEstrogen

Attached: 1537379077881.jpg (1916x1080, 1.08M)

they're just containers and instead of operating directly to the values they contain you do it with special functions

Post an example then

That's what I thought they were, but I felt like I was missing something seeing nobody just came out and said it

awful explanation
Then you were wrong

Should be “Chad code ninja” or sth

You use syntax-rules inside of deifne-syntax. define-syntax binds a name to the macro you create, which you can use within syntax-rules.

>doesn't elaborate, just calls people wrong
another victory for the FPtards

>What are you working on, Jow Forums?
Nothing today yet, just finished watching virgin cuckboy Conor VS Chad and Khabib's match. Emotion game truly doesn't really play with based ruskies.

I'll have some food and get back to my gtkd series now.

Attached: 1536063434963.jpg (700x343, 35K)

Spent all day writing tests/validation. It's a slog to write all of it but really satisfying when it all finally works.

when will bowsette fad go away its so forced

It's just one OP, it's possibly a discord raid.
Don't worry it'll be over in a week or two.

Attached: 1538759723991.png (380x640, 648K)

Every
Fucking
Time

Based komariposter

no but i see it all over /b/, chan.sankakucomplex, etc etc etc it's everywhere

None of that actually exists
Only Jow Forums is real

Those are not relevant. Going to /b/ is your problem. Then again, this will fade away in /b/ soon too.

/b/ still exists?

more mario comics!

What languages have a debug print feature that prints both the source of the expression being debugged and what it evaluates to?

You mean this?
void main() {
debug {
import std.stdio : writeln;

writeln(__PRETTY_FUNCTION__, "\n ", __FILE_FULL_PATH__);
}
}

Common Lisp

What is used instead of CGI nowadays?
It looks so simple conceptually - take input and make HTML output. But they write that CGI is not used anymore.

Attached: 1530620899081.jpg (440x392, 34K)

I'm making quiz "find out what celebrity you are"
except you will be matched with school shooters only.

The C programming language

FastCGI, uWSGI, SCGI, Reverse Proxy, maybe some modules if you're still stuck on Apache. If you google 'setting up {your_webserver} with {the_language/framework_you_want_to_write_for}', you're guaranteed to find lots of valid ideas.

I use uWSGI behind nginx for running django.

>FastCGI, uWSGI, SCGI
Sounds like I can use my CGI applications without any change, can't I?

>want sum fucc niggy?
yes

No. CGI apps get launched once for each request, while those all use long-running processes listening on a port or socket to handle multiple incoming requests. FastCGI would probably be the simplest conversion job.

Getting off my ass and learning to program. I am messing around with cs50 as it seems like a good place for a brainlet like me to start. But fuck me if I know what I am doing wrong here. Please help.

#include
#include

int main(void){
int quarters, dimes, nickels, pennies;
float change = get_float("Change owed: ");
float q = 0.25, d = 0.10, n = 0.05, p = 0.01;

do while( change = q){
for( quarters = 0 ; change < q ; quarters ++){
change - q;
}}
else if (change >= d){
for( dimes = 0 ; change < d ; dimes ++){
change - d;
}}
else if (change >= n){
for( nickels = 0 ; change < n ; nickels ++){
change - n;
}}
else if(change >= p){
for( pennies = 0 ; change < p ; pennies ++){
change - p;
}}
}
printf("Your change is %d quarters, %d dimes, %d nickels, and %d pennies.\n", quarters, dimes, nickels, pennies);
}

Attached: 1533122631443.jpg (300x350, 95K)

change - q
did you mean
change -= q

That's not how do...while loops work.

This will produce a compiler error.
while (x) { y; z; } and do { y; z; } while (x); are valid constructs but do while (x) {y; z;} is not.

in fact i'm pretty sure you can just remove the do while and the ifs and just have the for loops (using -=)

your variables are named poorly, something like quarter_count and quarter_value = 0.25 would be more readable.

do while loops do not work like that

i have no fucking idea what you were doing with your inner for loops

int main(void){
int quarters, dimes, nickels, pennies;
float change = get_float("Change owed: ");
float q = 0.25, d = 0.10, n = 0.05, p = 0.01;

if (change > 0)
{
while (change >= q) {
change -= q;
quarters += 1;
}
while (change >= d) {
change -= d;
dimes += 1;
}
while (change >= n) {
change -= n;
nickels += 1;
}
while (change >= p) {
change -= p;
pennies += 1;
}
}

printf("Your change is %d quarters, %d dimes, %d nickels, and %d pennies.\n", quarters, dimes, nickels, pennies);
}

>sucking at maths this hard

Attached: 1536537224489.png (316x422, 150K)

Attached: aeudtcahfsq11.jpg (810x1080, 107K)

...

I changed it to a do while as for( ; change

for the actual algorithm, you can just use 4 while loops
while (change >= q) { ...add quarters, subtracting from change...}
while (change >= d) {... add dimes, subtracting from change...}
while (change >=n) {...same for nickels...}
while (change >= p) {...same for pennies...}

You'd probably be better served going through a simple C tutorial first just to get the syntax down.

Also, you seem to be mixing up your less than and greater than tests a lot. If a number, like your quarters,dimes, etc., is being consistently added to, you'll probably be testing if it's still less than some number, and conversely, if a number is consistently being subtracted from, like your change variable, then you'll probably want to be checking if it's still greater than some number.

The compiler's not lying to you.
change - q
What does this say? You're taking q away from change and then... nothing. The result of this calculation doesn't get used, it just gets thrown away.
What you want is to then assign the result of taking q away from change to change. So
change = change - q
Assigning back to one of the operands is something you'll be doing a lot, so C has a concise alternative syntax for this case.
change -= q

Dude what the fuck are those inner for loops.
It should be change = change - q OR change -= q, you do a calculation but dont assign it anywhere.
Just read the code posted above.

use -=
also your do while is wrong, it's doing while change

Thank you for the feed back. I know what I want to do but it's clear I am not putting enough thought into the syntax. I hope next time I post here it wont be such a waste of time for you guys and something worth sharing. Thanks again.

Attached: 1533080216762.png (1134x852, 1001K)

quarters = change / q
change = change % q
dimes = change / d
change = change % d
nickels = change / n
change = change % n
pennies = change

Overcomplicated a very simple problem.

int main(void){
float q = 0.25f, d = 0.10f, n = 0.05f, p = 0.01f;
int quarters = 0, dimes = 0, nickels = 0, pennys = 0;
float change = get_float("Change owed: ");

while (change >= q) {
change -= q;
quarters += 1;
}
while (change >= d) {
change -= d;
dimes += 1;
}
while (change >= n) {
change -= n;
nickels += 1;
}
while (change >= p) {
change -= p;
pennies += 1;
}

printf("Your change is %d quarters, %d dimes, %d nickels, and %d pennies.\n", quarters, dimes, nickels, pennies);
}

main = let helloAction = putStrLn "Hello"
worldAction = putStrLn "World!"
in helloAction >> worldAction
tfw finally staring to grok io monad

Real talk, where can I find this SE Crown?

Attached: 1526443568222.png (800x1067, 1.03M)

Are there any good resources on modeling category theory/abstract algebra in programming?

also WHY DO I HAVE TO SOLVE 50 CAPTCHAS NOW FUCK YOU GOOGLE GIVE ME A FUCKINGRBAHJDASDSAD

Attached: Dancing Queen.gif (680x486, 42K)

>Are there any good resources on modeling category theory/abstract algebra in programming?
no

>Doesnt handle negative user inputs
>Using modulo with floats
cmon dude are you trying to confuse noobies

I forgot to say everything should be ints, you souldn't use floats for currency anyway.

>you souldn't use floats for currency anyway
bruh they are literally real numbers. a quarter is .25 dosh

Floats are inaccurate, just use fixed point arithmetic you dumbass

double has more than enough precision for regular ass currency.

>more than enough precision
floats have different behaviours on different systems
use ints

Currency is literally an integer with a period before the two least significant figures

fiiiiiiiiiiiiiine. if displaying a monetary value, how would you represent the decimal? something as simple as

int dosh{399};
cout

floats aren't reals

floats are feels

store the price as the amount of cents, preferably in a long instead of an int
when you want to display it you can convert to float and divide by 100 or write a convert to string function that inserts the point manually

>The Coinage Act of 1792 of the Continental Congress established that the lowest money of account for the United States is one-thousandth (1/1000) of a dollar.
Banks and stock traders actually trade in much smaller fractions than this too.

any reason to use
fgets(array, 20, stdin);

as opposed to
scanf("%20s", array);

scanf needs to interpret the the format string, can make a difference if you are calling it a billion times a second.
fgets also has the advantage of catching alot more errors at compile time.

also, fgets will read newlines into the buffer if it has space for it, scanf will break on newline

no problem user

thanks lad

My thinking

Attached: 412TO0yF2hL._SX403_BO1,204,203,200_.jpg (405x500, 30K)

I have to become interested programming by way of video games but don't know where to start.i been told to start from python to java/javascript then C.

This is the right path?
Do I have to go to a CS course?

Attached: 1538527363731.jpg (348x1024, 80K)

do you want to program video games?

For the most part, but I've been in awe by the programming world and Jow Forums I wish to go deeper into it.

I have a lot of free time.

Attached: 1538272628924.jpg (648x648, 51K)

Stick to one language at a time and see what you can make with it,it will be the foundation language to understand computing and it will be easier to transition to others after you learn the bigs idea through that language.

Python or C are good starts

you'll probably have to learn C# and C+ for games

okay then sums it up very well.

The choice of language you start with doesn't matter terribly much, just don't waste your time going to and fro without learning anything substantial. When you have enough experience you won't find learning a new language difficult anyway.

People say python is a good beginner language but heard javascript common in web games/phone games.

>C# and C+

How different are this from plan old c itself?

Both are quite different from C.
C++ started off looking quite similar to C, but modern C++ is unrecognisable. C# was never very much like C and resembles Java more than anything.

C# and C++ are used as scripting languages for different game engines to do stuff,stuff like telling the game what to do for gameplay.C and C++ are use in graphic API too so if you want to get to the dirty tunnels parts of programming there that.

Ok thanks guys, going to download python now.
Do you guys have any resource on python just or just use the sites.?

*scripting languages for the most popular game engines(unreal,unity,cryengine etc).

when I was in school with use "how to think like a computer scientist useing X" and I learned alot from it, we also use a visual programming tool to see the flow of logic before we started coding called rapto use in the airforce or something.