[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: 37
File: 1451683583776.gif (2 MB, 400x600) Image search: [Google]
1451683583776.gif
2 MB, 400x600
Functional programming edition
>>
threads posted before 310 posts are not valid
>>
If non-nude anime girls get removed for being lewd, this should too, especially considering it was posted before the bump limit.
>>
If I want to make a single global vtable for a specific object struct in my library code, is it advisable to put a single global vtable like this in the header?
Or should I combine the struct declaration and tack on the struct literal initializer list since this struct will only ever be used once.
const struct _vtable __GLOBAL_OBJECT_VTABLE = {
&member_function1,
&member_function2,
&member_function3
};
>>
>>52458465
Who else going through SICP? I'm trudging through understanding some of the challenges in here, specifically around the coin denominations combinations part (which is quite early)
>>
>>52458494
>for being lewd

no, they are being removed for being cancer
>>
>>52458642
Why in the header? Put it in the implementation file.
>>
Nooo, the real thread was deleted.
>>
>>52458494
no this isn't lewd, at least not in the same way as a blushing 4 year old girl with her soaked panties half way off
>>
PD3D

>>52458494
This.

Abandon ship. Make a new thread.
>>
>>52458663
you make it
>>
>>52458465
Should I learn LISP or Haskell?
The name LISP sounds very faggy, Haskell sounds awesome
what do? dubs decide
>>
>>52458705
Racket for going through SICP
Haskell for anything else
>>
If you don't program in ocaml, you don't know SHIT about programming!
>>
>>52458705
be different, learn cobol
>>
>>52458705
F# if you have to learn a FP language
>>
>>52458705
Learn OCaml for real work, and use chicken scheme for sicp. Chicken scheme is the best scheme implementation by far, with the only caveat that it's restricted to green threads. OCaml is a very high-performance yet very high-level language used in the real world. It has none of the flaws of haskell and trades haskell's discrepancies for practicality - i.e. it's perfect.
>>
File: s.png (2 KB, 314x164) Image search: [Google]
s.png
2 KB, 314x164
i drew a circle
>>
>>52458733
How fast is this compared to ocaml?
>>
File: assburgers.png (68 KB, 993x1133) Image search: [Google]
assburgers.png
68 KB, 993x1133
>>52458737
that's dank now draw a flower of life

you should be able to specify any number of circles within reason
>>
F# is a meme. If you're not already tied to .Net, use OCaml. If you're tied to .Net, kill yourself.
>>
File: 1452647847613.jpg (77 KB, 720x556) Image search: [Google]
1452647847613.jpg
77 KB, 720x556
Can I put initializer lists in C structs?
>>
Daily reminder you're a fag if you use emacs. People who want to become good or are a professional, you'll use vim.
>>
JUST AVR MY THINGS UP
>two sketches use THE SAME libraries
>two sketches set ports to the same state
>two sketches try to start a peripheral device
>one sketch succeeds
>other sketch hangs
>both are run on the same hardware setup
what is happening, any ideas on fixing this mess?
>>
File: 37.png (92 KB, 969x1145) Image search: [Google]
37.png
92 KB, 969x1145
>>52458762
>assburgers.png
wait i think that's the one with the misaligned circles because the assburger was complaining about the circles not being identical because of the geometry of the circle of life
>>
File: tumblr_m499szxbUb1qkwym7.gif (512 KB, 400x282) Image search: [Google]
tumblr_m499szxbUb1qkwym7.gif
512 KB, 400x282
>>52458737
>>
>>52458774
FP as a whole is a meme

>>52458753
it's fine, almost as fast as normal languages
>>
>>52458793
>AVR
There's your problem, anon.
>>
File: sa.png (3 KB, 314x164) Image search: [Google]
sa.png
3 KB, 314x164
>>52458737
it messed up

>>52458762
might give it a go
>>
>>52458775
if you want your house to catch on fire
>>
>tfw virtual box for running ubuntu doesn't work for me
What does your windows development environment look like lads?
- Main:
Notepad++
C + GCC

- Prototyping
CPython + IDLE
Notepad

Also git
>>
>>52458775
I would advise against ever storing an initializer list.
>>
File: bglisp.jpg (42 KB, 500x225) Image search: [Google]
bglisp.jpg
42 KB, 500x225
>>
>>52458832
VS for C#/C++
Just NP++ for everything else
>>
>>52458815
I paid like five bucks on aliexpress for that. When it works, it's okay.
>>
>>52458826
>>52458839
ok

Should I just put this vtable inside it's own object struct declaraion then?

struct _object {
int *data;
int size;
struct _vtable {
void (*func1) (struct _object *self);
void (*func2) (struct _object *self);
void (*func3) (struct _object *self);
} *vt;

};
>>
>>52458832
Sublime Text
GHC with cabal for building
>>
>>52458788
w-what? why??
>>
File: 1430853197680.png (331 KB, 474x432) Image search: [Google]
1430853197680.png
331 KB, 474x432
fib(8) using iteration: 1 1 2 3 5 8 13 21

fib(8) using recursion:
fib(8) = fib(7) + fib(6)
fib(7) = fib(6) + fib(5)
fib(6) = fib(5) + fib(4)
fib(5) = fib(4) + fib(3)
fib(4) = fib(3) + fib(2)
fib(3) = fib(2) + fib(1)
fib(2) = 1
fib(1) = 1
fib(3) = 2
fib(4) = 3
fib(5) = 5
fib(6) = 8
fib(7) = 13
fib(8) = 21

which is more elegant and useful?
>>
>>52458900
Iterative of course
>>
>>52458832
GVim, GCC, CPython
>>
>>52458876
XY problem, anon.

In any case, no, because the whole point of having a vtable is for inheritance and polymorphism. The struct definition has to be available everywhere. The actual vtable value that points to the functions that should be used as virtual methods should be in the implementation file of the "class".
>>
>>52458876
struct _object {
int *data;
int size;
struct _vtable {
void (
*func1
) (
struct _object *self
);
void (
*func2
) (
struct _object *self
);
void (
*func3
) (
struct _object *self
);
} *vt;

};
>>
>>52458900
Nice meme
>>
>>52458465
Figuring out what kind of libraries Free Pascal/Lazarus don't provide.
So far I found it doesn't have premade functions for building power sets or cartesian products.
>>
>>52458900
Recursion was a mistake.
>>
File: 8.png (64 KB, 993x1133) Image search: [Google]
8.png
64 KB, 993x1133
>>52458762
There's something off with your circles.
>>
>>52458762
>>52458987
He's back
>>
>>52458996
>implying I ever left
>>
>>52458753
It's a bit slower in most tasks pre-flambda. With flambda it's a lot slower.
>>
File: 1432916172444.jpg (89 KB, 396x294) Image search: [Google]
1432916172444.jpg
89 KB, 396x294
>>52458987
with low-resolution images of the flower of life there's a trade-off between having accurate geometry vs. identical circles. if you use for example the bresenham's circle drawing algorithm then especially for low-resolution images the misalignment of the circles will be significant.
>>
>>52458793
these arduino librares, man
redincluding main.c from arduino library misteriously fixed it.
I hate arduino libraries, but I'm too stupid to rewrite them to be pure-avr.
>>
>>52459038
not very significantly for real word stuff. Access to the .NET ecosystem more than makes up for it.
>>
>>52458887
Emacs gives you carpel tunnel syndrome aka the emacs pinkey. You also have to learn a meme language to make it usable. Vim is perfect and won't ever give you problems.
>>
>>52459052
also i think i will make a flower of life using opengl some day but probably not today
>>
>>52458861
fibs = 0:1:zipWith (+) fibs (tail fibs)
>>
>>52458861
Bill Gates was such a such motherfucker
>>
>>52459170
such a smug*
>>
>>52459106
doesn't vim has its own scripting language too?
>>
>text editors with their own scripting languages
Disgusting, just use Notepad++, stop overdoing things
>>
>>52459141
That's not recursion, it's corecursion :^)
>>
>>52459203
Yes, but at least it is its own thing, not some bastardized LISP that nobody would actually use if it weren't for emacs.
>>
>>52459323
That's the same thing.
>>
>>52459218
Stupid winbabby, use a real text editor
>>
>>52459065
With flambda, yes it is. Especially for real-world stuff because full-program optimization scales extremely strongly.
>>
>>52458971

