[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 25
File: psystems4.jpg (46 KB, 492x412) Image search: [Google]
psystems4.jpg
46 KB, 492x412
Logic Programming Edition

(functional also welcome but keep OOP IN THE LOO in the pajeet general)

Old: >>54744605

How is Lisp for logic programming btw?
>>
>>54750565
IGNORE THIS THREAD IT WAS POSTED PREMATURELY ON A SLOW PART OF THE DAY AND IT'S FUCKING GAY

kill yourself
>>
>>54750565
>Created before the bump limit
>Shitposting in the OP
Delete this shit. I don't care if you're not the trapfag.
>>
>>54750565
>How is Lisp for logic programming btw?

Use prolog like a normal human being.
>>
>>54750585
>>54750587
kill urself cunt

>>54750593
fuck off tripfag, Prolog isn't even the only or even the best logic programming language, you retarded mongrel
>>
What are some real world uses of Prolog or logic programming in general? I know Nokia used Prolog for the N900/Maemo5 process scheduler

>>54750606
What's the best one?
>>
>>54750649
>What are some real world uses of Prolog or logic programming in general?
makes you even more smug then haskelel
>>
>>54750649
>What are some real world uses of Prolog or logic programming in general?

From what little exposure I've had to it, I find it very elegant/simple. You're just stating facts and deriving things from these facts.
>>
File: CAN'T WAKE UP.png (725 KB, 1280x738) Image search: [Google]
CAN'T WAKE UP.png
725 KB, 1280x738
>>54750722
>tfw you fix your C++ code by turning it into C code

my only real mistake was falling for the STL containers meme.
>>
Am i fucking retarded for not getting this?

Say we have an array a = [1,5,7,9]
length is n = 4
for(i = n - 1; i > 0; i--){
do something
for(j = i - 1 ; j >= 0; j--){
do something (x)
}
}



How many times will the line on X be executed (with n a random array length). Is it (n-1) * (n-1).
A friend of mine said it was (n(n-1)) / 2. But I don't see how that can be correct.
>>
>>54750785
>lapishit posters can't even quote the right posts

a bird mom poster would never do this
>>
>>54750649
>>54750670
N-queens problem
>>
>>54750726
>>54750726 >>54750726
>>54750726 >>54750726 >>54750726
>>54750726 >>54750726
>>54750726

i can play the spamming game too fucking cancerous smug fag
>>
>>54750851
Damn, I just clicked a random post to get a quick reply window.
>>
>>5475083
you are retarded.
Its simply nested loop.

4 times 4 do somethings.its n^2 thats it.

Dont let you confuse yourself by that n-1. Its simply because the first index is 0 instead of 1.
>>
>>54750839
Outside executes n - 1 times (ex: n = 4, executes for 3, 2, 1 = 3 times). Inside executes i times (ex: i = 5, execute for 4, 3, 2, 1, 0 = 5 times). Taking into acount that i is the current n - 1, then for n = 6, for example, you'd have

n = 6, i starts at 5
i = 5 && j will go from 4 to 0 (= x5 executions) || outter loop x1 = inner loop x5 = line x5
i = 4 && j will go from 3 to 0 (= x4 executions) || outter loop x2 = inner loop x4 = line x4
i = 3 && j will go from 2 to 0 (= x3 executions)| | outter loop x3 = inner loop x3 = line x3
i = 2 && j will go from 1 to 0 (= x2 executions) || outter loop x4 = inner loop x2 = line x2
i = 1 && j will go from 0 to 0 (= x1 executions) || outter loop x5 = inner loop x1 = line x1
total amount of executions of that line: x15

it's easy to spot the relationship (just imagine the pattern - n = 5 is n = 6 minus the first line, so x4 + x3 + x2 + x1, and the same strategy applies if you increase n instead of decrementing it): 1 3 6 10 15 21 etc, which are the triangular numbers with the n triangular number being n*(n-1)/2 (proving this is easy but falls outside the scope of this discussion)
>>
>>54750984
oops, last line should be n*(n+1)/2

so neither of you is right
>>
>>54750565
What is this image from?
>>
>>54751008
shit, second correction: the triangular numbers are n*(n+1)/2, yes, but I mixed up the variables: your sequence is shifted (n = 6 is 15, which is the 5th triangular number)

so replace the formula for the triangular numbers with k*(k+1)/2, knowing that k = n - 1, substitute and you get (n-1)*n/2 like your friend said
>>
File: 1463414666390.jpg (161 KB, 480x589) Image search: [Google]
1463414666390.jpg
161 KB, 480x589
>get told to learn C as my first language
>wanna study EE so that makes sense
>The only programming I've done was some basic stuff on Python during GCSE (loops, tables, displaying images)
>look through recommended book, only find one (Head First C)
>begin the first exercise
>errors all over
>all this shit I don't recognize
>only thing I could run properly was "Hello World"
Fuck help me /g/. Should I just piss off and learn JavaScript first or something?
>>
>>54751008
Are you sure? If i put n = 1, i would be 0, so nothing would get executed. However using your fomula it would get executed 1 time. Using the other formula it'd be 0.
>>
File: hqdefault[2].jpg (14 KB, 480x360) Image search: [Google]
hqdefault[2].jpg
14 KB, 480x360
>>54751060
>learn JavaScript first or something?
Yes.
>>
>>54751060
Fellow EE here

Don't worry. Most EEs are absolutely retarded about programming for some reason. You'll fit right in in the industry.
>>
>>54751085
see my correction >>54751043
I kind of mixed up the variables I was using
>>
>>54751060
You're not going to get it instantly, it takes some practice to internalize a language. But keep going at C, you don't have to master it just understand how programming works. Also, don't expect to be able to program without having to look at references constantly, nobody remembers every single language's syntax and standard library by heart.
>>
File: sumform.png (29 KB, 576x256) Image search: [Google]
sumform.png
29 KB, 576x256
>>54750839
The inner loop gets evaluated i times with i from 1 to n - 1. So it's pic related which is a known sum ("Kleiner Gauß" sum_{ i = 1 }^n = n(n+1)/2 ).
>>
>>54751153
>nobody remembers every single language's syntax and standard library by heart.
False! I am superiorly aware of my own Scheme's internal implementation and standard library, as well as of its beautiful, elegant & simple syntax.
>>
>>54751060
C is where you begin to study the languages as a real man. Python and JS are for babies.

Also, get Kochan.
>>
>>54751195
Reread what I wrote
>nobody remembers EVERY single language's syntax and standard library by heart.
>>
>>54751060
Ask someone for help.
>>
>>54751195
>my scheme implementation is "every single language"
Why are schemers so illiterate?
>>
>>54751195
learn haskell dude
>>
Where can I read about what visual studio puts as its default clear values for debug?
I get:
îþîþîþîþîþîþîþ
and I think I'm having a heap corruption and VS is being most unhelpful, only giving me a (very) small piece of assembly and a pointer to where the illegal access was.

Not sure how to debug this properly..
>>
int main(void)
{
_Static_assert(__alignof__(long) > __alignof__(char), "non-pathological");
(void)(long *)__builtin_assume_aligned((char *)__alignof__(char), __alignof__(char));
// Why doesn't this trigger any warnings?
}
>>
>>54751244
>>54751246
Well, of course no one knows every single language's syntax (because many "languages" - most of them, in fact - are not even worth knowing in the first place), so that's not an interesting fact to discuss. I'd rather discuss whether or not it's possible to know an entire language and at least an implementation by heart, and it turns out that it's possible for some languages (real languages) and impossible for others (Cshit, Cshit++, etc)

>>54751262
Don't you ever fucking quote my posts again if you're going to talk of that meme language
>>
File: 2016-05-26_11-03-36.png (135 KB, 540x960) Image search: [Google]
2016-05-26_11-03-36.png
135 KB, 540x960
How do you /g/uys feel about this
>>
>>54750606
>Prolog isn't even the only or even the best logic programming language

I didn't say either of those things. Learn to read.
>>
>>54751279
Ok so I found that it's a procedure in nvogl32.dll.
So I'm probably doing something wrong with my vertex buffer.
No worries dudes. I got this.
>>
>>54751399
just read a book, nigger. apps for learning stuff are never good.
>>
File: evil.webm (2 MB, 640x256) Image search: [Google]
evil.webm
2 MB, 640x256
/dpt/-chan, dai suki~

Ask your much beloved programming literate anything (IAMA).

>>54750649
It has been proved that prolog is a dead end (by the fifth computer generation project and by the guy who invented the actor concurrency model).

>>54750649
>What's the best one?
https://www.mercurylang.org/
>>
>>54751503
>actor concurrency model
That's literally just Scheme, f'am.

t. The Sussman
>>
What's the deal with cmake
>>
>>54751311
// This is OK too.
(void)(long *)(void *)(char *)__alignof__(char);

GCC is trash.
>>
>>54751318
laughingbitches.jpeg
>does not know haskell
>>
>>54751073
wtf dude
just use Atom, vim, vs code, emacs, etc

vs code provides intellisense
>>
>>54751409
OP didn't as about your opinion on Prolog either your insufferable faggot.
>>
>>54751554
Why would I waste my time learning a shitty meme language? If I really needed to get my ML fix, I'd use OCaml, thank you very much.

Now shoo, shoo memeposter!
>>
How's IronPython, PS a shit
>>
>>54751399
Great way to sell your shitty habits to advertisers, just to learn syntax
>>
What if I want a job OP?
>>
>>54751553
>GCC is trash.
>implying you could right a compiler

shyddydoo
>>
>>54752523
it's probably easier than you'd think even for a full-fledged compiler
>>
>>54752523
Most CS degrees teach you how to write a compiler
>>
File: poo-en-java.jpg (114 KB, 429x629) Image search: [Google]
poo-en-java.jpg
114 KB, 429x629
>>54750726
So the OOPfags apparently created their own thread lmao
>>
>>54753036
kys
>>
If I have a program where I don't free malloc'd memory before exiting, when it exits, is the memory that was allocated available to the OS again?
>>
>>54753070
depends on the OS but yes
>>
>>54753070
yes
>>
>>54753070
no, it's lost forever; don't do it, or you'll have to buy more rams
>>
>>54753070
no you have to start up the program and free up the memory for it to ever be available again
>>
>>54753070
Yes.
>>
>>54753070
Yes. The kernel knows what memory every process has allocated and will free it automatically once the process is terminated. However, you should still force yourself to free every allocated bit of memory as soon as possible. Once your program becomes some subroutine of a bigger program you will fuck things up and leak memory like a motherfucker.
>>
>>54753093
Basically any OS except DOS does this
>>
>>54753149
>Once your program becomes some subroutine of a bigger program
cucked hard
>>
Niggas I need some help with R I also asked /sci/ and /sqg/ but no help so far:

Anyways I saved a lot of data frames in nested lists.
I know I can access my values with mylist[[1]][[1]][2,2]
for the value in cell 2,2 but I wanna save all [2,2]s of all nested list as a vector or list in a variable.
How do I do this?
With normal lists I'd do this
variable <- sapply(list, `[`, 2, 2)

but that doesn't work so uh now what?

Also one guy on #R gave me this is a tip
sapply(list, function(x) sapply(x, function(y) { func of y } ))

but this doesnt work nor do I understand this
>>
>>54751649

Learn how to write.
>>
>>54753149
>However, you should still force yourself to free every allocated bit of memory as soon as possible.
No, you should do it as late as possible (preferably not at all if you can get away with it) because freeing memory is a very costly operation.
>>
>>54753171
Don't talk to me or my child process ever again.
>>
>>54750565
Racket lisp implemented Prolog, Datalog, a lisp-like Prolog called Parenlog, and Kanren. Racket treats languages as libraries and modules, which means you can freely intermix purely logical modules of code with regular Lisp code in your preferred style.
>>
>>54753248
lisp is truly God's gift to mankind
>>
>>54753213
Well, okay, assuming available memory is not a problem then of course. But you should really free it yourself or you might regret it sooner or later.
>>
>>54753213
How and why?
>>
>>54753328
Not that anon, but freeing and allocating memory involves asking the kernel to free and allocate memory. That takes some time. So you always want to keep the number of mallocs and frees as low as possible. I.e (just assume this example makes any sense)

const size_t N = 100;
int *test[N];

for ( int i = 0; i < N; ++i )
{
test[i] = malloc ( sizeof ( some_struct_t ) );
some_function ( test[i] );
free ( test[i] );
test[i] = NULL;
}

That is shit. Better is:

const size_t N = 100;
int *test = malloc ( N * sizeof ( some_struct_t ) );

for ( int i = 0; i < N; ++i )
some_function ( test[i] );

free ( test );
test = NULL;


It seems obvious here to do latter, but it may not seem obvious otherwise. So it's not really about when you allocate and free but how often you allocate and free. If you have a large chunk to free at the beginning of a program that you won't need further, then you should of course free it however. Makes no sense to keep it allocated then.
>>
>>54750649
It's easy as shit to program AI in it. Also it's easy do deal with linguistics in this manner.
>>
Is it wise to learn Haskell for fun and C++ for work?
>>
>>54753618
Yes. Learning haskell makes you a better c++ programmer
>>
>>54753618
It is wise to learn everything you like and as much as you can, but keep in mind that you also have to organise your time.
>>
>ImportError: /usr/lib/python3.5/site-packages/nacl/_sodium.cpython-35m-x86_64-linux-gnu.so: undefined symbol: crypto_sign_ed25519_pk_to_curve25519

Wat do?
>>
>make a program that uses only ints
>get a floating point exception

why does literally everything in my life only get worse
>>
I understand that asm.js is purely for writing the algorithmic part of your application because there's no way to interact with the dom, but how are you supposed to interact with the js part?

Do I have to cook up some shit-tier message passing system?
>>
>>54753652
The best course of action would be to kill yourself.
>>
>>54753641
Is this a troll?
>>54753648
Yes, which is why I decided on only Haskell and C++.
>>
Using Powershell is literally like hammering nails into your balls. I'm trying to return a string from a function and it gives me the object type
>>
>>54753892
Man, you're bad at this. Read there manual or spend five minutes reading a tutorial.
>>
>>54753915
Yeah, read a tutorial to figure out why my function can't just return my string
>>
>>54753892

Are you, or are you not, using the appropriate attributes?
>>
>>54753652
Figured it out, had to uninstall PyNaCl, install libsodium systemwide and reinstall PyNaCl with SODIUM_INSTALL=system pip install pynacl
>>
>>54753213
No, you should use a modern language that doesn't require you to manually allocate memory
>>
>>54751503
Why do you always get rekt so hard? >>54750386
Are you simply retarded?
>>
NEW THREAD WHEN?
>>
imagine i have this function


int test(int array[4], bool flag);



can i pass the array in the argument when calling ?
like

test({1,2,3,4}, false);



?
>>
>>54753933
If you don't know how to do that, then yes, obviously.
>>
>>54754113
no, this isn't javascript.
in C, arrays and functions are not first class, you have to pass them as pointers.
>>
>>54754139
>class
C has no classes, dip
>>
>>54754113
int test(std::array<int, 4>, bool flag);
should work
>>
>>54754113
int test(int *array, char flag);
...
int arr = {1, 2, 3, 4};
char flag = 0;
test(arr, flag);
>>
>>54754162
https://en.wikipedia.org/wiki/First-class_citizen
>>
>>54754162
not what he meant by first class
>>
>>54754178

You are being baited.
>>
>>54754181
how's the .22 rifle ?
>>
>>54754113
Sure thing buddy.

#include <utility>

void test(const std::initializer_list<int> &array, bool flag)
{
}

int main(int, const char **)
{
test({1, 2, 3, 4}, false);
return 0;
}
>>
>>54754195
doesn't have static length
>>
Do you think employers would notice me more if I wrote my CV in LaTeX or should I just use Europass like everyone else.
>>
>>54754203
np
#include <utility>

template <int a, int b, int c, int d>
void test(bool flag)
{
const std::initializer_list<int> array{a, b, c, d};
}

int main(int, const char **)
{
test<1, 2, 3, 4>(false);
return 0;
}
>>
File: 1463243363534.jpg (24 KB, 319x283) Image search: [Google]
1463243363534.jpg
24 KB, 319x283
>>54754192
>>
>>54754234
>>54754163
>>
File: melonbread.webm (2 MB, 960x540) Image search: [Google]
melonbread.webm
2 MB, 960x540
>>54754113
Yes

test( (int[4]){1,2,3,4}, false );


>>54751526
Yes, Scheme has been heavily influenced by the actor model.

https://en.wikipedia.org/wiki/History_of_the_Scheme_programming_language#Carl_Hewitt.2C_the_Actor_model.2C_and_the_birth_of_Scheme
>>
>>54754234
>>54754195
can you do the same thing in C?
>>
>>54754269
No.

Go back to >>>/wdg/
>>
>>54754269
No, C is obsolete and not really useful anymore outside of a few niches, which it's not even good at, just useful due to the lack of alternatives.
>>
>>54754268
this tho >>54754056
>>
>>54754295
t. webdev
>>
>>54754294
>>54754295
suck my big fat dick NEETS
>>54754268
thanks!
>>
>>54754309
well memed my friend
>>
>>54754268
warning: ISO  forbids compound literals [-pedantic]
>>
>>54754269
Sure.

#include <stdio.h>

double sum_of_four ( double array[4] )
{
return array[0] + array[1] + array[2] + array[3];
}
int main ()
{
printf ( "%f", sum_of_four ( ( double[] ) { 1.0, 2.0, 3.0, 4.0 } ) );
}

It's not pretty, but it works.
>>
>>54754127
How about MS makes it so that functions aren't retarded and return the string I explicitly want to return
>>
>>54754361
Wait, you can pass array literals to a function directly?

Can I do the same with function pointers?
>>
>>54754361
you forgot the spaces around the array indices tho
>>
>>54754361
 warning: ISO forbids compound literals [-pedantic] 
>>
>>54754392
turn off -pedantic
>>
File: testover.webm (3 MB, 684x385) Image search: [Google]
testover.webm
3 MB, 684x385
>>54754332
Update your compiler.
>>
>>54754417
>>54754403
my compiler its pretty old (C90) , but will this generate a waring in modern compilers?
>>
File: skilled.webm (3 MB, 720x404) Image search: [Google]
skilled.webm
3 MB, 720x404
>>54754387
No because a procedure in C is not an expression.

>>54754459
No, compound literals are standard since c99.
>>
tfw after becoming an expert in c/c++ you move to go and rust and your quality of life significantly improves.

i regret nothing.
>>
Press F12 and paste this into your JS console.
Post results.
  addEventListener("keydown", function(event) {
if (event.keyCode)
document.body.style.background = (event.keyCode % 2) ? "red" : "blue";
});
addEventListener("keyup", function(event) {
if (event.keyCode)
document.body.style.background = "";
});
>>
>>54754555
you weren't an expert in the first place
>>
File: 3.png (45 KB, 1366x305) Image search: [Google]
3.png
45 KB, 1366x305
>>54754559
>>
>>54754568
i was though
>>
>>54754555
>tfw after becoming an expert in c/c++ you move to go and rust and your quality of life significantly improves.

How do you deal with the fact that nothing ever compiles? The error messages are good, but still...
>>
>>54754609
You gain intuition eventually and won't try to compile shit that simply wont work.
>>
>>54751060
C is pretty brutal, what were the mistakes? Don't feel too bad going for something babby-tier first to warm you up

>>54752523
>right

>>54753093
depends on the malloc implementation actually

>>54753717
>doing division
>not learning about type promotion

>>54754113
language?
>>
>>54754683
>language?
C mostly.
>>
>>54754683
>>not learning about type promotion
explain?
>>
I'm trying to implement the method that adds to the front of a deque.
Given these data members:
private:
struct DequeNode {
Object item;
DequeNode *next;
DequeNode *prev;
};
DequeNode *front;
DequeNode *back;


I wrote this for adding to the front:
template <class Object>
void Deque<Object>::addFront(const Object &obj) {// add a new node to front
DequeNode toInsert; // Is this not how I make a struct object?
toInsert.item = obj; // Put the obj in the item to be inserted.
toInsert->prev = front->prev; // have toInsert prev point to front's prev.
front->prev->next = toInsert; // The item that was pointing to front now points to toInsert.
front->prev = toInsert; // front's prev now points to toInsert.
toInsert->next = front; // toInsert now points to the front.

}


I'm not sure how to make a struct object.
>>
>>54754863
deque is implemented as a vector of vectors

#include<iostream>

using namespace std;

class dequeue {
friend ostream & operator <<(ostream &os,dequeue &d);
public:
dequeue(int size); //constructor
~dequeue(){ delete [] storage; } //destructor
void push_front(int data);
void push_back(int data);
int pop_back();
int pop_front();
int & dequeue::operator[] (int index);
private:
int size;
int curr_front,curr_back;
int * storage;
};

dequeue:: dequeue(int size){
curr_back=curr_front=0;
// curr_back=curr_front=size/2; // some issue here...i don't get it!
//curr_back++;
storage = new int [size];

}

void dequeue:: push_front(int data){
storage[curr_front]=data;
curr_front++;
}

void dequeue:: push_back(int data){
storage[curr_back]=data;
curr_back--;
}

int dequeue:: pop_front(){

int x = storage[curr_front];

storage[curr_front]=x;
}

int dequeue:: pop_back(){

int y= storage[curr_back];
storage[curr_back]=y;
}
int & dequeue::operator[] (int index)
{
if(index < 0 || index >size)
cout<<"Error \n";
else
return storage[index];

}

ostream & operator <<(ostream &os,dequeue &d)
{
int i;
os << "[ ";
for(i=0; i<d.size; i++)
os << d[i] << " ";
os << "]" << endl;
return os;

}

int main(){
cout<<"This is a Dequeue implementation \n";
dequeue q_obj(4);
q_obj.push_front(1);
q_obj.push_front(2);
q_obj.push_front(3);
q_obj.push_back(7);

return 0;
}
>>
>>54753513
that example isn't good, you're doing two different thing's in each snippet. in the first you are creating a list of int pointers. each needs to be allocated separately. in the second, you are allocating a list of ints.

pls revisecand resubmit ur example :)
>>
File: Burd_06b1ee_5593782.jpg (41 KB, 337x498) Image search: [Google]
Burd_06b1ee_5593782.jpg
41 KB, 337x498
>try to use new library
>code crashes
>open source file and view the function code
>throw std::exception("Not implemented.");
worse than hitler
>>
You know what really grinds my gears?
People on Github who intentionally name the readme file "README.txt" instead of "README.md" so it wouldn't get processed into good-looking html.
>>
>>54754929
Ah, sorry, I wasn't clear. My hw assignment (let me know if this thread isn't for my school crap) is based off of deque that is not apart of the C++ libraries/classes. So, the instructors implementation is a linked list where there's a front and back that point to null, and everything gets inserted between.
The constructor:
template <class Object>
Deque<Object>::Deque() {
front = back = NULL;
}

