/dpt/ - Daily Programming Thread

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

Attached: dpt.jpg (800x547, 185K)

Other urls found in this thread:

pastebin.com/LYyusjVw
ideone.com/bZsyuH
u.lewd.se/3dAs7N.gz
blogs.msdn.microsoft.com/oldnewthing/
channel9.msdn.com/Events/GoingNative/2013/Inheritance-Is-The-Base-Class-of-Evil
twitter.com/SFWRedditImages

Posting "first for x" is for low brow mongs who just want a turf war.

I'm working on some robotics simulations with genetic algorithms in c and python. It's pretty good fun.

How How do I I write I write a iwritealoop iwritealoop iwritealoopincommon lisp?iwritealoopincommonlispi iwritealoopincommonlispireally sont

How do I write a loop in common lisp? I really don't get it. I've seen many examples but I can't build any intuition on it so rest I can internalize it and naturally make any loop.
How arrays work???

How does any of this work???
How the FUCK DO I PROGRAM? WHY CAN'T I LEARN? WHY DOES EVERYONE TAKE FOR GRANTED THAT IT SHOULD BE "EASY FOR ME" BECAUSE I'M A MATH MAJOR? I FAILED OUT OF PYTHON. I HAD TO SWITCH FROM CS TO MATH. I'D TRADE EVERYTHING FOR PROGRAMMING ABILITY

Attached: 1501794445868_0.png (863x1080, 365K)

Reminder that your code is not generic enough. You should use C++ templates and avoid loops.

install shen

Good post until C and python

(loop)

is this a pasta or are you serious?

Lisp frowns on loops. Instead of using a loop to iterate, you pick an element off the list and process that, and then call the function again with the remaining elements. Now, you're processing each element with a call, rather than an iteration. What languages do you know already?

>more turfwarring
Despite your opinion I'm having fun and getting paid to work on cool stuff. Keep shitting up Sup Forums my man

anyone able to help me on my databases homework? shouldn't be super difficult, I'm just struggling. We're doing it in MySQL but whatever works as long as it's in SQL

Database - pastebin.com/LYyusjVw

Attached: assignment 3.png (930x211, 30K)

you don't get it, it's sophisticated american humor, I did the opposite of what you said, and then the laugh track comes in and everyone claps

Attached: americlap.png (587x600, 475K)

Why does Lisp even have loop if it's frowned upon?

Thanks for your help user. Earlier I tried using this as my loop (c_pci initialized outside of the loop):
do {
a[i] = rand_num(0.0, 1.0);
i++;
sum = sum_array(a, i);
avg = calc_avg(sum, i);
variance = calc_variance(a, i, sum, avg);

if (i > 30) {
c_pci = pci(avg, variance, i);
} else {
continue;
}

} while (c_pci > 5);

but my program would always stop at 6147 iterations every time the program was run. Any reason why it would stop at 6147 iterations specifically?

>Lisp frowns on loops.
Is that why CL has the most extensive loop construct in the history of programming? I don't like it, but it's there.

Attached: (You).png (645x773, 71K)

I'm serious I don't get it
Can you say that in English? I don't get that explanation

If I can't loop then how do I do some thing over and over n times?
And what? And what else ? What else ?

I wish I could program

Attached: imsorry.png (1236x674, 708K)

you should use print statements to investigate which conditions makes your program behave. Often this alone will make your error obvious.

Many languages give you tools that aren't idiomatic for the situations where pragmatism trumps purity and you know better than a designer far away from your actual problem.

*shoots rifle into air*
yee haw

ok, you understand how loops work in C right?

>Lisp frowns on loops.
you mean schemefags tell you to use recursion.
Lisp(Common Lisp) tells you to use right tool for job, that's why there's goto, dolist, dotimes, do and loop.

???

but for real drop python, GAs with a functional language is aspberger nirvana

user, do you really think you have to ask?

Attached: rwby___yes_pillow_by_bean1215-d9ifwwz.jpg (1523x525, 184K)

Brainlet here. I don't understand ints and division. Can anyone show me how to calculate the average of two ints in C?

>*YOU* are full of bullshit.

>C++ is a horrible language. It's made more horrible by the fact that a lot
>of substandard programmers use it, to the point where it's much much
>easier to generate total and utter crap with it. Quite frankly, even if
>the choice of C were to do *nothing* but keep the C++ programmers out,
>that in itself would be a huge reason to use C.

-Our lord and savior, Mr. Trovalds