True
>>
C++ or Rust?
>>
>>52459462
D
>>
>>52459462
C
>>
>>52459462
>2 meme languages
You're making this hard
>>
>>52459462
C++
>>
>>52459462

C++ if you want to make money. Rust in your free time because programming is fun.
>>
is every language a meme?
>>
Wait, is there a GUI library for Rust yet?

>>52459532
Of course
>>
>>52459532
Yes
Except Java
Java is too shitty to be a meme
>>
>>52459532
different languages have different memetic features, but some languages are completely memes in themselves
>>
>>52459539
OOOOOOHH
>>
>>52459535
>>52459539
>>52459541
although, I have to say, being a meme is great since memes propagate throughout the society
>>
>>52459559
You're going to have to provide a detailed analysis as to why that implies it being great
>>
>>52459535
>Wait, is there a GUI library for Rust yet?

Conrod
>>
>>52459559
>being a meme is great since memes propagate throughout the society
I don't see why that's a good thing. Being popular doesn't mean it's good, it's just whoever 'marketed' themselves better.
>>
Relation between mandelbrot and julia set is almost magical.

Rewriting the whole thing in OpenCL, apart from adding a gigantic boost to rendering speed, will also allow user to input his own function instead of just specifying coefficients for a premade one (as soon as i fighure out an efficient way to tackle complex numbers inside OpenCL).
>>
>>52459575
actually, fuck my reasoning, im u=just retardede
>>
File: ss+(2016-01-17+at+01.18.00).jpg (647 KB, 1085x1393) Image search: [Google]
ss+(2016-01-17+at+01.18.00).jpg
647 KB, 1085x1393
>>52459600
Great, I forgot the picture.
>>
File: memelbrot.jpg (558 KB, 1038x744) Image search: [Google]
memelbrot.jpg
558 KB, 1038x744
>>52459612
That's quite beautiful. I'll raise you a brainfuck mandelbrot
>>
is java really that shitty?
>>
>>52459621