>>
Anyone have experience with Boost.Asio?

I have a function that invokes async_read and uses a deadline_timer to handle a timeout.

After calling async_read the timer is handled this way:
readTimer.cancel();
readTimer.expires_from_now(boost::posix_time::seconds(Connection::ReadTimeout));
readTimer.async_wait([this](const auto &error) {
this->onTimeout(error);
});


The problem is that async_wait for some reason kicks off immedietely after the first packet is received. If I comment out the line that calls onTimeout function, I receive all the data properly. I'm not sure what's going on here, any ideas?
>>
>>54754983
They're writing plaintext, not your fancy gitcuck webdev markup language
>>
>>54752523
gcc writers are sadists, even linus hates them
>>
>>54755013
It's meant to be readable in plain text, yet beautiful when compiled to HTML.
>>
Python:
def pprint(string):
''' Print a string without creating a new line. '''
sys.stdout.write("\r%s" % string)
sys.stdout.flush()


\r enables me to print on the same line, but is there a way to guarantee that anything printed after this will be placed on a new line without breaking the functionality of the function?
>>
>>54755026
Programmers don't give a shit about "pretty" repo pages.
Have you ever noticed that only webdevs partake in bikeshedding everything about their computer experience instead of writing code?
They'll rice out their text editors, their command lines, rice out their repos, bog down their websites with fancy effects, etc.
>>
File: 1380497434131.jpg (44 KB, 500x276) Image search: [Google]
1380497434131.jpg
44 KB, 500x276
>going to graduate in 3 months
>applying for jobs
>2 weeks in
>no calls
>2 emails saying companies are looking elsewhere
>don't know what the fuck I am doing wrong

