Quantcast
[ 3 / biz / cgl / ck / diy / fa / g / ic / jp / lit / sci / tg / vr / vt ] [ index / top / reports / report a bug ] [ 4plebs / archived.moe / rbt ]

Due to resource constraints, /g/ and /tg/ will no longer be archived or available. Other archivers continue to archive these boards.Become a Patron!

/g/ - Technology


View post   

[ Toggle deleted replies ]
File: 454 KB, 1046x1500, x14.jpg [View same] [iqdb] [saucenao] [google] [report]
67828122 No.67828122 [Reply] [Original] [archived.moe] [rbt]

What are you working on, /g/?

Previous thread: >>67820193

>> No.67828145
File: 715 KB, 640x640, LIGHT_WEIGHT.webm [View same] [iqdb] [saucenao] [google] [report]
67828145

I have placed a curse on this thread

>> No.67828146
File: 44 KB, 636x616, 1474325315193.jpg [View same] [iqdb] [saucenao] [google] [report]
67828146

Employed Haskell programmer reporting in

>> No.67828163

>>67828146
What do you do? Why Haskell?

>> No.67828186

>>67828122
Daily reminder that wireless devices cause brain damage, endocrine dysfunction, DNA damage, and irreversible infertility.

>> No.67828208
File: 33 KB, 696x943, quak.png [View same] [iqdb] [saucenao] [google] [report]
67828208

Light themes are the best, but not too light!

>> No.67828251

First for vim is shit

>> No.67828375

>>67828186
Daily reminder /dpt/ causes irreversible death

>> No.67828422

>>67828375
Let us honor the memory of all fallen /dpt/-comrades we've lost along the way.

>> No.67828465

https://github.com/drujensen/fib
This github repo did 10 implementations of recursive fibonacci and has 150+ stars now.
How many stars has your most ambitious project gotten?

>> No.67828481

>>67828465
>github upvotes
who cares

>> No.67828742

>>67828208
Patrician taste

>> No.67828751
File: 127 KB, 700x2528, tu2.png [View same] [iqdb] [saucenao] [google] [report]
67828751

>>67828465
reminds me this. (pic)

>> No.67828790

>>67828122
Shamelessly bumping my question in the previous thread:
>>67827486

>> No.67828812

>>67828751
Any implementation other than the hackathon (jump table) is unacceptable.

Large company makes me shudder and feel all twisted up inside.

>> No.67828907

Last time I posted, I was studying for a Google phone interview.

Now, I'm getting flown out to a Google onsite interview. Studying for that rn

>> No.67829026

>>67828465
>>67828751
>current year
>still not learning how to solve fibonacci using a fibonacci matrix

>> No.67829110

Rate my C program, /g/.

%:include <stdio.h>
int main(argc,argv)
int argc;char*argv[];<%
int array[012:>;
for (int i=0;i<sizeof(array)/sizeof(array<:0]);++i){
i[array] = i;
printf("%s: %d\n", 0[argv], i[array]);
%>
return 0;
}

>> No.67829167

>>67829110
not valid

>> No.67829180

>>67829167
What isn't valid?

>> No.67829192

>>67828751
I'm working at a startup and I've noticed my code slowly transition from startup to large company mode. The math PhD one makes no sense, why would they prefer function notation to binary? t. Not quite math PhD yet.

>> No.67829223

>>67829180
i[array]

>> No.67829235

>>67828751
None of these scale very well for large n.

>> No.67829251

>>67829223
It's absolutely valid. i[a] and a both work in C.

>> No.67829254

>>67829223
That's valid C, n00b.

i[array] translates to *(i + array)
array translates to *(array + i)

As addition is commutative, those two are equivalent.

>> No.67829259

>>67829235
desu it is wrong to write things to be scalable and generic when they only have one limited use; look at the comment of the hackathon code

>> No.67829292

>gcc doesn't support destructors for classes that are thread_local in c++11

>> No.67829293

>>67829259
It can be written scalable and generic with less code than any of those examples.

public int getFibonacciNumber(int n) {
int[] fib = {1, 1, 2};
for (int i = 3; i < n; ++i) {
fib[i % 3] = fib[(i - 1) % 3] + fib[(i - 2) % 3];
}
return fib[n % 3];
}

>> No.67829306

>>67829293
It needed neither of those qualities, and now the
code looks worse.

>> No.67829323

>>67829306
>the code looks worse.
If you think any of those except the very first one looks "good", then I hope I'll never encounter your code in my life.

>> No.67829335

>>67829306
>>67829323
Also, where the fuck is it stated that none of those are needed?

>> No.67829385

>>67829323
I never claimed that. Don't make such baseless assumptions. Also the code you wrote is a totally niggerlicious way of doing fibonacci.

>>67829335
Look at the comment in the hackathon piece, it implies it doesn't need them given the context it is used it.

>> No.67829398

>>67828465
i have 3-4 ok projects of medium size i can upload on github but i'm afraid they might get stolen

>> No.67829413

>>67829385
>Also the code you wrote is a totally niggerlicious way of doing fibonacci.
Enjoy your stack overflow

>Look at the comment in the hackathon piece,
What kind of retard answer is that? Look at the comment in the enterprise edition.

You're just insanely butthurt you couldn't come up with a non-recursive method of calculating Fibonacci numbers, lol.

>> No.67829439

>>67829293
Just use the math one without the retarded redefining of basic operations, it's F(n) = round(phi^n / sqrt(5)), that's it.

>> No.67829456

>>67829292
what's the reason given?

>> No.67829459

All right. I have gotten tired of all the ridiculously complicated build systems.