That was one of the first things I ran in my BF interpreter.
>>
>>52459656
It truly does nothing well.
>>
>>52459656
It's pretty good. A very comfortable language to write code in, especially compared to C++.
>>
>>52459656
There's much better alternatives
>>
>>52459667
then why's it so popular?
>>
>>52459703
it's taught as babbys first programming language
>>
>>52459703
Because it does a huge lot of things in a shitty way. But when you get paid to do some job fast and your employer is a moron then you simply don't care.
>>
>>52459703
It filled a niche when it was introduced, but now it's the language of choice for people who haven't ever done programming to tell their subordinates to use. And for that reason, it's also widely taught by universities that want their CS program to include code monkey training.
>>
>>52459703
>>52459723
Like, Java is a literal meme language. Using it is a meme among corporations that gets propagated by universities (why use any other language if most graduates are going to have learned it at some point?).
>>
File: 1448798270196.png (44 KB, 646x1029) Image search: [Google]
1448798270196.png
44 KB, 646x1029
i made a super advanced animation

https://jsfiddle.net/am382d17/
>>
>>52459664
Have you interpreted any part of how it generates the image? A simple algorithm of storing all the needed letters, traversing the stack and printing it 1 by 1 would run MUCH faster and you'd see more periods in the code. To generate this without, possibly through actually emulating the mandelbrot algorithm to get the respective values of each point, must be a hell of an algorithm
>>
>>52459703
there's like a billion pajeets m8
>>
>>52459424
source?
>>
>>52459742
I ran it for two minutes and now it became sentient. Thanks a fucking lot.
>>
I <3 the stack
>>
>>52459805
but do you <3 the doubly linked list
>>
>>52459765
>Have you interpreted any part of how it generates the image?

Not really. I did a Mandelbrot generator in C# using the escape-time algo, but the BF one is magic as far as I'm concerned.
>>
>>52459535
GTK.
>>
>>52459656
it's very good for large-scale OOP applications where development time, portability and safety is valued more than execution time and memory usage
>>
>>52459832
I <3 those, but not as much as the stack
>>
>>52459851
Just not as good as C# for the exact same kind of stuff.
>>
>>52459858
is there something about the stack that makes you <3 it more than you <3 the doubly linked list
>>
>>52459867
yeah, well, that's just, like, your opinion, man
>>
>>52459867
C# is the least portable language I know of.
>>
File: 1451751832808.png (17 KB, 418x359) Image search: [Google]
1451751832808.png
17 KB, 418x359
>when you tell the doubly linked list you only love her, but you're seeing the double-ended queue behind her back
>>
>create string
>use zlib to compress string
>save compressed string into text file

>load compressed string from text file
>pass compressed string into uncompress() function
>uncompress returns -3, which means data was corrupted, program crashes