I have talked with company managers and friends and they have said my resume is quite good but 2 weeks in and I haven't gotten anything.

Should I start panicking? How do I deal with this despair?
>>
>>54755045
Maybe something like this:
nl = False

def pprint(string):
''' Print a string without creating a new line. '''
sys.stdout.write("\r%s" % string)
sys.stdout.flush()
nl = True

def lprint(string):
if nl:
sys.stdout.write('\n')
nl = False

sys.stdout.write(string)
sys.stdout.flush()


Then use lprint instead of print.
>>
>>54755071
That's true, but it doesn't mean that plain-text is better than formatted HTML in this situation.
>>
>>54754403
yeah, fuck ISO right?
>>
is there aany fun useful things i couls program while at work? i have mothing to do and most of my work is automated and i just need something to write.

preferably not some useless 1st year undergrad toy
>>
>>54754113
test((int []){1,2,3,4}, 0);

c99
static int x[] = {1,2,3,4};
test(x, 0)

c90
>>
>>54755113
An OS
>>
>>54755097
ISO C is defined by the current C standard which is C11

His compiler is outdated.
>>
>>54755091
Thanks, that's a good idea. Is there any advantage to
sys.stdout.write('\n')

over just using print\nstring?
>>
>>54755153
Not really I just wrote it that way to keep it consistent with pprint.

