/dpt/ - Daily Programming Thread

Old thread: What are you working on Sup Forums?

Other urls found in this thread:

etalabs.net/overcommit.html
twitter.com/SFWRedditVideos

pls don't bully 4-chan

first for Haskell

Let's discuss our personal usage of terminology gee.
>how do you define a variable?
In particular, is it just a label on a piece of the stack, or the piece itself? Doess dynamically allocated memory contain variables?

I see Golang take the stance that
>A variable is a storage location for holding a value.
from which it follows that
>[dynamic allocation] allocates storage for a variable at run time.
and that &x points to the variable we were calling x itself. In C its not so, so there is a weird, difficult-to-explain distinction between variables and objects... What do you think? Would that terminology be possible in C?

first for Python is cancer

First for lookup table is more readable than hundreds of if statements.

Fucked up my link

>>for no gain
Why express things in code logic, when you can express it in data?
My way is easily extendible, but I suppose it's not that important in this situation, because you probably won't be extending brainfuck.

First for
if c == "":
break
elif c == '>':
sys.stdout.write("\tadd $1, %rbx\n")
elif c == '

agreed. Reposting:
Yes there is a qualitative difference. There are much more details which are fixed in a if-write program like yours than in creating a dictionnary containing lambdas or whatever. There is only one way to create the dict, but here you copy paste the exact manner in which you are going to use the string, dummy.

No it's not, except if your goal is to express how inexpressive Python is. ffs!

Made a program that does this,
What are more ways to obscure IPs/URLs?
aHR0cDovL/CdkIbwnZCO8J2QjvCdkIbwnZCL8J2QhC7wnZCC8J2QjvCdkIwvDQpodHRwOi8vMDMzMC4wNzIuNTU1OTgvDQpodHRwOi8vMHhkOC4weDNhLjU1NTk4Lw0KaHR0cDovLzAzMzAuMzg1NjY4Ni8NCmh0dHA6Ly8weGQ4LjM4NTY2ODYvDQpodHRwOi8vMDMzMC4wNzIuMDMzMS4wNTYvDQpodHRwOi8vMHhkOC4weDNhLjB4ZDkuMHgyZS8NCmh0dHA6Ly8zNjI3NzM1MzQyLw==
>Error: Our system thinks your post is spam. Please reformat and try again.
base64 decode it senpai

They could do it while still yielding the string to the stdout.write, which is the main point of the code. Plus you can just return "" if you don't want to output anything. See

>all valid urls
wat

I was joking, I'm not the guy from last thread that thought it was a good idea.

>this image was made ironically
>the code in this post was not

Oh ok! I so often fall for it. 10/10 nonetheless!

>GNU software

It's this legal code in C?
int main(void)
{
string c;
for(int i = 0; i < 5; i++)
{
c += " ";
}
c += "#";

printf (c);
}

>string c
No.

no it isn't good at all

there is no switch or pattern match for python

you are suppose to use multiple if-else statements, that's why python is dogshit

the guido faggot

no for multiple reasons

I'll be using a string library.

I already know string it's not a default type in C.

even worse, you are forced to use elif instead of else + if

No, you need to include stdlib
#include "stdlib.h"
int main(void)
{
string c;
for(int i = 0; i < 5; i++)
{
c += " ";
}
c += "#";
printf (c);
}

There, much better.

xD

how do you format with tabs inside appchan?

>tab-based language
Disgusting. I only use space-based languages.

>#include "stdlib.h"
>not #include
>not using #include
>string c
>printf(c)

hello pahjeet

Can getc() return a negative value different than EOF?

Is there anything more autistic than fighting over tabs vs spaces?

>what is joke
>user don't banter
>don't banter
>no more

No, tabs are objectively superior.

getc() returns the character read as an unsigned char cast to an int or EOF on end of file or error.

>I can copypasta the man page
you did good, pajeet

lambda chain nigguh

>i don't read the fucking manual
back to the loo rajesh

lambda dictionary was horrible

(not him) read this sentence and think about it. Sometimes text analysis is no more than isolating the element and bringing it to light. Pajeet did a pretty good job at it IMHO.

how do I add "\n" to a string in c?

str[0] += '\n';

So, yes?

why are u using 0 in the char array?

I'm joking. That's not how you do it.

Use strcat

it's a string array

yes

Depends what you're doing to it. Remember that in C you have to micromanage memory. "producing a string by adding a newline to an existing string" is not how you should think in C.
printf("%s\n", str); // if you can
size_t len = strlen(str);
str[len] = '\n';
str[len+1] = '\0'; // ONLY IF YOU KNOW FOR SURE THAT IT IS SAFE
size_t len = strlen(str);
char *str2 = malloc(len+1);
sprintf(str2, "%s\n", str); // or you can do it manually

>sprintf(str2, "%s\n", str);
undefined behavior