Anyone know why this might be happening? I cout'd the compressed string before I try to uncompress it, and it's the exact same string as the compressed version.
>>
>>52459873
Yes
A stack is simple, quick and elegant
A doubly linked list is just too slow sometimes
>>52459896
That's rude anon
>>
>>52458861
a = 0
b = 1
c = a + b
for i in range(1000):
print c
a = b
b = c
c = a + b


see ever a retard can do fib
>>
>>52459911
>I cout'd the compressed string before I try to uncompress it, and it's the exact same string as the compressed version.

is it EXACTLY the same, or does it have some extra control characters that you can't see?
>>
>>52459976
I mean, just looking at the console window, it looks the exact same. Is there any other way I can tell?
>>
>>52459911
Make sure you're reading and writing the compressed data in binary mode.
>>
>>52459967
If you're going to use python, do it right
a, b = 1, 1
for i in range(1000):
print b
a, b = b, a+b

But our implementations start printing at 1,2,3,5.. instead of 1,1,2,3,5 or 0,1,1,2,3,5.
>>
>>52459911
Rotational velocidensity and/or electric infetterence.
>>
>>52460020
nice meme

i bet you think your $10 mouse is the pinnacle of human interface device technology
>>
>>52459892
In what way?
>>
>trying to include sqlite3 into c++

So I tossed sqlite3.c, sqlite3.h, and sqlite3ext.h into /usr/include/sqlite3

In source file, I have:

#include <sqlite3/sqlite3.h>


And make command is

clang++ -std=c++11 test.cpp -o test -lsqlite3


But the linker tells me it can't find it?

When I run verbose output, I see
#include <...> search starts here:
... some other directories
/usr/include


So it should be looking in the right place.

What do.
>>
>>52460070
Should be
#include <sqlite3.h>
tbqf.
>>
>>52460094
That just gives me fatal error: 'sqlite3.h' file not found
>>
File: code.png (46 KB, 1221x606) Image search: [Google]
code.png
46 KB, 1221x606
>>52460004
>>52459976
This is what my code looks like. I know, it's a mess, sue me.
The first line of the save file is an integer, it's the number of characters in the original, uncompressed string. The rest of the file is garbage text that I want to uncompress.
What I'm doing is opening the file, getting the first integer, then putting all the garbage text into the saveFile string, which I try to uncompress.
It doesn't always return -3; sometimes it returns -5, which means there isn't enough space in the output buffer (in this case, "uncompressedData" char array). Sometimes, for some reason, it won't even copy the entire contents of the original string (or maybe it does, but the last few lines are somehow lost).
>>
>>52460116
My bad.
You can't just dump a source file into /usr/include and expect it to magically work. Build sqlite and store the .so in /usr/lib64.
>>
What's the current js meme framework?
>>
>>52460152
vanilla.js
>>
>>52460137
You need to specify binary mode using the second parameter of open. It defaults to text (which changes some control characters and thus can corrupt the data).
>>
>>52460018
a, b = 1, 1
print 0,1
for i in range(1000):
print b
a, b = b, a+b
>>
>>52460165
std::fstream::binary, right?
Do I need to do it when I first create the text file?
>>
>>52460210
You need to do it both for saving and loading.
>>
>>52460041
Not him but: C# is only good because of .net as the backend. Without it, C# is pretty much exactly as bad as Java. And since .net is not portable to old Windows versions (or any non-Windows system) its portability is severely limited.
>>
>>52460151
Oh derp, I thought it just would include the code staticly
>>
>>52460236
>And since .net is not portable to old Windows versions (or any non-Windows system) its portability is severely limited.

If you build your application for older .NET versions, it works just fine.

>inb4 I need all the new features

Do you really?
>>
>>52460236
Except .net is just a standard library. The java and C# standard libraries are pretty much the same quality. C# has a boatload more keywords to make concepts more explicit, and many features that java only dreamed it had like LINQ, pipeline transforms, generators, proper generics, etc. The fact that the standard library is shared across all M$ languages doesn't change anything. It's a good thing that it's shared because it means you have a base that ensures up to a point interop between the languages, but jvm languages can talk to each other in the same way anyway, so it's really the VM and not the library that's good in this setup.
>>
>>52460273
>new synchronized data structures only available on .net 4 or higher
Yes, I need that feature.
>>
>>52460273
>all
If you need even just one new feature (which your dependencies almost certainly do) then you don't get to bring friends to old windows.
>>
>>52460294
>The java and C# standard libraries are pretty much the same quality.
Except one is portable to about every single device and OS, and the other one is not.
>>
>>52460304