>>54755001
Also I solved the issue, apparently when a deadline_timer is rescheduled or cancelled, it will call the timeout with asio::error::operation_aborted error code, which should be handled explicitly and not close the connection.
>>
>>54755013
yo kill urself pls
>>
Is there a bitwise operation that can be performed on 2 bytes of data that would increase its size to more than 2 bytes, and can be reversed to get the original 2 bytes back?
>>
>>54755233
bitwise shift left?
>>
>>54755233
short s = 10;
int i = s & 0xffff;
>>
>>54755253
yeah...
>>
>>54755233
I have to ask. Why on earth would you want to increase the amount of space your data takes up for the sake of taking up more space? Casting is probably faster than bitwise.
>>
>>54755153
>>54755188
>>54755091
>>54755045
hard mode: is it possible to roll this into one function and prevent double newlines?

I

want

to

avoid

this

but also not have two separate print functions if I can avoid that. Would be nice to just call pprint("string", newline=False) or similar
>>
>>54755296
casting isn't a runtime operation.
>>
Haskell's a great language and all, but it has its limitations. It is unlikely to get full dependent types for a long time. Its effect model is too coarse. It makes no distinction between total and non-total functions.

Which language is best placed to succeed it?
>>
>>54755233
I don't really get the question.
Any operation which doesn't lose any bits would work just as if it was 2 bytes to 2 bytes, adding more bytes in the intermediate result would just consist of padding bits which you can do whatever you want with.
>>
>>54755077
>2 weeks