error: invalid operands to binary expression ('string' (aka 'char *') and 'char *')
error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
printf(tmp);

Eh? Why?

No.
int sprintf(char *str, const char *format, ...);

because sprintf writes len + 2 bytes
you're an idiot

>you're an idiot
why

OMG rite! Thank you user, I didn't malloc enough of them. Well I should probably smprintf, it boils down to the same thing.
You were entirely out of topic in an idiotic fashion, that's why.

Also, newfriend, don't forget to free(str2).

>You were entirely out of topic in an idiotic fashion, that's why.
>Also, newfriend, don't forget to free(str2).

don't forget to check the return value of malloc, pleb.

>check the return value of malloc
Fucking useless to a degree not yet described by mankind. Linux overcommits, the rest don't matter.

I need to understand a MATLAB program by someone else for Uni, which is quite hard for me.

he called this function
store(variable)

at the end of almost every block.

But if I open the file store.m, all I see is this:

function store(c)

store(get(c,'this'),c);


No comments. Nothing. "store" in whatever configuration is not in the matlab documentation. It calls itself apparently recursively, so I suppose whatever is being returned by the first call triggers whatever it is doing at the second call. But I don't get where it stops, or is this just a fancy way to call

get(((variable,'this'),variable)),((variable,'this'),variable))


Whatever that would do.

Wanting to get in to python and I have a few questions.
1. To write and execute scripts, should I use visual studio or something less gay?
2. Does python use pointers like in C#?

Wew lad... You need the Python interpreter to execute the scripts. To write them, you use your favorite text editor. No, there's no pointers.

You are a retard
etalabs.net/overcommit.html
Also on the new linux versions malloc will return null instead of killing the program.

You need to end yourself.

int main()
{
mpd::conn mpd;

for (auto &song : mpd.playlist())
{
std::cout

how many minutes to compile that 5 line program?

cutFunction

improved version, optimised for faster compile time

int main(){mpd::conn mpd;for(auto&song:mpd.playlist())std::cout

What have been some of the most challenging and useful exercises you did when learning C++, Sup Forums?

C is beautifuler.

int main(int c, char **v)
{
struct mpd_connection *mpd;

char *error;
if(mpd_connection_init(mpd, error) != MPD_OK);
{
fprintf(stderr, "%s\n", error);
mpd_error_free(error);
return 0;
}

struct mpd_entry *e = mpd_playlist(mpd);
while(e != NULL)
{
fprintf(stdout, "%s\n", e->uri);
e = e->next;
}

mpd_connection_free(mpd);
return 0;
}

>stateful functional programming
>Java

I wouldn't describe R as a functional language, really

da fuck

pls rate my homework.


#include
#include

int main(void)
{
printf("How tall do you want the stair?\n");
int number = GetInt();
int stairs = 1;

for (int y = 0; y < number; y++)
{
stairs++;
for (int x = 0; x < number; x++)
{
if (x > number - stairs)
{
printf("#");
}
else
{
printf(" ");
}
}
printf("\n");
}
}

10/10 for unnecessary braces

10/10 for pointless stairs variable

Ew, not elegant.

It implements some of the basic concepts, which is enough for me right now. I'm not trying to write full programs in R functionally or anything, that would be stupid as fuck. I'm just encountering places here and there where constructing a closure turned out to be easier than other ways I could think of to do a task.

1 second.
Although that is one problem of C++, slow compile times.

>pointless stairs variable
>wanting magic numbers in code

I don't think magic number means what you think it means.

>(y + 1)
>magic number

All numbers are magical when you think about them enough, user

>passing uninitialized "mpd" and "error" by value to _init
ishyggy

I don't have to think enough to conclude that you're a faggot, though.

THIS

>#define ONE 1

if user wanted to make his stairs offset to the right then user could pass a number to the stairs variable instead of leaving it at one, which is easy functionality to add as the program stands. if it was a 1 in the comparison instead of stairs then that's a meaningful number that controls the output and behavior of the program that's hardcoded in - a magic number

Is scala a good language for a first time programmer?
I enrolled the coursera 5-course specialization but dunno if I should switch to another language

int stairsDifference = 1;


y + stairsDifference

>scala
>good language
>first time programmer
bwahahahahaha

Is scala a good choice for my first programming language?
I just enrolled the 5 course specialization in functional programming in scala but I dunno if I should switch to another language
Also best books in scala/ the language you're going to recommend

posted twice, fuck

Any language is a good first language, honestly.

sounds like you don't know scala :^)

Sounds like you do :&)

I do :#(

8===D O:

how do I solve this?
:(

Care to explain why pls

Install Gentoo.

reported

Lo siento, no hablo espanol :(((

Hola Mario

Learn to use the debugger.

the output is correct, but it's not what they are expecting.

I'm just confused over what to do, since my answer is correct.