Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Programmer's Music Mix for Dark Minds

Name: Anonymous 2016-12-30 0:47

Get to work
Enterprise IntelliJ Java Beans and Node.js ES6 Enterprise frameworks
Pajeet just won't stop talking about his shitting street
Need something to cut out the noise
Can count on Programmer's Music Mix for Dark Minds every time

https://www.youtube.com/watch?v=6dkqVj7heiA

Name: Anonymous 2017-01-05 3:26

>>7
It supports functional programming a lot better than C. JS makes partial application trivial:

function add(a, b) {
return a + b;
}

function multiply(a, b) {
return a * b;

function partialApplication(func, arg) {
return function(n) {
return func(arg, n);
}
}

var addToFive = partialApplication(add, 5);
var multiplyBySeven = partialApplication(multiply, 7);

addToFive(3); //8
multiplyBySeven(9); //63


The equivalent code in C is quite clumsy, and the resulting partially-applied functions will always stand out from "real" functions:

#include <stdio.h>

int add(int a, int b) {
return a + b;
}

int multiply(int a, int b) {
return a * b;
}

typedef struct {
int (*func)(int, int);
int arg;
} closure;

closure partialApplication(int (*f)(int, int), int n) {
closure c;
c.func = f;
c.arg = n;
return c;
}

int call(closure c, int x) {
return c.func(x, c.arg);
}

int main(void) {
closure addToFive = partialApplication(add, 5);
closure multiplyBySeven = partialApplication(multiply, 7);
call(addToFive, 3);
printf("%d\n", call(addToFive, 3)); //8
printf("%d\n", call(multiplyBySeven, 9)); //63
return 0;
}

Name: Anonymous 2017-01-05 3:44

>>7-8
JavaScript is Lisp. Lispers made JavaScript to spread Lisp ideas to the masses as the epitome of good.

It was their "Trojan horse" for embedding dynamic typing, Lisp-style garbage collection, Lisp-style dynamic OOP, etc. into a program the masses will have on their computer (web browsers).

Lispers originally planned to use a dialect of Scheme, but they made JavaScript so Lisp would remain free from criticism.

They knew from experience that when Lisp ideas become popular, they become hated, so Lisp must always be a minority.

Name: Anonymous 2017-01-05 5:27

smoke weed everyday.

Name: Anonymous 2017-01-05 6:27

check dubs everyday

Name: Anonymous 2017-01-05 7:26

>>9
Javascript definitely had some Lisp influence (as did other dynamic languages) but its lack of homoiconicity makes metaprogramming much harder (in JS, code generation is rarely used for any serious task; in fact, it's usually done to either minify or obfuscate the code as opposed to extending the language), and metaprogramming is one of the biggest draws of Lisp.

Name: Anonymous 2017-01-05 9:53

>>8
What is the point of partial application?
#define add(a,b) (a)+(b)
#define add5(b) add(5,b)
int n=6;
int r=add5(n)// Same thing

Name: Anonymous 2017-01-05 10:01

>>13
the point of partial application is to create more specialized functions at runtime. practical example: I do it a lot in the game I'm writing and the resulting functions are dependent on values not known at compile time so making a C macro or C function is not viable. as to why you'd need more specialized functions, it depends on the programming style you're using but it's obviously a pretty common need in FP. I'm not doing pure FP in my game (I'm using FIOC) but partial application helps me combine generic functions and runtime data into something that fits the required interface.

Name: Anonymous 2017-01-05 10:15

>>14
There is no magic barrier from ``the runtime''
#include <stdio.h>
#define add(a,b) (a)+(b)
#define add5(b) add(IamARunTimeVariable,b)
int getnum(void){
int num;
printf("Enter a RunTime variable: ");
scanf("%d", &num);
return num;
}

int main(void){
int IamARunTimeVariable=getnum();
int n=6;
int r=add5(n);

printf("\n Result:%d:\n",r);
return 0;}

Name: Anonymous 2017-01-05 10:31

//rewritten to concise macro style i normally use
#include <stdio.h>
#define getnum() ({int num; printf("Enter a RunTime variable: "); scanf("%d", &num); ;num;})
#define add(a,b) (a)+(b)
#define addnum(b) add(getnum(),b)
int main(void){
printf("\n Result:%d:\n",addnum(6));
return 0;}

Name: Anonymous 2017-01-05 10:58

Bonus for >>8 you don't need the verbose drivel to create function in JS
var add=(a,b) => (a)+(b);
var addToFive = (n)=>add(n,5);
alert(addToFive(1))

Name: Anonymous 2017-01-05 11:04

>>17
this syntax looks quite nice, completely unlike most of the javashit I've seen (which manages to be both verbose and inconsistent at the same time). maybe it's not such a bad language after all.

Name: Anonymous 2017-01-05 11:07

>>8 Its only due ES6 standard syntax being implemented in major browsers. Its basically a shorter way to write:
var add=function(a,b){return (a)+(b)}
var addToFive = function(n){return add(n,5)}
alert(addToFive(1))

Name: Anonymous 2017-01-05 11:10

>>19
I know it's a syntactic sugar but it's both clear and concise. you can write lambdas this way, right? if so, javashit would be an implicit var away of not being a pain in the ass to read and write.

Name: Anonymous 2017-01-05 11:20

>>20

alert([1,2,5,10,25,100,250,500,100].map((n)=>n*n))

Name: Anonymous 2017-01-05 11:33

Additionally javascript objects are all associative arrays so this works too:
var funcname=prompt("Enter function name","map");
alert( [1,2,5,10,25,100,250,500,100] [funcname] ((n)=>n*n) )

Name: Anonymous 2017-01-05 12:27

>>21-22
nice javashit FP and nice dubs. looks like I'm going to add JS to my list of languages that don't necessarily suck but are often misused horribly.

Name: Anonymous 2017-01-05 16:52

>>22
That's more proof that JavaScript is Lisp.

[1,2,5,10,25,100,250,500,100] ["map"] ((n)=>n*n)

Name: Anonymous 2017-01-07 0:43

class Mapper {
constructor() {
this.target = null;
this.operation = null;
}
setTarget(target) {
this.target = target;
}
setOperation(operation) {
this.operation = operation;
}
map() {
var result = new Array(this.target.length);
for (var i = 0; i < this.target.length; i++) {
result[i] = this.operation.run(this.target[i]);
}
return result;
}
}

class Squarer {
run(value) {
return value * value;
}
}

var mapper = new Mapper();
mapper.setTarget(new Array(1,2,5,10,25,100,250,500,100));
mapper.setOperation(new Squarer());
mapper.map(); // [ 1, 4, 25, 100, 625, 10000, 62500, 250000, 10000 ]

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List