Nigga start panicking after six months, Jesus. Do you also have a snazzy portfolio?
>>
>>54755296
I don't think I would ever want that.

I'm working with an undocumented file type and I have 524 bytes of data where I was expecting 180. I'm just trying to figure out what the hell they did to enlarge the data. I'm assuming it's some kind of bitwise related encoding process.
>>
>>54755275
why & 0xffff;
also, sizeof(short) not necessary 2.
>>
>>54755388
It could be literally anything, maybe not even any arithmetic or bitwise at all, just extra bytes they pulled from anywhere.
>>
>>54754268
Nichijou a best.
>>
File: 1462237046270.jpg (92 KB, 500x543) Image search: [Google]
1462237046270.jpg
92 KB, 500x543
Making the switch from community college to university to get a CS degree, what kind of math should I self study this summer so I'm prepped? I spend my summers away from home and don't have much opportunity to program/do math so I try my hardest to stay up to date.
>>
>>54755335
https://raw.githubusercontent.com/wrvc/etc/master/loading-bar.c

this might (not) help
spaghetti overload
>>
>>54755452
Proof by induction, even if you do nothing else.
>>
>>54755338
I'm pretty sure you can turn a 2byte in to a 4byte int at run time.
>>
>>54755388
it's probably a header and some metadata type stuff.
>>
>How is Lisp for logic programming btw?
Check it out
http://minikanren.org/
>>
>>54755338
yeah dude, ints are magically turned into floats and vice-versa during the runtime.
>>
>>54755502
int short_to_int(short s)
{
return (int) s;
}