in order to give you an intuition on how to write a loop in lisp I figured it would be useful to show how to implement a loop in C without the for { } construct..

I'm just gonna leave this here.
var fps = 60;
var dist = 375;
var dur = 60 * 6;
var fpp = dur / dist * fps;

var k = fpp - Math.floor(fpp);
var x = 0;
var countdown = Math.floor(fpp);

for(var t = 0; t

He is right but he is a faggot.

ideone.com/bZsyuH

will tip in ETH lol

int avg(int x, int y)
{
while (y)
--y, ++x;
return x >> 1;
}

user asked for source for my work in progress
u.lewd.se/3dAs7N.gz
tar -xzf
cd zip_dir
python2 gl.py

>using FLOAT for currency
>the very state of MySQL
Anyways anything in particular you're struggling with?

what if y is

Start writing down in plain english how you would get the information, then writing the SQL will be easier. It will also help you realize which terms to google

Imagine being this smart, but this stupid.

How do you think this will work for the average of -20 and -10?

Thanks bud

(You) for being original

c++ using "auto" as the keyword for type inference is the worst language design decision ever made in human history

Eh.. At least it is not 'let'

The fourth part of the assignment,

List all Customers that purchased any type of Hammer or any kind of Saw or Saw Blade.

Just not sure on how to do it.

why is that?

building on this, for excercise 1 you want to:
Get all the customers who live in 615, and all the customers who has been invoiced, then you want the intersection of those two sets wrt customer id.

>her language doesn't make everything "auto" by default
Revolting.

collect all invoices for hammers, saws and sawblades, intersect with customer ids and remove duplicates

Sometimes I wonder why "auto" even popped in their heads when implementing type inference. A solid-rock proof that C++ makes you an autist

her : Male

Composition over inheritance

I'm asking you what's wrong with auto though.

YourPost : Void

i dont like it

Attached: 1522073037083.png (190x266, 5K)

this

it's different from what im used to

Attached: 400.jpg (353x400, 127K)

I understand what you're saying, but I have no clue how to put that into SQL Code

>having to type more letters than it takes to just type out the actual type

Attached: 729.gif (340x340, 137K)

break it down, how would you write a SQL query to select all invoices for hammers?

Look into SELECT DISTINCT; looks like you'll need to hard-code the product IDs into the query since the schema you posted doesn't have a table for product categories.

>*changes type*

stop

Attached: it's all so tiresome.png (500x478, 114K)

_ for auto
problem solved.

>changes type
>m-m-muh auto saved me so much work!
>gets some obscure errors further down the line

Attached: 253534425.png (226x223, 3K)

yeah I'm lost

The professor is pretty shit so I don't really know SQL

I'd prefer _ be a global, built-in, write-only variable of type auto so it can act like _ is used in Python, but that would take more effort to add to the standard than it would save.

>cannot on variable of type
Stop using bad compilers.

*changes type at runtime*

>she doesn't program in Idealized Algol

you know what you want to achieve, but you don't know how. This should be enough to know which part of the docs, or what you should google for. This is an essential skill, much more important than knowing SQL, and it's something you have to practice.

> like _ is used in Python
pls no
it should simply be a hole like in FP with the added benefit of also being an "auto".

You'll need to select distinct customer IDs from your customers table, joined to products through the invoice & line tables, where the product ID is one of the ones you're looking for. This will not be a short query, so don't worry you're getting a wrong answer if it looks complicated.

I mean, that's kind of how it's used in Python, just that it's convention rather than a supported part of the language.

Well Python allows a lot of other things i disagree with.

go is for retards

Reusing a keyword is always better than introducing a new one, and nobody is sad to see C89 auto gone.

> std::map::iterator it = myMap.begin();
> auto it = myMap.begin();

>backward compatibility uber alles
Tales from a company that has that stance, and its consequences
blogs.msdn.microsoft.com/oldnewthing/

>what are using declarations

How does C++ handle this?
base.H:
struct FooB {
int first;
FooB(): first{0}{}
virtual FooB & foo() { return *this;}
};


derived.H:
#include "base.H"
struct FooD : public FooB {
int second;
FooD(): FooB{}, second{0} {}
FooD & foo() {return *this;}
};


lib.H:
#include "base.H"
void bar(FooB const &);


main.cpp:
#include "lib.H"
#include "derived.H"
int main(){
FooD foo{};
bar(foo);
}


lib.cpp
#include "lib.H"
void bar(FooB const & input){
auto something = input.foo();
}


What is the datatype of variable something in the function bar()?
FooB::foo() return a reference to FooB, but because it's a virtual, and the main() function pass a FooD, then the function FooD::foo() called instead.
But the while lib.cpp translation unit doesn't have any idea about FooD at all, because it's a derivation from FooB, so how C++ handle this mess?

Fuck, I made a mistake. The function bar() is accepting non const reference, so it should be:
void bar(FooB &);

vtables

This is you admitting you care more about language wars than robots.

Get off Sup Forums and go somewhere like Sup Forums where shit chat is actually what people want.

lol i bet ur one of those "right tool for the job" fags

the opposite, i dont care what you use as long as you're doing cool stuff with it

I'm not gonna pretend I'm not a huge PL autist. I actually have done a lot of robotics in python and C++ with ROS making ROVs for competitions, and the one thing I'd do differently today is drop python for either haskell or scala.

Programming languages are important dammit

Womans aren't worthless whores. Jews want western man to think so. It's a small part of white genocide project.

It creates a FooB, which is obviously a mistake. A FooB is constructed using the (implicitly defined, nonvirtual) FooB::FooB(FooB const&) constructor, which is a mistake. This problem is generally known as object slicing.

The solution is as follows. For all user-defined types do either of the following.
>Declare it final, thus making it non-inheritable.
>Explicitly delete the T::T(T const&) and T::operator=(T const&) functions, therefore preventing accidental slicing.
You may want to wrap uses of inheritance in objects that obey value semantics, as demonstrated in this talk.
channel9.msdn.com/Events/GoingNative/2013/Inheritance-Is-The-Base-Class-of-Evil

>haskell for robotics
how would you justify that?

nothing but recursion.

for (int i = 0; i < N; ++i) {putc(array[i]);} putc('\n');

Can't you explicitly declare the copy constructor/assignment operator and declare them as virtual?

I'd use haskell for high level tasks (and possibly streams).

For instance, I'd use scala or haskell to run a genetic algorithm to search the parameter space of the regulator, but let ROS gazebo do the actual heavy lifting.

(ROS gazebo + the C++ codebase for the regulator system)

>>Explicitly delete the T::T(T const&) and T::operator=(T const&) functions, therefore preventing accidental slicing.
isn't that will result in linker error, whenever there is a pass by value?

Constructors can't be declared virtual, and it's a bad idea anyway. Consider the following.
void bar(FooB const &a)
{
FooB b;
b = a;
}
Let's suppose the runtime type of a is a FooD. What is the correct behavior? Only a FooB has been declared for b, so it's lacking the capacity for FooD's members. You can't create another FooD instance. The best thing you can do in this circumstance is raise some sort of error, like throwing an exception.

If you have polymorphic objects for which you want to create copies, the idiomatic way is to use a clone method.
class Copyable
{
public:
virtual Copyable *clone() const { return new Copyable; }
};

class CopyableD
{
public:
Copyable *clone() const override { return new CopyableD; }
}

You may want to return a unique_ptr if you're a fan of Modern C++.

It will. Polymorphism does not play nicely with value semantics. If you want to keep value semantics, it's best to wrap inheritance-based polymophism in an object with value semantics like that talk describes.

why wont my [spoiler]spoiler[/spoile tag work?

>Print a char array in one line of code.

Answer1:
[spoiler]for (int i = 0; i < N; ++i) {putc(array[i]);} putc('\n');[/spoiler]
Answer2:
[spoiler] printf("%s/n",arrayname); [/spoiler]

Winner for answer 3 gets an ascii picture

redpill me on antigrain geometry

Spoiler only works on specific boards. Stop spamming.

because it's not supported here newfag, now fuck off.

>/n

answer2 is shit
printf("%.*s/n", N, arrayname);

Object slicing isn't occurring here because they're being passed by reference, unless I missed something.

I have 16 hours to figure out how to make an app with a few clickable buttons that play gifs. I also need to have a "bar" decrease over the span of 2 weeks. I'd also like to add a background that changes based on time of day and a splash screen. Is this possible to learn in 16 hours? I've never made an app before but I know java. It's not being marked btw. It's just to impress normies for a presentation

auto something = input.foo();

>a char array
>printf("%s/n",arrayname);

What kind of drugs are you high on?
passing non null-terminated string to any stdlib expecting a null-terminated string will read your whole machine's memory