A program should be able to build as gcc main.c deps/*.c -Ideps/.
To this end:
Projects which only produce one binary should name the .c source file containing the main() function either main.c or {name of binary}.c
Projects which produce multiple binaries should have one .c source file named after each binary in the root folder, which in turn include the needed headers.
Libraries must work both by #include and linking, unless they are header-only libraries, in which case the latter is optional.
This means that libraries must avoid defining the same identifier across multiple source files. Such identifiers should instead be put in a common header with an include guard. If this is not possible, the identifiers should be made locally scoped by a prelude which redefines them.
Example
#define id1 file_id2
#define id2 file_id2
#define id3 file_id3
...
#undef id1
#undef id2
#undef if3

All source code and header files must have include guards, with the exception of files that define a main() function, or which are intended to be included multiple times.
If the project contains a makefile, it should not require GNU make, nor should it be required to compile the project without taking more than a cursory look at the structure.

Did I miss anything?

>> No.67829461

>>67828751
math phd would be using matrices not the one with the golden ratio, because that one is actually slow

>> No.67829487 [DELETED] 

>>67829439
The funny thing is that it's not even correct (which I guess is part of the joke?)

It should be: F(n) = (phi - (-phi) * n) / sqrt(5)

>> No.67829488

>>67829413
>Enjoy your stack overflow
>You're just insanely butthurt you couldn't come up with a non-recursive method of calculating Fibonacci numbers, lol.

lmao, No I am not. This proves you wrong:
int fibonacci(int n)
{
int foo = 0;
int bar = 1;
int tmp;

while (n--) {
foo += bar;
tmp = foo;
foo = bar;
bar = tmp;
}
return foo;
}


It is a shitton better than your nigger solution½

>> No.67829498

#pragma once or good old header guard?

>> No.67829500

>>67829488
Your implementation of fibonacci(n) will return 0 for n=0, which is wrong retard.

>> No.67829515

>>67829500
By definition, the first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two. Some sources omit the initial 0, instead beginning the sequence with two 1s. For n = 0 it is clearly 0: F(0) = (1 - 1) / sqrt(5) = 0.Sep 20, 2009
In the Fibonacci sequence, is fib(0) 0 or 1 ? - Stack Overflow
https://stackoverflow.com/questions/1451170/in-the-fibonacci-sequence-is-fib0-0-or-1

>> No.67829521

>>67829498
#pragma once for your own stuff, old header guard if you're writing a library.

>> No.67829525

>>67821484
>>67826857
>no one here
Employed computational scientist, AMA.

>> No.67829539

>>67829488
>while (n--)
Pass in -1 to your function, and it now iterates until it wraps (undefined behaviour for signed ints).

Good job at making a "generic" solution....

>> No.67829540

>>67829487
No, both are correct.
(pow(phi, n)-pow((1-sqrt(5))/2, n))/sqrt(5) is equivalent to floor(pow(phi, n)/sqrt(5)+0.5f).

>> No.67829552

>>67829540
Yeah, I realized that after posting. Thanks for correcting me anon.

>> No.67829553

>>67829525
>scientist
hi have you considered quitting rather than continuing to endanger the human race

>> No.67829564

>>67829553
Not really. The only other field that may interest me at this point would be HFT.

>> No.67829575

>>67829525
>FEniCS
Simula faggot detected.

>> No.67829602

>>67829539
You should ensure valid arguments before calling the function.
>Good job at making a "generic" solution....
Never claimed to have done that. For that you would also need something like the java BigInteger

>> No.67829607

>>67829498
Pragma once can be trivially converted to header guard with a two line shell script.

>> No.67829618

>>67829602
A negative integer is a valid argument to something that expects a signed integer.

>> No.67829636

>>67829575
I've been found

>> No.67829643

>>67829618
I meant in the same sense that it is your job to ensure that you are not dividing by zero when dividing.

>> No.67829644

>>67829636
Yes, you have. It's stupid to post RL projects online, especially when you're boasting about your e-peen.

>> No.67829652

>>67829235
What about using binomial expansion and (1/2 + sqrt(5)/2)^n?

>> No.67829697

>>67829644
Next you're going to say you were merely pretending

>> No.67829734

>>67829697
Why would I say I'm merely pretending? I'm not the one boasting about working on FEniCS (which is a pretty done project by now tbqh).

>> No.67829754

>>67829456
#include <cstdio>

template <typename T>
class sample {
public:
sample()
{
printf("sample\n");
}

~sample()
{
printf("~sample\n");
}

public:
T member;
};

static thread_local class sample<int> mysample;

int main()
{
mysample.member = 10;
return 0;
}


g++
/usr/bin/ld: /tmp/cctQLO7o.o: in function `__tls_init':
sample.cpp:(.text+0x5b): undefined reference to `sample<int>::~sample()'
collect2: error: ld returned 1 exit status


clang++ just werx

>> No.67829778

>>67829754
Oh, it (gcc) needs -pthread to even use tls
That's why

>> No.67829817

>>67829734
>I'm not the one boasting about working on FEniCS
Where did I do that you mongoloid? Please spend more time focusing on your mouth-breathing and less on making retarded comments on 4chan.

>> No.67829833

>>67829817
>>67821484

The fact that you're getting mad and upset about this proves to me that I found you out.

>> No.67829857

>>67829618
>>67829602
>>67829643
You are retarded, a negative number is a valid argument since the general sequence is ...,-8,5,-3,2,-1,1,0,1,1,2,3,5,8,...

>> No.67829957

>>67829857
So in that case it should actually be:
int fibonacci(int n)
{
int foo = 0;
int bar = 1;
int tmp;

if (n < 0) {
int tmp = fibonacci(-n);
return (-n & 1) ? tmp : -tmp;
}

while (n--) {
foo += bar;
tmp = foo;
foo = bar;
bar = tmp;
}
return foo;
}

>> No.67829982

>>67829957
>(-n & 1)
Implementation specific behaviour. Into the trash it goes.

>> No.67830003

Where am I fucking up?
def MArray( i, j ):
#Produce an Array of size i, and dimensions j
#MArray(2,3)
#>>>[ ['1','2','3'], ['4','5','6'] ]
arr = [None] * j
arr2 = [None] * i

for c in range(len(arr2)):
for k in range(len(arr)):
arr[k] = input('enter your data')

arr2[c] = arr

return arr2

>> No.67830012 [DELETED] 

>>67828122
#include <stdio.h>

int main()
{
double a,b,c,a_2,b_2,ac_4,b2_ac4;
printf("Quadratic equation calc\n"
"a(x^2)+bx+c=0\n"
"Enter values for a b c\n");
scanf("%lf %lf %lf",&a,&b,&c);
printf("Displaying your values a=%lf b=%lf c=%lf\n",a,b,c);
printf("\n");
printf("x1= -b+sqrt((b^2)-4ac)\n"
" ----------------\n"
" 2a");
printf("\n");
printf("x2= -b-sqrt((b^2)-4ac)\n"
" ----------------\n"
" 2a");
printf("\n");
printf("\n");
//-------------------------------------------------------------
printf("x1= -(%lf)+sqrt((%lf^2)-4*%lf*%lf)\n"
" -------------------------------------------------\n"
" 2*%lf",b,b,a,c,a);
printf("\n");
printf("x2= -(%lf)-sqrt((%lf^2)-4*%lf*%lf)\n"
" -------------------------------------------------\n"
" 2*%lf",b,b,a,c,a);
printf("\n");
printf("\n");
//-------------------------------------------------------------
a_2=2*a;
b_2=b*b;
ac_4=4*a*c;
//-------------------------------------------------------------
printf("x1= -(%lf)+sqrt(%lf-(%lf))\n"
" --------------------------------------\n"
" %lf",b,b_2,ac_4,a_2);
printf("\n");
printf("x2= -(%lf)-sqrt(%lf-(%lf))\n"
" --------------------------------------\n"
" %lf",b,b_2,ac_4,a_2);
printf("\n");
printf("\n");
//-------------------------------------------------------------
b2_ac4=b_2 - ac_4;
//-------------------------------------------------------------
printf("x1= -(%lf)+sqrt(%lf)\n"
" --------------------------\n"
" %lf",b,b2_ac4,a_2);
printf("\n");
printf("x2= -(%lf)-sqrt(%lf)\n"
" --------------------------\n"
" %lf",b,b2_ac4,a_2);
printf("\n");
printf("\n");

return 0;

>> No.67830017

>>67829982
On which platforms does it not work?

>> No.67830020

>>67828208
Name?

>> No.67830027

>>67830017
Platforms that uses one's complement.

>> No.67830086

>>67830027
yeah well you just keep using your imaginary system, while I program for real hardware.

>> No.67830088

Any good resources for learning machine learning and deep learning in depth? I mean the actual math and algorithm creation.

The results I keep coming across keep saying just use these AI libraries, rather than actually learning the underlying technology.

>> No.67830101

>>67830088
it's a meme technology, if you have a brain get into something useful that isnt a fad

>> No.67830105

Or, you could just write % 2 like a sane person, and let the compiler handle your silly microoptimisation.

>> No.67830110

>>67830086
told

>> No.67830118

>>67830105
Was meant for >>67830086

>> No.67830127

>>67830020
of what?

>> No.67830140

>>67829982
>>67830027
I looked a bit at it again and I think you're wrong.
-n comes before the bitmask.

>> No.67830152

>>67830127
Theme you dum dum

>> No.67830157

>>67830140
You're probably right, but still you should do >>67830105 imo

>> No.67830163

>>67830105
>trusting the (((compiler)))

>> No.67830177

>>67829398
what are they about

>> No.67830179

>>67830163
Premature (micro)optimisations are the root of all evil.
- The D.

>> No.67830184

>>67830152
It doesn't have a name.

background: #CFCFCF
text: #000000
comments: #9E0C0C
strings: #009456

>> No.67830187

>>67830003
please help I have no idea why it's only indexing the last element of my outer array.

>> No.67830195

>>67830179
you just making your js apps with electron

>> No.67830211

>>67830187
Because [None] * j doesn't do what you think it does.

Do this instead:
arr = []
arr2 = []

for c in range(i):
for k in range(j):
arr.append(input('enter your data'))

arr2.append(arr)


Lists are not arrays.

>> No.67830225

>>67830195
I'm serious though, if you ever examined the assembly from your compiler, you'd realise that it does this """optimisation""" for you.

There is no excuse for writing non-portable code unless you're dealing directly with hardware (which you're not in this case).

>> No.67830226

>>67830163
>not trusting the compiler
Until you tell me how ROB, load/store buffers, instruction retirement and cache synchronization work you really don't know more than a good optimizing compiler does. Don't forget about register renaming and data hazards.

>> No.67830240

>>67830163
>programming without trusting the compiler
Let me guess, you're one of those people who write your own string functions too, because the standard library can't be "trusted", am I right?

>> No.67830255

i've been out of the loop for a while
can you give me an update on rust

is it more popular now
is it still fast

>> No.67830268

>>67830225
>>67830226
>>67830240
Get a loads this (((compiler dev)))

>> No.67830273

>>67830211
It's a step up, but not quite what I want to do since it copies my inner array to each element in the outer array.

>> No.67830278

How do I use SDL2 to stream to an indexed texture with a custom palette?

Here's the problem. There doesn't seem to be any way to access the palette of an indexed texture. You can create one, by passing an indexed pixel mode to SDL_CreateTexture, but since you can only pass the flag for the pixel mode, not the entire pixel mode data structure, you can't specify a palette.

You can create a texture with an arbitrary palette by first creating a surface with that palette (since there are functions available to freely manipulate the palette of a surface) and then using SDL_CreateTextureFromSurface. However, SDL_CreateTextureFromSurface is documented as always allocating and returning a static texture. I need a streaming texture. There also do not seem to be any functions for creating a texture from an existing texture, except SDL_RenderCopy[Ex] with a texture as the render target -- which would defeat the purpose, as neither pixel mode nor streaming mode would not be preserved, so in order to create an indexed streaming texture to copy to, I'd be faced with the same problem as before.

Pls. All I want is to directly manipulate the pixels on my 8-bit emulator.

Current workaround is to store the texture as RGBA8888, have a separate 8-bit indexed pixel array in static memory as well as a palette for it, and manually convert every pixel from indexed 8-bit to RGBA8888 every frame. This works but it would be more efficient to just have the texture itself be indexed 8-bit with the palette I want.

>> No.67830280

>>67830255
Still ugly, compiler still exceeds the 32-bit address space when being linked, still pushed by loud, insufferable people who ride on Haskell's coattails.

>> No.67830281

>>67828208
You are right about light themes being patrician, bul low contrast increases eyestrain

>> No.67830282

>>67830195
This but unironically

>> No.67830299

>>67830281
That's still good contrast.

>> No.67830315

How do I get good haskell integration with emacs?
I'm trying to setup haskell-ide-engine but it's not working. I'm on archlinux btw

>> No.67830329

>>67830315
Just get hlint and ghcid, you don't really need anything else

>> No.67830351

>>67830299
>black on grey
>contrast

>> No.67830360
File: 227 KB, 1582x2111, Screenshot_2018-09-29 regexp Go's regex is even slower than Python · Issue #26623 · golang go.png [View same] [iqdb] [saucenao] [google] [report]
67830360

Remember all the time I have been constantly bitching about Go - C FFI cost and no one gave a shit?

>> No.67830415

>>67830360
Yet still noone gives a shit

>> No.67830425

>>67830360
LOL I like how C# manages to come out as the bottom of the barrel Java's bitch every damn time

>> No.67830435

>>67830360
I'd have to know which of those are unicode aware before I give a shit.

>> No.67830436

>>67830351
You ain't seen nothing.

>> No.67830442
File: 143 KB, 500x855, 5C0348A0-6687-48E9-B3D0-214FEFC5F4DB.png [View same] [iqdb] [saucenao] [google] [report]
67830442

>>67830425

>> No.67830460
File: 610 KB, 1291x3600, 1534935983694.jpg [View same] [iqdb] [saucenao] [google] [report]
67830460

>>67830442

>> No.67830474

>>67830360
>I don't understand why Go has to use cgo to call C code
Is he fucking stupid or something?

Anyway, Go's regexp package was designed to deal with common-ish pathological cases where PCRE would start blowing up and taking years to complete, but it hasn't been optimized.

>> No.67830475

>>67830460
> counting other people’s money
good going sanjeev

>> No.67830479
File: 510 KB, 782x1238, bakabaka.png [View same] [iqdb] [saucenao] [google] [report]
67830479

>>67830442
Isn't that just a shittier copy of this meme? I mean C# is literally Microsoft Java, so the meme doesn't even make sense. Pot calling the kettle black.

>> No.67830481
File: 58 KB, 1000x1000, 1535935817856.png [View same] [iqdb] [saucenao] [google] [report]
67830481

>>67830475

>> No.67830500

>>67830481
>JS
Y
U
C
K

>> No.67830509

Dumb question but this has always confused me.


What do double pointers mean in C++?

If I do
int **A= 103

For instance.
Wouldn't that indicate the address for *A?

I mean whatever content is fit in **A would be the address for *A right?

>> No.67830525

>>67828751
>startup can't even write Fibonacci right in the end
lel
>math phd doesn't do exponentiation by squaring
cringe

>>67829461
You forgot to attach a frog picture, dumb frogposter.
Both use exponentiation so both can run in O(log(n)). The foremost reason it's stupid is because it uses doubles so it'll probably break down past F(70), while an int64 matrix holds up to F(92) and is guaranteed to give you the right answer for any value that doesn't overflow.

>> No.67830530

>>67830481
> tfw maining both C# and JS
I’ll be alright

>> No.67830531

>>67830509
real programmers use only three stars like int ***x;

>> No.67830538

>>67830525
>The foremost reason it's stupid is because it uses doubles so it'll probably break down past F(70)
yea it was something with the limitations of the hardware
it;s slower because you'd have to implement unlimited precision

been a while since i read algorithms, maybe i should brush up

>> No.67830539

>>67830509
pointer to pointer to something

address of address of value

int n = 123;
int *np = &n;
int **npp = &np;

printf("fuck my %d anuses\n", **npp);

basically the more indirection the more powerful your code is. there's no limit, you can only level up.

>> No.67830545

>>67830509
A pointer is a variable, and the value of that variable is a memory address. A pointer to an integer is therefore a variable that contains the address of an integer in memory.
int i = 3; // this statement reserves//allocates memory, and stores the value 3 in that memory
int* p = &i; // the value of p is the address of the memory location reserved/allocated by i.


A pointer-pointer to an integer would therefore be a variable that holds the address of a pointer to an integer.

int i = 3;
int* p = &i;
int** pp = &p;

>> No.67830549

>>67830509
It's a pointer to a pointer, just like it says on the tin.
>int **A= 103
is basically saying that the number at memory address 103 is a pointer to another address that actually has the int you want. This will of course segfault your app if you dereference it.

>> No.67830558

>>67830549
>This will of course segfault your app if you dereference it.
Depends on what's stored in address 103 and the permission of that memory segment.

>> No.67830559

>>67830003
you keep working on a single arr that you then save to arr2 at every index.
make a new arr=[None]*j in every iteration of your "c" loop

>> No.67830562

>>67830509
yep. its a pointer to a pointer.

int a = 5;
int *ap = &a;
int **app = &ap;
int p = *app; //val = &a
int val = **app; //val = 5

>> No.67830570
File: 33 KB, 600x569, Programming-Languages.jpg [View same] [iqdb] [saucenao] [google] [report]
67830570

>>67830442
>>67830475
>>67830500
SEETHING NEET lol

>> No.67830573
File: 21 KB, 601x2411, 1537531127481.png [View same] [iqdb] [saucenao] [google] [report]
67830573

>>67830179
>>67830226
>>67830240
&1 feels far more natural to me anyway. But you shouldn't trust the compiler.

>> No.67830574

brb taking a poop

>> No.67830579

>>67830570
I’m employed lol.

>> No.67830580
File: 25 KB, 480x394, brainlet-autism.jpg [View same] [iqdb] [saucenao] [google] [report]
67830580

>>67830573
>But you shouldn't trust the compiler.

>> No.67830587

Compilers are pretty clever, but not too clever. They will not replace a bubble sort with quicksort for example.

>> No.67830614

>>67830587
Obviously, but that's why we're talking about microoptimisations (such as bitfiddling), and not macrooptimisations (such as algorithms and data structures).

>> No.67830644

>>67830573
>&1 feels far more natural to me
Not an argument.

>But you shouldn't trust the compiler.
Portability > premature microoptimisations.

>> No.67830657

>>67830570
where's haskell? shouldn't it be on top?

>> No.67830661

>>67830573
use isodd(x)
I don't care if you #define isodd(x) ((x)&1) or make an inline function or a fucking template factory builder concept, just make that code easily readable.

>> No.67830662

>>67830657
Haskell is so popular, it's literally off the charts.

>> No.67830673

>>67830442
>C++
>cleanly designed

>> No.67830682

>>67830657
>implying the average poo or joe can grasp haskell
if haskell were on top it'd be a shit language

>> No.67830688

>>67830662

>> No.67830695
File: 8 KB, 442x500, 1538068292820.jpg [View same] [iqdb] [saucenao] [google] [report]
67830695

>>67830442
>beautiful and cleanly designed language
>Microsoft Java 2.0

>> No.67830703

Based Rust though

>> No.67830735

>>67830673
That’s C++++ though, aka C#

>> No.67830751

Why do compilers often xor a register before storing a value into it? Is it not pointless?

>> No.67830781

why would i ver choose ugly ass haskell over lisp

>> No.67830787
File: 71 KB, 645x729, brainlet3.png [View same] [iqdb] [saucenao] [google] [report]
67830787

>>67830735
fuck

>> No.67830791

>>67830751
to clean up before using it

>> No.67830810

>>67830781
Haskell is cleaner and terser than lisp

>> No.67830819

>>67830791
Look at this:
popcnt_native(int):
xorl %eax, %eax
popcntl %edi, %eax
ret

The popcntl replaces the value in eax, so zeroing it out is totally pointless
Just like the assignment to zero is pointless in this code:

int a = 0;
a = 10;

>> No.67830834

>>67830819
I don't know x86 but is it possible that the register width is different in these cases

>> No.67830836

>>67830751
If the operand size it's moving into the register doesn't trigger the upper bits to be zeroed automatically. XOR'ing a register on itself is zeroing itself.

>> No.67830847

>>67830819
that particular example looks pointless, yes. report it to the devs?

>> No.67830850

can anyone help a brainlet out? how the fuck does hash table work? how do you pass "john doe" to a function and get the guy's position on the index in return?

>> No.67830876

>>67830850
Using a hash function. A hash chews up some data - a string or whatever you like - and spits out an index. There's no guarantee that the index is unique to your particular string but you can start searching from a match at that index if there are multiple strings with the same hash.

>> No.67830885

>>67830850
The idea is to group the input by the bytes it uses.
A hash function generates a single number from the input bytes that you can then do modulus on and use as an index to a group, where you can check each "collision".

>> No.67830886

>>67830479
It fixed everything that was wrong with java

>> No.67830897

>>67830886
The only thing it fixed was Generics, then it bolted on a bunch of badly designed badly implemented afterthoughts

>> No.67830900

>>67830886
It didn't

>> No.67830923

Before I try to possibly reinvent the wheel is there a way in python to get a list of all substrings from a list in a string? Like this:

If I have this string: 123abaaaabqwertyqwerty
And this list of strings: ['123', 'ab', 'a', 'qwerty']

I want to split the string into this list: ['123', 'ab', 'a', 'a', 'a', 'ab', 'qwerty', 'qwerty']

>> No.67830927

>>67830886
Is it nearly as portable as Java? No?
Into the bin.

>> No.67830942

>>67830923
Don't know about any such feature already existing but when you implement that, you'll have to watch out for "ab" and 'a' colliding with eachother.
If you can think of any efficient algorithm for it then let me know cuz I can't think of any.

>> No.67831000

>>67830661
>isodd(x)
>readable
>>67830644
&1 is portable.
>inb4 one's complement

>> No.67831004

>>67830923
is the order in the list the precedence at which they're extracted? sounds like a fun problem!

>> No.67831014

>>67831000
You're not inb4, you're in-after.

There is no reason not to use % 2. No reason.

>> No.67831017

>>67830923
That sounds like a NP-hard problem.
Maybe you could build a tree, but you still might have to backtrack.

>> No.67831031

>>67831014
>No reason.
My % key is broken.

>> No.67831032

>>67831014
It looks ugly. %2 is nonstandard, it's like using output instead of rc. Am I supposed to write %65535 instead of &0xFFFF too?

>> No.67831047

>>67830101
>get into something useful that isnt a fad
Example?

>> No.67831049

>>67831032
Yes, goy. The CIA doesn't wa- err.. you don't want to use bitmasks!

>> No.67831067

Doesn't get much more inane than this

>> No.67831139

>>67830751
>>67830819
see for example https://reviews.llvm.org/D17289
tldr: Sandy/Ivy Bridge and Haswell are too retarded to see that eax is a destination register, not a source register, so to pipeline the instructions better an xor is inserted

>> No.67831161
File: 20 KB, 412x351, 1531827399967.jpg [View same] [iqdb] [saucenao] [google] [report]
67831161

>company was going to give me $5k for relocation
>slipped my tongue and said i would be okay with taking the hit myself
i fucking hate being autistic. there's no way i can renege this, is there?

>> No.67831175

>>67830923
>>67831017
It seems pretty easy:
>let S = the string, L = the search list, M = the result list (empty), i = index into S (0)
>sort L in place from longest to shortest
>loop while i < |S|:
>>let Y be nothing
>>for each string X in L:
>>>if X is at position i in S:
>>>>add X to M
>>>>Y is now X
>>>>break
>>if Y is nothing:
>>>increment i
>>else:
>>>increment i by |Y|
>return M

>> No.67831189

>>67831161
dumb frogposter

>> No.67831191
File: 9 KB, 390x454, 2018-09-25-004245_390x454_scrot.png [View same] [iqdb] [saucenao] [google] [report]
67831191

I made a 4chan file grabber in BBC BASIC.

>> No.67831194

>>67831032
>%2 is nonstandard
What the fuck are you talking about? It's the modulus operation.

>Am I supposed to write %65535 instead of &0xFFFF too?
Is it a bit mask? Use AND and 0xF's
Is it a check for divisibility? Use modulus.
>>67831031
>>No reason.
Because it's portable.

>> No.67831212

>>67830923
indeed, don't reinvent the wheel:
re.findall(r'123|ab|a|qwerty', '123abaaaabqwertyqwerty')

>> No.67831233

>>67830927
It is.

>> No.67831239

>>67831161
>on second thought I need the cash
no harm in trying, no shame in needing cash

>> No.67831254

>>67830570
The number of jobs available for a language is not a good measure of how good the language is. It's a better measure of how many shills the language has in high places. Which, frankly, is practically the opposite: a measure of how BAD the language is.
Which is why I'm proud to be a Ruby dev.

>> No.67831277

>>67831239
>no shame in needing cash
Not him but there is absolutely shame in needing cash. There's nothing wrong with it, but unfortunately, we live in a fucked up world where plenty of things have been made shameful despite not being wrong, or even necessarily within someone's personal control.

>> No.67831278

>>67831254
>How good the language is
There are hundreds upon hundreds of better languages than Microsoft's java ripoff.

>> No.67831291

>>67831278
So I guess you're agreeing with me then?

>> No.67831343

>>67830834
>>67830791
>>67830751
The reason is that they wanna clean up, but you could just do mov eax, 0x00. However, historically xor eax, eax was much faster than an actual mov and its instruction encoding is also much smaller. See:

bits 32
section .text
global _start
_start:
mov eax, 0x00
xor eax, eax
mov eax, 0x01
mov ebx, 0x00
int 0x80


Then:

$ nasm -f elf32 asm.s
$ ld -m elf_i386 asm.o
$ objdump -d a.out

a.out: file format elf32-i386


Disassembly of section .text:

08049000 <_start>:
8049000: b8 00 00 00 00 mov $0x0,%eax
8049005: 31 c0 xor %eax,%eax
8049007: b8 01 00 00 00 mov $0x1,%eax
804900c: bb 00 00 00 00 mov $0x0,%ebx
8049011: cd 80 int $0x80


You can see that xor eax, eax gets encoded as 0x31 0xc0, which is absolutely tiny. What's more, xor eax, eax works on the entire register 100% of the time, while the mov instruction in this takes 32-bit immediate data, but on some processors might take 16-bit immediate data depending on what the "default" size is defined as for that particular processor.

Furthermore, the 0x66 prefix can be used to modify it to take immediate 16-bit data instead, but this is ignored on Intel processor and it treats it as a 32-bit instruction, while on AMD it's treated as a 16-bit instruction with the 0x66 prefix.

x86 is a complete and utter clusterfuck.

>> No.67831351

>>67831212
or if you really need to grab your needles from a random string list
needles = ['123','a','ab','qwerty','.']
haystack = "123abaaaabqwertyqwerty."
matches = re.findall("|".join(map(re.escape, sorted(needles,reverse=True))), haystack)

>> No.67831364
File: 286 KB, 960x722, 1535972932461.jpg [View same] [iqdb] [saucenao] [google] [report]
67831364

I made a spongebob mock meme generator. Comes in handy sometimes.
void main(string[] args) {
import std.uni : toUpper, toLower;
import std.stdio : writeln;
import std.encoding : codePoints;

string toPrint;
bool mkLower = true;
foreach (word; args[1 .. $]) {
foreach (c; word.codePoints) {
toPrint ~= mkLower ? c.toLower : c.toUpper;
mkLower = !mkLower;
}
toPrint ~= " ";
}
writeln(toPrint);
}


$ ./mock Sîne klâwen durh die wolken sint geslagen
sÎnE kLâWeN dUrH dIe WoLkEn SiNt GeSlAgEn

>> No.67831365
File: 56 KB, 924x976, pure.jpg [View same] [iqdb] [saucenao] [google] [report]
67831365

>>67831191
>BBC

>> No.67831385

https://github.com/doitsujin/dxvk/pull/674/commits/62cf08904ac1c3493ae90f02b4ead8870b3bb574
Who was in the wrong here

>> No.67831386

>>67830751
because if you use a 64 bit register and move a 32 bit value into it the top bits are still set
as rax and eax are the same register only eax is the lower 32 bits

>> No.67831398

>>67831385
autism

>> No.67831399

>>67831386
Mostly because of right shifts you dont want to get nigger dicked because there is still a set bit when right shifting

>> No.67831401

>>67831385
>rejected
who saw this coming woah

>> No.67831429

>>67831385
>https://github.com/doitsujin/dxvk/pull/674/commits/62cf08904ac1c3493ae90f02b4ead8870b3bb574
It is wrong to make changes for the sake of optimization without perf measurements to back it up

>> No.67831437

>>67831429
>It is wrong to make changes for the sake of optimization without perf measurements to back it up
This

>> No.67831451

>>67831437
>>67831429

Or at least the assembly output.

>> No.67831452

this reminds me
is there a good guide to writing 64 bit assembly, preferably gas
i had a compiler to 32 bit gas (didn't have arrays)

i want to make one to 64 bit and i dont want to use llvm cuz that's like cheating right

>> No.67831468
File: 825 KB, 700x700, 43DE75E21A954ABA8991FD29F6A09FD2.png [View same] [iqdb] [saucenao] [google] [report]
67831468

> tfw Junior sysadmin containerizing products and transitioning to devops
It's grunt work, but whenever i test a build and a billion lines scroll down the screen...
>pic related

>> No.67831485

I feel like just knowing how to code without any knowledge about algorithm is a bit like knowing how to draw while being color blind. What's some good books to help me learn algorithms?

>> No.67831488

>>67831385
you for shitposting

>> No.67831493

>>67831343
>>67830751
>>67830791
>>67830834
Oh and yes, I forgot to address this:
>but on some processors might take 16-bit immediate data depending on what the "default" size is defined as for that particular processor.
What I mean by this is that if one uses mov eax, 0x00 and it is encoded as 0x8B 0x00 0x00 0x00 0x00, then it will in fact end up with undesired behavior if it is then executed on a processor with a 16-bit instruction size as default. On a processor defaulting to 32-bit instructions, the processor it will execute as "mov eax, 0", but on a processor with 16-bit default instruction size will execute it as:

mov eax, 0
add eax, [garbage data] ; [garbage data] should be next opcode, but it's treated as data

And from that point on EVERY single instruction in the program will be malformed and your program will break.

You can't use 0x66 prefix either and compilers NEVER EVER DO because it's massively problematic, because then:

- Processors with 16-bit instruction default will treat it as 32-bit instruction and the program breaks
- Intel i386 and x86_64 processors will ignore it (not spec compliant) and continue to treat it as 32-bit instruction (which is their default)
- AMD processors will not ignore it and will treat the instruction as a 16-bit one and now your program breaks again

This is stuff that compiler devs are forced to think about because they need to compile code that works on every x86 processor imaginable, even an only hypothetical processor that defaults to 16-bit instructions in 32-bit protected mode.

So this is why registers are zero'd out with xor.

>> No.67831503

>>67831485
Introduction to Algorithms aka CLRS

>> No.67831518

>>67831493
>>67831343

Meant to say "it is encoded as 0xB8 0x00 0x00 0x00 0x00"

0x8B does not deal with immediate data (but it is a mov instruction).

>> No.67831552

>>67831503
Thanks

>> No.67831553

>>67831493
Absolute madness

>> No.67831557

What should I program now? I want something simple but challenging

>> No.67831563

>>67831557
An x86 emulator

>> No.67831573

>>67831552
If you want more, try
The Art of Computer Programming aka TAOCP

>> No.67831622

>>67831557
i'm currently writing a torrent CLI downloader/uploader. don't copy me silly boys

>> No.67831631

what's a brainlet friendly introduction on scheme macros?

does define-syntax just work like define except it doesn't eval its arguments?

>> No.67831663

>>67828812
This. But it doesn't carry a backup solution and doesn't miscompile when used outside the jump table range.
Ideally the backup solution shouldn't compile for any input within the jump table range either but that's kinda hard to deal with. And in a good language (not C++) we'd have the introspective abilities to choose which values we store in the jump table automatically.

>> No.67831667
File: 29 KB, 515x613, 1522344200660.png [View same] [iqdb] [saucenao] [google] [report]
67831667

Still playing with Julia, loving it so far.

Heres newtons method
using Flux.Tracker
using Flux.Tracker: Params, gradient, update!

∇(f,x) = gradient(() -> f(x),Params(x))[x]

function Newtons(f, x0, ε=1e-3, maxiter=1e3)
x = param(x0)
for i in 1:maxiter
x = x - f(x)/∇(f,x)
@show(f(x)) > ε || break
end
@show x
end


pic in case something fucks up again, and for output. Its great that you can write algorithms so close to how the math is.

>> No.67831690

>>67831552
If you know (or are learning in) C or Java, you might find Sedgewick's books more approachable. They're nowhere near as encyclopedic as CLRS, but they cover all the basic algorithms, and having actual code examples rather than pseudocode can be helpful when you're starting out.

>> No.67831710

>>67831386
On x86 all 32 bit operations implicitly zero extends to 64 bits.
So you should always prefer the lower 8 registers and 32 bit encodings unless you have to (i.e dealing with pointers or 64 bit numbers) since they are smaller.

>> No.67831723

>>67831667
Julia is a trick by the subversive Leninist society of anti-intellectuals who are part of an ancient and powerful conspiracy designed to overthrow and enslave the neanderthal race

>> No.67831732

>>67831557
GB emulator

>> No.67831769

>>67831557
>1. Download this paper: https://www.microsoft.com/en-us/research/publication/the-bw-tree-a-b-tree-for-new-hardware/
>2. Implement it in your language of choice
>3. Launch NoSQL Database Startup

>> No.67831771

>>67831723
I subverted your mom last night

>> No.67831772

>>67831710
This.

>> No.67831786

>>67831769
>3. Launch NoSQL Database Startup
>4. Get patent trolled and sued into the oblivion by Microsoft.

>> No.67831789

>>67831710
xmm register dont do this so it is probably compiler standard to do so

>> No.67831796

>>67831769
https://blog.timescale.com/why-sql-beating-nosql-what-this-means-for-future-of-data-time-series-database-348b777b847a

>> No.67831797

>>67831451
They didn't even look to past experience here. Awful.

>> No.67831814
File: 7 KB, 329x190, 1511081262450.png [View same] [iqdb] [saucenao] [google] [report]
67831814

>>67831667
oh shit I just realized you can use /in for in, updated to be even better.

>> No.67831817
File: 1.09 MB, 3000x1994, gettyimages-8501546581.jpg [View same] [iqdb] [saucenao] [google] [report]
67831817

>>67831786
And I would have gotten away with it if too, if it weren't for you meddling kids.

>> No.67831842

>>67831817
I fucking hate him.
I hate patent trolls.

>> No.67831857

>>67831769
Red-black pill me on BW-Trees

>> No.67831910

uwu

>> No.67831925

>>67831910
:3

>> No.67831948

I looked at https://en.wikipedia.org/wiki/List_of_data_structures and there are really many different data structures than you normally think about.
Is there any kind of diagram/flowchart that explains when to use which one?

>> No.67831971

>>67830531
>>67830539
>>67830545
>>67830549
>>67830562


What purpose do pointers to pointers serve?
It's already complicated enough to work with pointers, why would I need to point to pointers or even point to a pointer that points to pointers?

>> No.67831973

>>67831948
No, you go by instinct
Picking data structures is just an innate talent you need to have as a programmer
If you don't already know when you would use a linked list, you'll never learn

>> No.67832013

>>67831948
that would be a good idea desu

>> No.67832020

>>67828122
https://www.codingame.com/multiplayer

I'll just leave this here.
It has nice bot programming contests and other cool stuff, in case anyone is interested.

>> No.67832034

Found something annoying in Julia, shits still incomplete. even though types in some libraries have both == and < defined for them <= doesn't work and I had to create a function ≤(x::T1,y::T2) = x < y || x == y for those cases.

>> No.67832039

>>67831971
pointers to pointers can be useful with some complex data structure operations. Last time I used them was implementing a pairing heap with back pointers

>> No.67832088

I have a bunch of microservices. I want one schema/db per microservice to achieve total and complete isolation.

So I need/want a database/database provider. PostgreSQL preferably. I can set one up myself. Sure. I have a home server. But I don't trust myself. My house will probably burn down or something.

What paid service for a VPN/DB provider is the best? I want backups and data security.

>> No.67832109

>>67832088
aws

>> No.67832124

>>67832034
julia confirmed shit
of course it already was because it has as many abstractions as java, which is fuck all

>> No.67832165

>>67832124
> it has as many abstractions as java, which is fuck all
wats missing that you need?

>> No.67832169
File: 112 KB, 675x949, 1510400538702.jpg [View same] [iqdb] [saucenao] [google] [report]
67832169

>>67832034
Rust doesn't have this problem

>> No.67832182

>>67828907
internship or full time? I'm patiently awaiting my phone interview for an internship but they haven't even confirmed a date yet

>> No.67832199

>>67832169
baka akari

>> No.67832211

>>67832169
>>67832034
>>67832124
Thats the library that's shit/incomplete, not the language. you need to define >, == and >= for custom types.

>> No.67832215

>>67832088
>I want backups and data security
backblaze.com?

>> No.67832219

>>67831971
an array of strings is a char**, just look at argv.
any array of dynamically allocated objects is an obj** for that matter.
if you want to pass an address via a pointer rather than as a reference, you easily get double or triple pointers.

>> No.67832228
File: 353 KB, 648x626, 1392011828134.png [View same] [iqdb] [saucenao] [google] [report]
67832228

and akari go hand-in-hand

>> No.67832266

>>67832228
why'd you post an image of a wall? Nice curtain btw

>> No.67832275

>>67832228
>akari
who?

>> No.67832540

>>67828122
That manga is awful

>> No.67832620

>>67832211
where's muh default implementation?
defaults Ordered t
a < b = (b > a)
a > b = not (a <= b)
a <= b = (b >= a)
a >= b = not (a < b)
defaults Equal t
a == b = (a <= b) and (b <= a)
a <> b = (a < b) or (b < a)
compare a b
| a > b = 1
| a == b = 0
| a < b = -1


>>67832165
higher-kinded types of course
how else are you getting your burritos?

>> No.67832640

wtf am i doing wrong?

num = int(input("Enter number: "))
x = range(1, num)
divisorList = []

for num in x:
if x % num == 0:
divisorList.append(x)
print(divisorList)

>> No.67832686

>>67832640
>wtf am i doing wrong?
you forgot to use code tags

>> No.67832691

>>67831948
It's not that simple. Datastructures inform algorithms and algorithms inform datastructure choice. So it's something you need to judge in a complex manner.

But if there was a flow chart describing the intersection of access patterns for common data structures and algorithms that'd be quite helpful for some cases. Especially for making a good first guess.

Most describe their choice as intuitive. It's probably more accurately described as arbitrary with a slight common sense applied. Measuring is the only way to really know. But sadly that implies you implement a realistic test case. And maybe once you've informed yourself on the tradeoffs you may choose to reevaluate your requirements.

It's not easy.

>> No.67832702

>>67832640
use proper names for the 4 different things you have and you'll see
and next time use code tags

>> No.67832737

>>67832702
I thought I used to proper names.

>> No.67832769

>>67832737
you thought wrong.

>> No.67832774
File: 77 KB, 680x535, maki.jpg [View same] [iqdb] [saucenao] [google] [report]
67832774

>>67828122
How do you get good at interview problems?

>> No.67832777

>>67832737
overly descriptive names like allNumbersFrom1ToInput

>> No.67832783

>>67832774
you git gud. Then you ace interviews with your left hand YOU FOOL.

>> No.67832787

>>67832640
x % num == 0
x is a list so that doesn't make any sense

>> No.67832788

>>67832777
fuck I meant listOfNumbersFrom1ToInput

wasted triplets

>> No.67832789

>>67828751
>>67829461
High school students know enough maths to do it in O(log(n)) with a few variables.

>> No.67832797

>>67832774
go through CLRS

>> No.67832827

>>67829439
That's not the real math one.
Arbitrary length arithmetic is O(n) and phi^n will very quickly overflow on fixed length representation.

>> No.67832876

>>67832789
>High school students
Only those who search on the web for optimal fibonacci algorithms and then copypaste the thing.
You won't come up with an iterative squaring solution by yourself.

>>67832827
>Arbitrary length arithmetic is O(n)
based and redpilled

>> No.67832881

When would you ever want the Nth Fibonacci number without first wanting all the Fibonacci numbers before it?

>> No.67832896

>>67832881
When would you ever want a Fibonacci number?

>> No.67832906

>>67832896
Good question.

>> No.67832939

tryin to make a js for scraping url;

var data = [];

data.push(1, 23); (does this even work?)

How to get 23 value only back? data[0] should probably print out (1,23) but I just want the second value.

How do?

>> No.67832943

>>67832881
>ever wanting fibonacci numbers
leave those thots behind

>> No.67832956

>>67832939
JS doesn't use tuples so it'd be [1,23]

accessing 23 would be data[0][1]

>> No.67832969

>>67829461
math phds are not computer scientists; they only see the expressions, not the underlying computation. this is why most of them wrote their programs in python or R then ask a real programmer to rewrite it in c++ to run it on HPC.

>> No.67832979

>>67832969
why can't math people program?

>> No.67832992

>>67832979
Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians.

>> No.67833023

>>67832896
>some guy walks up to you
>says "I would like F(1) mcnuggets and F(3) fries please"
>fetch laptop
>stack build /g/ certified© fibonacci program
>stare blankly at the other person for 3 minutes
>run /g/ certified© fibonacci program
>enter 1 mcnuggets and 2 fries into register
a day in the life of a haskell professor

>> No.67833035

>>67832979
Math students in my experience usually have an easier time with algorithms and a harder time with large-scale program structure.
My guess is that the structure of a proof is really different from the structure of a program, but I only took undergraduate courses that dealt with proofs, so I'm not sure.

>> No.67833053

>>67832182
Full time. Just graduated.

>> No.67833112

How is string interpolation usually implemented?
I mean something like this:
foo = 'fgt'
urafgt = `ura_{foo}` \\'ura_fgt'

It's just syntactic sugar for a string format function, right?

>> No.67833153

>>67833112
Some sort of substitution regexp or the compiler might split it up into several string append operations. Depends which idiot wrote your language.

>> No.67833207

>>67833035
Large-scale program structure isn't difficult.
Just break down your problem into something sensible that other people can understand, and then make it concrete.
That's step 1 and all most people need to be able to do.

Senior fags need to be able to design systems to be able to logically interconnect with other, already and usually larger existing systems, and also be able to navigate company politics since it can sometimes affect the scope of the project and the communication between projects

>> No.67833245
File: 148 KB, 222x293, 1536362535565.png [View same] [iqdb] [saucenao] [google] [report]
67833245

>>67833023

>> No.67833283

>>67833112
what programming language?

>> No.67833293

>>67833153
>Depends which idiot wrote your language
that's gonna be me in a second

this is for a .yaml file, where {foo} expands to a serialized object {'like': 'this'}

It makes little sense to me and I'm honestly not sure where they're going with this. Maybe the string gets absorbed into the object or something.

>> No.67833307

>tfw overthinking everything
>tfw worrying about performance even though a phone can run thousands upon thousands of the same function every single fucking second, and I'm worrying about it

>> No.67833312

inspired by this:
http://gameprogrammingpatterns.com/state.html

wrote a version that uses in-place new to avoid heap allocations for a nice fsm
#include <memory>

struct FSM;
struct StateBase;
struct StateDeleter;

using sptr_t = std::unique_ptr<StateBase, StateDeleter>;

struct StateBase {
virtual ~StateBase() {}
virtual sptr_t update(FSM &) = 0;
};

struct StateDeleter {
void operator()(StateBase *s) {
s->~StateBase();
}
};

struct S1 : StateBase {
sptr_t update(FSM &fsm) override;
};

struct S2 : StateBase {
sptr_t update(FSM &fsm) override;
};

struct S3 : StateBase {
sptr_t update(FSM &fsm) override;
};

struct FSM {
void update() {
state = state->update(*this);
}

union SUnion {
S1 s1;
S2 s2;
S3 s3;
};

template<class T, class ...Args>
// TODO: add check that T is S1..Sn
sptr_t in_place(Args... args) {
return sptr_t {
new (&s[index++ & 1]) T{std::forward<Args>(args)...}
};
}

// double buffer for the intermediate
// state of in place creation
uint8_t s[2][sizeof(SUnion)] {};
size_t index {};
sptr_t state { in_place<S1>() };
};

sptr_t S1::update(FSM &fsm) {
puts("S1");
return fsm.in_place<S2>();
}

sptr_t S2::update(FSM &fsm) {
puts("S2");
return fsm.in_place<S3>();
}

sptr_t S3::update(FSM &fsm) {
puts("S3");
return fsm.in_place<S1>();
}

int main(int argc, char* argv[])
{
FSM fsm;
for (auto e : {1,2,3,4,5,6,7,8})
fsm.update();
}


although I don't know if I'm invoking undefined behavior due to alignment.

>> No.67833321

>>67832956
That makes sense, I wasn't thinking about it properly. Ultimately, I decided to keep using the single data array and access it via data[0] and data[1] since I was only using it to store one set.

>> No.67833322

>>67833307
Worrying about performance is a valid concern. Do you want to be a shitty engineer or a good engineer?

>> No.67833323

>>67833307
Performance on phones is often about energy efficiency, not run time. Being able to do twice the work in the same amount of time is equivalent to being able to do the same amount of work with half the battery consumption.

>> No.67833336

>>67833312
Just use C++1z resumable functions (stackless coroutines).

>> No.67833374
File: 407 KB, 1120x840, 1509333007981.jpg [View same] [iqdb] [saucenao] [google] [report]
67833374

>>67832640
>wtf am i doing wrong?
You're not using Haskell
divisors num = [x | x <- [1..num]
, num `mod` x == 0]

main = print . divisors =<< (putStr "Enter number: " >> readLn)

>> No.67833382

>>67833336
Is that already available on gcc ? This is the latest compiler I can use:
https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads

>> No.67833452

>>67833207
>Large-scale program structure isn't difficult.
its the only difficult thing about programming, and what senior programmers get paid the most amoutn of money to do

>> No.67833466

>>67833382
Apparently no compiler has implemented it. Fucking lmao, nice language.

>> No.67833501

>>67833307
>>67833323
Just look at Snapchat and Tinder. They're by no means slow or unresponsive, but they're beasts when it comes to battery consumption. Which is pretty unreasonable.

>> No.67833571

>>67833112
In Swift, the compiler generates an array of strings from the literal string segments and interpolated references and then calls an initializer that concatenates them together to make the final string. So "The temp is \(currentTemp(n)) degrees" gets translated into something like String(segments:["The temp is ", currentTemp(n).description, " degrees"]) behind the scenes.

>> No.67833583

>>67833501
I dunno about others but on my Galaxy S7 Snapchat is extremely slow

>> No.67833585

>>67833466
no, clang actually has, but you need to enable it as an experimental feature

>> No.67833608

Why don't people that write in C++ write readable code?

>> No.67833632

>>67833312
for the alignment issue this might be an option:
using union_t = std::aligned_union_t<sizeof(SUnion), S1, S2, S3>;
std::array<union_t, 2> s {};

>> No.67833641

>>67833608
wah wah poo poo pee pee
someone call teh wahmbulance wah wah
ur mom

>> No.67833649

>>67833608
>C++ beyond toy examples
>readable

>> No.67833655

>>67833632
nvm, I found that this is also an option, removing the need for SUnion
using union_t = std::aligned_union_t<0, S1, S2, S3>;

>> No.67833673

>>67833608
Because they've been given too many tools to do so

At least with C, an emulator still looks pretty damn simple

>> No.67833764

>>67833374
And you're not using the fact that any divisor gives a complementary divisor:
divisors n = divisor 1
where
divisor a
| a*a > n = []
| a*a == n = [a]
| a*b == n = [a] ++ divisor (a+1) ++ [b]
| otherwise = divisor (a+1)
where b = n `div` a

(Appending to the list only to get the divisors from small to large)

>> No.67833810

>>67833764
you calculate a*a twice unless it's > n

>> No.67833852

Actually stackless coroutines could easily be done with the gnu++11 standard:

#include <cstdio>

#define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0]))

int main() {
int co_state = 0;
int a = 10;

auto my_coroutine = [&]() -> bool {
static void *state[] = {&&first, &&second, &&third};
if (co_state != ARRAY_LEN(state))
goto *state[co_state++];
return false;
first:
a = 20;
return true;
second:
a = 30;
return true;
third:
a = 40;
return true;
};

printf("a is %d\n", a);
while (my_coroutine())
printf("now a %d\n", a);

return 0;
}

>> No.67833868
File: 25 KB, 655x509, 7ppiugrc47d11[1].png [View same] [iqdb] [saucenao] [google] [report]
67833868

>>67828122
>ask for relocation assistance like another guy from the last thread told me to
>they end up dropping the offer's salary by 10k, but offer me 5k in relocation fees

>> No.67833873

>>67833868
dumb frogposter

>> No.67833883
File: 120 KB, 500x408, 798fc127521.png [View same] [iqdb] [saucenao] [google] [report]
67833883

I have problem with my C exercise, mostly loops not terminating properly, my comments go on more detail.
https://pastebin.com/YHq2mvej

>> No.67833933

>>67833883
does using '\0' not work?

>> No.67833964

>>67833883
>or
>not_eq
dropped
>if (First = 'E')
on second thought...

>> No.67834028

>>67832876
>copypaste
Well at least they could recognize it.
I don't think either of the people I quoted would recognize a O(log(n)) if it hit them in their face.

>> No.67834038

>>67834028
What does it feel like to be hit in the face by an O(log(n))?

>> No.67834042

New thread!!!
>>67834037
>>67834037

>> No.67834052

>>67833810
>https://wiki.haskell.org/GHC/FAQ#Does_GHC_do_common_subexpression_elimination.3F
shit you're right

>> No.67834283

>>67832640
>wtf am i doing wrong?
using Python

>> No.67834701

>>67832109
>>67832215
thanks for the suggestion.

>> No.67835078

>>67833452
senior programmers get forced into management because they cost too much to keep around

>> No.67835781

>>67828122
Just finished up a Python script to turn all of my ZIP and RAR files into CBZs and CBRs, so that MComix previews them better.

>>
Name (leave empty)
Comment (leave empty)
Name
E-mail
Subject
Comment
Password [?]Password used for file deletion.
Captcha
Action