short s = 500;
int i = short_to_int(s);
>>
File: retardedd.png (11 KB, 470x169) Image search: [Google]
retardedd.png
11 KB, 470x169
url = '4chan.org/g/'

base_url = re.match(r'\bhttps?://[^/]+', url).group(0)
resp = urllib2.urlopen(url)
soup = BeautifulSoup(resp, "html.parser")
for link in soup.find_all('link', href=True):
cssPath = str(link['href'])
print base_url + cssPath
cssFilename = re.match(r'\w+', cssPath)
print cssFilename

This returns absolutely nothing and I have no idea why? I am only trying to scrape off the filename for the CSS file but for some reason it doesn't even want to match a word.

I've confirmed with pycharm that cssPath is a valid string which contains data but for some reason beknown to me it doesn't want to match anything. Can anyone tell me why?
>>
>>54755538
>>54755541
FUCKING MAGNETS
>>
>>54755616
maybe yo uhave to wget it
>>
>>54755391
>also, sizeof(short) not necessary 2.
wow youre a real whiz kid have a sticker

what is it with bad c programmers and pedantism?
>>
>>54755464
this works. amazing stuff
>>
>>54755655
not pedantic, your code is simply wrong.
>>
>>54755642
I'm only trying to regex the filename, there is no rule which suggests that this is not permitted?