Tell people to get off XP for your applications, then.

>>52460301

See above.
>>
>>52460331
My clients are in the government and still work with XP. It's not my choice. Also
>ditching customers because of old OS
How about I instead use languages that aren't dependent on a single entity deciding where I am allowed to run it?
>>
>>52460301
MUH DATER STRUGERS
>>
>>52460353
>How about I instead use languages that aren't dependent on a single entity deciding where I am allowed to run it?

Enjoy C, I guess.
>>
>>52458900
Who's the fool who suggest recursion over iteration?
>>
>>52460392
>C
>C++
>Java
>Delphi/Object Pascal
>Lisp
>Python
>Ruby
The list goes on.
>>
>>52460392
java is open source
>>
File: compress.png (46 KB, 1314x463) Image search: [Google]
compress.png
46 KB, 1314x463
>>52460219
Still isn't quite working. The text from the file looks exactly like the text from when I first compress it, except the text from the file doesn't have any line breaks.
For what it's worth, this is my code for creating the file. saveText is the uncompressed string.
>>
>>52460408
neckbeards in /dpt/ used to be really smug about their FP and recursion but the sentiment seems to have changed for the better.
>>
>>52460410

I was lightly rusing, but in most cases, C# is just fine. Especially so when you've got clients who are at least running Win7.
>>
>>52460445
filtered.
>>
>>52460408
>there are people who believe >>52458900 unironically
>despite the 200+ refutations to date
>mfw imperativefags are this retarded
>there is no face
>>
>>52460472

I'm innocent.
>>
>>52460488
the iterative way is how you would write it out if you solved it with pencil and paper. it's the most clear and intuitive way to solve it.
>>
>>52459911
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <zlib.h>

#define FILENAME "output"

void write_str()
{
const uint8_t *src = "Hello World!";
size_t src_len = strlen(src) + 1;

size_t dest_len = compressBound(src_len);
uint8_t dest[dest_len];

compress(dest, &dest_len, src, src_len);

FILE *fp = fopen(FILENAME, "wb");

fwrite(&src_len, sizeof src_len, 1, fp);
fwrite(dest, 1, dest_len, fp);

fclose(fp);
}

void read_str()
{
FILE *fp = fopen(FILENAME, "rb");

fseek(fp, 0, SEEK_END);
long file_len = ftell(fp);
fseek(fp, 0, SEEK_SET);

size_t dest_len;
fread(&dest_len, sizeof dest_len, 1, fp);

uint8_t file_buffer[file_len];
fread(file_buffer, 1, (size_t)file_len, fp);

uint8_t dest[dest_len];
uncompress(dest, &dest_len, file_buffer, file_len);

printf("%.*s\n", dest_len, (char *)dest);
}

int main()
{
write_str();
read_str();
}
>>
File: 1451683513443.gif (2 MB, 400x225) Image search: [Google]
1451683513443.gif
2 MB, 400x225
>tfw you can't shave your asshairs because it'll itch, but the only option for truly cleansing after a loose-ish shit is to take a shower after
I think I'm going to try implementing Pong in CHIP-8, I always make the mistake of dreaming up big games when I do game dev. Also thinking of doing snake after, but storing the nodes would take up about 4k memory which is all I have
>>
>>52460524
No. The intuitive way is the mathimatical recusive definition. And if you use memoization then all the drawbacks become entirely moot.
>>
>>52460551
its called a bidet
look into it
>>
>>52460551
how much goddamn asshair do you have? are you wiping carefully or smearing the shit everywhere? how about trimming your asshairs?
>>
File: imgur-2016_01_17-00:28:50.png (32 KB, 1169x272) Image search: [Google]
imgur-2016_01_17-00:28:50.png
32 KB, 1169x272
Why do we like C++ again?
>>
>>52460564
the most intuitive way to write the mathematical definition is the "iterative way":
1, 1, 2, 3, 5, ..., fib(n-2) + fib(n-1)

memoization is a roundabout band-aid to force your shitty ideology that it should be a recursive function
>>
>>52460568
I love bidets, but I'm not currently living in my place so I can't just get one here

>>52460573
A lot m8