It worked for getting the title, I just can't get over this and why it won't work this way, there's no legitimate reason to why this isn't matching ANYTHING
>>
>>54755621
It's actually quite simple:

#include <stdio.h>
#include <stdint.h>

int main(int argc, char **argv) {
int i = 10;
float j = *((float*)&i);

float k = 10.0;
int32_t l = *((int32_t*)&k);

printf("%f, %d\n", j, l);

return 0;
}
>>
>>54755680
do you think that guy would ask a bitwise question he could google in 5 seconds if he was intending to write for a 1980s mainframe?
>>
>>54755680
not my code, also, it's correct
>>
>>54755709
there are many DSPs where a byte is 32 bits. you should know that.
>>
>>54755708
RUN TIME CASTING?
ABSOLUTE MADMAN
>>
>>54755734
i dont do embedded chips
i didnt know that

but still maybe you (?) should look at the documentation before asking here
>>
>>54755708
that's not casting, that's aliasing and it's undefined behavior when it's done with incompatible types. learn your c.
>>
>>54755739
>>54755774
It's more efficient.
>>
File: cake.webm (447 KB, 900x506) Image search: [Google]
cake.webm
447 KB, 900x506
>>54755708
Undefined behavior :P

>>54755734
>>54755709
Unicos's short were 64 bits :3
>>
>>54755828
It works on my machine, matey.
>>
>>54755774
i dunno it looks like those pointers are getting cast
>>
>>54755723
#include <stdint.h>
#include <stdio.h>

#define X(x) _Generic((x), \
int: "int", \
short: "short", \
default: "unknown")

int main(void)
{
printf("%s\n", X((short){1} && 0xFFFF));
}

try it n00b
>>
>>54755923
mind the extra ampersand... doesn't matter since every op is the same
>>
i'm gonna need a little bit of help over here
>>
>>54755452
Look at the CS curriculum at the university you're transferring to (required courses, prerequisites). I'd worry more about the programming side of things myself.
>>
>>54755655
>waaaaaaaaah
>why do you prove I'm a retard
>I cam here for animu tho
end yourself you shit
>>
>>54755987
Easy enough
>>
>>54755987
you have to be careful for loss of precision

this is the kind of shit that fucks me up cos i have no, none, nil, knowledge of numerical analysis
>>
>>54755828
where were you when you got raped, m80?
>>
>>54756033
what? i don't understand
>>
>>54755987

Simply not possible. Averaging two (2) numbers is already enough of an ordeal.
>>
>>54756063
>I'm literally retarded
we can tell
>>
>>54755338
Depends on the cast.
>>
>>54756073
Assuming he's using C of course
>>
>>54756075
sorry i don't speak 4chan piss baby
>>
>>54755338
it can
>>
>>54755987
int avg(int *arr, int n)
{
int result = 0;
unsigned i;
for (i = 0; i < n; i++)
result += (float) arr[i] / n;
return result;
}


:3
>>
There was a website that had communist stuff on it where you could learn C++ and other languages. What was it again? I can't remember and I don't have it bookmarked.
>>
>>54756095

I imagined that's what he was using. He should just use Scheme instead.
>>
>>54756100
>DELETE THIS
:^)
>>
>>54756119
>average of 1 and 1 is 0
just end yourself, webshit
>>
>>54756120
I am interested in that too, even tho I hate communism but I am learning C++ right now
>>
>>54756120

Like communism, it probably failed.
>>
>>54755987
int average(int a, int b)
{
return (a & b) + ((a ^ b) / 2);
}