anyone got any solution for snake? It seems no matter what I think up, I'll need to use 2 bytes per 2048 square. The only tighter way is to combine the bytes since 2^5 by 2^6 can be put into 11 of the 16 bits, but messing around with that option is unthinkable
>>
>>52460617
>Why do we like C++ again?
Where did you get that impression?
C++ is shit.
>>
>>52458465
why'd you post the disgusting vapid cunt , tho? dont answer just never do it again thanks 'ppreciate it
>>
>>52460617
>Why do we like C++ again?
Pretty sure it's the few new people that popped up over the past week or 2

>>52460636
Doing it again for the next thread lel
>>
>>52460236
>And since .net is not portable to old Windows versions
how old? You mean windows 95 old? Is modern Java still supported on that?
>>
>>52460621
>even includes the recursive form in order to explain the iteration
Wow.
>>
>>52460655
literally retarded
>>
>>52460636
>disgusting vapid cunt
she's a pure LA angel m8
>>
>>52460648
Read the thread.
And yes.
>>
Coming from c++ to python here

How come there isn't an int main() in python?

How do I write a driver program and header files containing my classes?

Let's say I have a linked list class in python, I want it in its own file then another file that is my driver program which should be able to communicate with my class file
>>
>>52460648
>how old?

I think the rub is that many workstations are on XP and the good versions of .NET (4.5+) require Win7.
>>
>>52460646
w0w reverse psychology!
simply could not have seen that coming!
>>52460666
nah. gross whore. LA is a dump.
>>
>>52460674
if __name__ == "__main__":
>>
>>52460564
Yes but memoization is not intuitive...
I'm nowhere near to be an expert but I remember that SICP suggested to use iterative processes, even if they are unintuitive...
>>
>>52460708
>Yes but memoization is not intuitive...
It literally transparent. There is no knowledge required.
>>
>>52460674
>How come there isn't an int main() in python?
Modularity, every file can have all of its functions, and you can import them all round, but if you wanted that module to execute different code if considered main, you do this
>>52460696

>How do I write a driver program and header files containing my classes?
Just write them up in any number of files you want

>which should be able to communicate
imports
>>
>>52460696
Where do I write that, in the other header files or in my main file
>>
>>52460617
Nice straw man.
namespace WP = WorldPositions;

for(auto i = WP::TOP_LEFT; i < WP::BOT_RIGHT; ++i) {
worlds.insert({(WP::Id)i, std::make_unique<World>(textureHolder)});
}
>>
>>52460763
WOOH. gotem
>>
>>52460735
Not him, but in whichever file you want. The code there only executes if it's the file you run from the start, and not if the file was imported. This way you can set up __main__ to be like a testing function for different modules, but without having all those tests run every time it's imported, only when it's the initial program being run
>>
>>52460724
OK, still it's not intuitive
>>
File: 1425429412322.gif (141 KB, 287x344) Image search: [Google]
1425429412322.gif
141 KB, 287x344
imperative

int fib(int n)
{
if(n == 0) {
return 0;
}

int a = 0;
int b = 1;

for(int i = 2; i < n; ++i) {
int m = a + b;

a = b;
b = m;
}

return a + b;
}


""""""""functional""""""""

data UpToTwo a = Zero | One a | Two a a
histo2 :: (UpToTwo a -> a) -> Int -> a
histo2 f = result . gen where
result (One x) = x
result (Two x _) = x
cons x Zero = One x
cons x (One y) = Two x y
cons x (Two y _) = Two x y
gen 0 = One $ f Zero
gen n = let
memo = gen (n-1)
in cons (f memo) memo

fib = histo2 phi where
phi Zero = 0
phi (One _) = 1
phi (Two x y) = x + y
>>
>>52460783
It seems to me that you have no clue what memoization is.
>>
>>52460786
>my joke code lives on
>still not understanding that the top part is library code
>>
>>52460783
Your retardation is not intuitive.
>>
>>52460798
>having to write "library code" in the first place
>>
>>52460800
seems intuitive for you to call others retards. surely you're not too familiar with retard-spectrum diagnoses?
>>
>>52460794
Don't care about me, it was just a stupid lexical issue...
But what about iterative functions as they are described in SICP? They are way less expensive...
(Really, I'm just interested I don't care if I'm right or not)
>>
So /sci/ is talking about programming

locate your nearest shelters
>>
>>52460881
What SICP describes as iteration is just tail recursion.
>>
>>52460819
>the point




>your head
>>
>>52460899
He's right though, he didn't say that particular infinite loop was the game loop itself
>>
>>52460926
>he has to use a library to get O(n) fib working
>>
>>52460881
You *always* write code in a way that it can be the most easily understood (and thus fixed in case of bugs) by others. If you implement a mathematical function that's defined in a recursive manner then you implement it like that. If it is defined in an iterative manner then you implement it like that. SICP with its old-ass dialect might be ignorant of this, but newer Scheme revisions provide ways to iterate over data in a non-recursive way.
>>
>>52460903
But the recursive Fibonacci computation someone wrote before wasn't tail recursive, was it?
>>
>>52460672
Java isn't supported there either. And a shite load of other stuff. So how is C# any worse than most?
>>
>>52460763
Thanks for improving my code
>>
>>52460940
kill yourself
>>
>>52460940
Fib is literally defined recursively, mathematically speaking, and it is literally the most easily understood, most straightforward, and most obvious way to implement it.
>>
>>52460938
That's a very silly way to write O(n) fibonacci that I did for fun. There are many other "functional" ways, like the classic Haskell corecursive definition:
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

Or, like that guy said, just use the naive definition with memoization.

>>52460980
Why are the types of TOP_LEFT and BOT_RIGHT not already Id?
>>
>>52461044
now do that zipWith shit with non-fizzbuzz tier applications

>>52461031
a self-contained loop is much easier to understand than a function that branches into itself over and over
>>
Whats the best way to keep a program organized?
>>
>>52460786
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
>>
>>52460763
>using a C style cast just because it's shorter
>>>/codegolf/
Also, wouldn't the compiler deduce i to be of type WP::ID? In which case this would fail to compile
>>
File: WallpaperPixelWaterfall.jpg (539 KB, 1920x1080) Image search: [Google]
WallpaperPixelWaterfall.jpg
539 KB, 1920x1080
>>52460617
Because that's what I was told most games and major applications were programmed in throughout the 90s.
>>
>>52461071
learn good code structure.
>>
>>52461073
kill yourself
>>
>>52460546
Is this C? It's not letting me create a const uint8_t and set it equal to a string.
>>
>>52460938
>>52461044
But I suppose, in the end, if all you want to do is get a single Fibonacci number in the cheapest manner, you either use a for loop (which requires imperative code) or you build a recursion scheme. The bonus of the recursion scheme is that you can reuse it for any algorithm with the same "structure", unlike the imperative way where you have to write the same boilerplate over and over again.

>>52461069
>now do that zipWith shit with non-fizzbuzz tier applications
Stop using a fizzbuzz-tier application to compare them, then.

>a self-contained loop is much easier to understand than a function that branches into itself over and over
So you literally don't understand recursion and that's why you're bashing it?
>>
C++ is the top choice for a trade-off between low-level performance and high-level features for applications such as games where performance truly matters
>>
>>52461074
Why would it fail to compile? In that case (which I asked about >>52461044), you wouldn't need the cast in the first place anyways.
>>
>>52461099
Not him, but did you include stdint? Otherwise, it might Uint8_t (capital U)
>>
>>52461044
WorldPositions is defined as follows
 
namespace WorldPositions
{
enum ID
{
TOP_LEFT
...
BOTTOM_RIGHT
}
}
>>
>>52461110
So you literally don't understand iteration and that's why you're bashing it?
>>
File: 1447731473305.jpg (178 KB, 597x1159) Image search: [Google]
1447731473305.jpg
178 KB, 597x1159
still playing with javascript desu

https://jsfiddle.net/8kpnah9z/

i don't get what all the hate is about, it's pretty neat
>>
>>52461086
>prove you wrong
f-fucking kill urself, normie scum, gtfo my GG!!!!!!
IM WRIGHT< IM" RIGHT < PLS KILL URSELF NORMIE< REEEEEEEEEEEEEEEEEEEEE
>>
>>52461145
fuck off to >>>/g/wdg weeb
>>
>>52461122
You cannot ++ an enum
>>
>>52461134
So what's with making the variable of type size_t and casting it back to ID every time?
>>
>>52461157
haskell is shit and you know it

>he has to use O(n) space just to get O(n) time fib
>>
>>52461140
I love how you guys never have any actual arguments.
>>
>>52461175
>being inbred
>still posting
>>
>>52461183
kill yourself retard

>>52461176
i already said that self-contained loops are cleaner and also >>52461175
>>
>functional programming thread
>200+ replies
>no mention of erlang

come on guys
>>
>>52461175
When the fuck are you only ever going to get a single Fibonacci number? You want to use the space so that subsequent calls are much cheaper.

The iterative version is optimized for a toy that does nothing useful, the recursion+memoization version is optimized for a real application.

>>52461195
Saying something doesn't make it true. You have to PROVE things.
>>
>>52461197
these tards are complete cargo-culting fuccbois what do you expect
>>
>>52461197
>erlang
>ever

Well, if you enjoy slow as fuck, single-core applications with no ability to run code in module definitions, I guess it's OK.
>>
>>52461145
Even better.

https://jsfiddle.net/8kpnah9z/1/
>>
>>52461175
whatever that means, have fun making that fizzbuss project applet in ur shitty java
>>
>>52461204
>You have to PROVE things.
as if you proved that haskell isn't fucking garbage lmfao kill yourself
>>
>>52461197
but functional is haaaaard ;_;
t. /dpt/
>>
>>52458705
>The name LISP sounds very faggy, Haskell sounds awesome
enough said
>>
>>52461099
>Is this C?
Yes.
It's also using VLAs, which is a feature that C++ doesn't have.
>>
C++ uniform initialization makes me feel warm and fuzzy inside
>>
>>52461220
>whatever that means
lmfao hahasklel tards don't even know big O
>>
someone explane monads and why >>= (bind) is useful?

my take is that monads are things with context, and bind just extracts things from things with context, does something with it, and puts it back in that same context
>>
>>52461227
functional isn't hard it's just shit and useless when imperative works perfectly fine for all purposes

FP literally has blood on its hands. shame on you.
>>
File: 1447238155229.png (78 KB, 300x356) Image search: [Google]
1447238155229.png
78 KB, 300x356
>>52461158
no
>>
>>52461239
having to create a potential large array on the stack, which usually has only little space available, isn't good. The argument is, if you know the size beforehand, you can use a static array. And if you don't know the size beforehand, you will write unsafe code
>>
>>52461243
i know what is it, why does it matter that u need O(n) space, O(n) time complx is what matters, plus, you can't store a couple bytes in ur 16gb ram?
>>
pre vs postfix increment operator.... wat do
>>
>>52461260
That's one interpretation.
Monads are useful because they're a common interface to many things. That's it.

>>52461261
>a shitty C implementation of recursion without tail calls reflects on FP
>>
>>52461273
As long as you're not allocating shit that is megabytes big, it'll be fine.
>>
>>52461285
THIS IS WHAT HASKELEL TARDS ACTUALLY BELIEVE

have fun never writing any non-useless high-performance application
>>
File: e.png (570 KB, 498x426) Image search: [Google]
e.png
570 KB, 498x426
>>52461145
For what purpose?
>>
>>52461288
PRE UNLESS POST IS RELEVANT FOR THE RESULT
>>
File: c1920x1080_18.jpg (116 KB, 1920x1080) Image search: [Google]
c1920x1080_18.jpg
116 KB, 1920x1080
>>52461261
>it's just shit and useless when imperative works perfectly fine for all purposes
lol
>cars are shit and useless when horses work perfectly fine for all purposes
>Cars literally have blood on its hands. shame on you.

FP is just a tool. Use the right tool for the right job. Most modern languages incorporate functional concepts these days. Expect that trend to continue.
>>
>>52461311
See >>52461204.
>>
File: 1445385784800.gif (1 MB, 720x480) Image search: [Google]
1445385784800.gif
1 MB, 720x480
>>52461285
>plus, you can't store a couple bytes in ur 16gb ram
>>
>>52461323
FP is never the right tool for the job except for "programs" that are essentially glorified math expressions
>>
>>52461311
fp is created not for optimization, but for better writing of the code, which allows for 1/16th the amount of code u write in imperative
even shitty programs thtat requiere too much mem in python are still used because of the abundance of ram, faggit
>>
>daily us vs. them thread
>>
>>52461342
less code != better
>>
>>52461291
What's another interpretation though?
So, you're saying monads are basically like functors, except they support something else, otherwise, no moands would of been.
I just wanna know exactly what they do different.
>>
>>52458494
Gtfo
>>
>>52461353
>this is what imperative fags think FP is about
I kek every time
Thread replies: 255
Thread images: 37

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.