int average_array(int *arr, int size)
{
if (size <= 0) return 0;
if (size == 1) return *arr[0];
if (size == 2) return average(*arr[0], *arr[1]);

int sum;
int count=0;

while(size-=2)
{
count+=2;
int i = average(*arr[count-2], *arr[count-1]);
sum = average(sum, i);
}

return sum;
}
>>
>>54756194
>>54756119
doesn't work with max_int
>>
>>54755987
  def average(ints: List[Int]): Double = {
if (ints.isEmpty) sys.error("List is empty")

val tolerance = 1e-8d

@tailrec
def iterate(lower: Double, upper: Double): Double = {
val guess = (lower + upper) / 2d
if (upper - lower < tolerance) guess
else {
val error = ints.foldLeft(0d)((result, next) => result + (next - guess))

if (error.signum == 0) guess
else if (error.signum < 0) iterate(lower, guess)
else iterate(guess, upper)
}
}

iterate(ints.min, ints.max)
}
>>
>>54756194
dude what happens if size is odd?
>>
>>54756288
program is kill
>>
>>54751318
>impossible to know C by heart
Fuck off retard
>>
>>54755335
You might be able to hack your way around it by having the non-newline-printing function pad the line out to $COLUMNS, so that you can still \r back to the start of the line, but anything printed after will be a new line.
>>
>>54755987
average = lambda *n: float(sum(n)) / len(n)

:^)
>>
File: 000.png (40 KB, 423x203) Image search: [Google]
000.png
40 KB, 423x203
>>54754863
Same fag. Ignoring that garbage, and on to new exciting stuff.
How do I change what a pointer points to?
deque.cpp.h:59:9: error: cannot convert ‘Deque<int>::DequeNode’ to ‘Deque<int>::DequeNode*’ in assignment
front = toInsert;


front is a pointer that is set to NULL in the beginning.
Now I want it to point to toInsert.
I tried doing:
*front = toInsert;


But that gives me segmentation fault.
>>
>>54756368
Perhaps you should get back to basics to refresh your knowledge up before you attempt to implement a deque, huh?
>>
>>54755616
Don't use urllib directly unless you really need to, use requests.
>>
>>54755616
the regex in your screenshot is wrong, it's \w not /w
>>
>>54756130
lol
>>
>>54756388
I was never taught pointers. First classes were taught in Java, and this one is in C++ and this class "is meant to be a fast-paced course to prepare you for higher level CSS classes."
But I'm not going to take higher level CSS classes, not my major.
>>
>>54756258
What the fuck is this?
>>
>>54756441
Well in that case the problem is that when you do *front and it's NULL, you're dereferencing a NULL pointer.

You can do it this way:
front = &toInsert;

However if toInsert is a temporary so it leads to invalid address.
>>
>>54755987
Move over you bunch of fucking pajeets:

#include <stdlib.h> /* for div() */
int avgn(int *nums, size_t n) {
int total_quot = 0;
int total_rem = 0;
int i;

for (i = 0; i < n; i++) {
div_t dm = div(nums[i], n);
total_quot += dm.quot;
total_rem += dm.rem;
}

return total_quot + total_rem / n;
}
>>
>>54755987
int average ( const int *numbers, const int N )
{
int value = numbers[0] / N;
int error = numbers[0] % N;
for ( int i = 1; i < N; ++i )
{
value += numbers[i] / N;
error += numbers[i] % N;
}
return value + error / N;
}
>>
>>54756508
nice code
i like it
>>
>>54756476
Oooohh, now we're rolling.
By doing & I'm saying front points to toInsert's address, yes?
And it wouldn't make sense to point to the value of toInsert, because then there would be no real connections in the data structure. Like, the locations of the objects wouldn't be known, just the values. I think.
I feel like I said that like a retard.

Thank you, though, I appreciate your patience.
>>
>>54755987
it's simple, just use your C program to launch a java program and average them there
>>
File: paradigms.png (25 KB, 800x800) Image search: [Google]
paradigms.png
25 KB, 800x800
>>
>>54756592
Where do F* and Idris lie on that chart?
>>
>>54756610
Way in the top right.
>>
>>54756592
procedural and imperative are the same thing
ocaml has oop
>>
>>54756592
Why is Haskell procedural?
>>
>>54756639
>procedural and imperative are the same thing
Not really. Procedural is a much more useful term if you use it to mean code where data and logic are separated (which is the opposite of OO).

>ocaml has oop
Yes, hence why it's more to the centre.

>>54756645
^
>>
>>54756645
Because that anon is ignorant.
>>
>>54756668
>Procedural is a much more useful term if you use it to mean code where data and logic are separated
No. Procedural means that it uses procedure. And procedure are "functions" with side effect.

Anon, you're ignorant. STFU
>>
>>54756686
Why even have the term "procedural" when it's nearly synonymous with "imperative"? Take the parts that are identical to "imperative" out, and you're left with that.

Alternatively, what's a good term for "data and logic separated"?
>>
>>54756194

Why divide by 2 instead of shift right?
>>
>>54756700
>Why even have the term "procedural" when it's nearly synonymous with "imperative"?
It's not the first time that IT uses two identical words.
>>
>>54756704
Because there's no point making the code harder to read when the compiler makes that transformation for you anyways.
>>
>>54756704
because they're not the same thing
>>
>>54756723
That doesn't make it okay.
>>
>>54756700
>good term for "data and logic separated"?
Proper design and it is not related to OOP. If you think the opposite you must really suck at programming.
>>
>>54756733
I do not care. Procedural and imperative mean the same thing: language based on side effects. Don't argue, you're wrong.
Thread replies: 255
Thread images: 25

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.