[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: 31
File: logocaml-oreilly.gif (5 KB, 375x352) Image search: [Google]
logocaml-oreilly.gif
5 KB, 375x352
old thread >>52538609

What are you working on, /g/?
>>
STATIC TYPING

NO TYPE INFERENCE

NO OPERATOR OVERLOADING

JAVA ÜBER ALLES

SIEG HEIL
>>
>>52543079
>not using an anime trap image

Fuck you. go back to reddit. This is an anime thread. fuck programming
>>
>>52543079
Official OCaml thread! My dream is finally realized! My God has answered my prayers! Praised be to him! Another 1000 lines of code shall be sacrificed to His Glory!
>>
>>52543116
>NO OPERATOR OVERLOADING
While it gets messy, I'd like something like "scoped operator overloading".
You'd explicitly state what operators get overloaded with what and its only in that file/block
>>
File: 1453201739293.png (2 MB, 514x989) Image search: [Google]
1453201739293.png
2 MB, 514x989
>>52543163
>>
>>52543212
So, like in ocaml then.
>>
>>52543211
307 posts, no new thread. I had to do it. So I did it.

OCAML MASTER RACE

let not_yet s _ = failwith (Printf.sprintf "not yet: %s" s);;

let fdebug f =
if Config.get_debug () then
Format.eprintf "@[<2>#%f %t@]@." (Sys.time ()) f
;;

let mmod a b =
let c = a mod b in
if c < 0 then c + b else c
;;

let map f l = List.rev (List.rev_map f l);;

let append l1 l2 = List.rev_append (List.rev l1) l2;;

let with_open_in file f =
let ic = open_in file in
try
let r = f ic in
close_in ic;
r
with
| x ->
close_in ic;
raise x
;;
>>
>>52543233
>writing in topscript
>2016
>>
>>52543279
topscript?
>>
>>52543227
ocaml doesn't even have function overloading
>>
>>52543116
>NO OPERATOR OVERLOADING
I never got why people wanted to avoid this. In my mind this is just equivalent to allowing people to come up with their own function names. Nothing is preventing anybody from writing a function plus : R -> R -> R which actually multiplies the arguments instead of adding them.
>>
>>52543289
>function overloading
Totally useless.
>>
>>52543289
MyModule.(overloaded 3 4)
Dicks.(overloaded 8 9)
MyModule.overloaded 3 (Dicks.overloaded 18 29)
???????????????
?????
>>
>>52543293
you don't need both. functions/methods are sufficient. without operator loading you ALWAYS know what an operation does regardless of the context of the code. also a function/method name can be much more expressive and descriptive than just a symbol.
>>
>>52542929
>maximum damage control
>>
What's the best/fastest algorithm for comparing elements in an array, generating a new array of links between them in which link[i,j] == link[j,i]? I mean don't compute a link if the reverse link exists.
>>
>>52543327
It really makes things a lot less clear when you have to do a lot of calculations with non-primitive types like matrices or polynoms.
>>
>>52543293
because most of the programmers are mediocre.
>>
>>52543354
That's what delimited overloading is for. Be it with
open Module

or
Module.(everything in here uses the overloaded methods until the last paren)
>>
>>52543321
I don't know what that's supposed to be but it ain't overloading.
>>
>>52543293
if you write a function called plus then it's clear as day that a * b is a mistake. if you overload + to be * then you'll be like "what the fuck?" and not be sure what the author really meant, like maybe they did it as a lazy hack to intentionally change from addition to multiplication?
>>
>>52543401
Could be a typo. For example you're binding cublas for your language and the signature for * and + is the same, so you copy-paste and forget to change the name of the function being called. Point is, operator or function overloading should be treated the same since it has the exact same properties.
>>
>>52543460
except operator overloading fucks with basic language features
>>
>>52543460
if they have the exact same properties, why do you need both? why give up the benefit of always knowing what an operator does, never having to even consider that it might be doing something non-standard?
>>
>>52543481
Such as?
>>
>>52543502
Operators?
>>
>>52543481
Then you should not create a function called log that logs messages. You also shouldn't define a function add that adds matrices together. You shouldn't have a method called next. Inheritance should never be used. Multiple dispatch? Pah! Even single-dispatch should not be allowed!
>>
>>52543460
>since it has the exact same properties.
not necessary, operators can be infix or postfix and have an order of evaluation
>>
O b j e c t i v e s h i t
>>
>>52543500
The exact same statement is true with regard to any function name whatsoever. That's the whole point.
>>
>>52543516
That's standard library stuff that doesn't happen without an include.
>>
I'm making a web crawler and I want to use TOR to not get shitlisted.

System.setProperty("socksProxyHost", "127.0.0.1");
System.setProperty("socksProxyPort", "9050");


Is this enough for IP rotation? How can I further beef up the anonymity aside from random request delays and random link clicking order?
>>
>>52543528
B u t t h u r t
You couldn't name a single flaw in the language that isn't you being struck with a deeply ingrained case of the baby duck.
>>
>>52543536
>core language features and automatically included basic symbols are library stuff that doesn't happen without an include
>>
>>52543513
Doesn't fuck with them if we do not give any type operators by default.
>>
File: giphy.gif (969 KB, 500x281) Image search: [Google]
giphy.gif
969 KB, 500x281
Ask yo beloved programming literate anything.

>tfw there no operators in lisp, only procedures.
>>
>>52543530
fucking idiot
>>
File: 1452450461467.png (17 KB, 418x359) Image search: [Google]
1452450461467.png
17 KB, 418x359
>>52543528
>I don't understand this
>It must be shit
>>
>>52543550
I was talking about functions like log, retard.
I don't care about your babbling about OOP stuff.
>>
>>52543566
fucking inbred
>>
>>52543569
>C is OOP
you heard it here first, folks!
>>
>>52543543
ocaml's oo is shit, even ocaml shills admit that.
>>
>>52543572
you need at least one or the other, and having both is redundant. functions with definable names is the obvious choice. with just operator overloading you'd run out of symbols really quickly.
>>
>>52543579
C has inheritance and methods now?
And they're not OOP?
How fucking dumb are you?
>>
>>52543584
It's the best OOP, it's just that OCaml shills hate OOP. Bust OOP in OCaml is goat.
>>
>>52543116
>no type inference
why.jpg
>>
>>52543616
inb4 12+ hours of spergrage
>>
>>52543616
at least OCaml's kind of type inference is completely retarded
>>
>>52543584
Actually it's the best implementation by far.
>row AND column polymorphism
>pattern matching and least requirements
>multiple inheritance and packing
Literally GOAT
>>
>>52543592
Both and neither work perfectly. Namespaces (such as modules, and then inclusion for overloading) are used to disambiguate.
>>
>>52543604
>inheritance
Can be implemented

>methods
Assuming you mean "virtual functions", then yes, can also be implemented.

However, inheritance and virtual functions are no requirement to be classified as object-oriented. There are many multi-paradigm languages that support OOP without a native implementation of inheritance, JavaScript or Common Lisp for example.
>>
>>52543633
Found the retard.
>>
>>52543667
>Can be implemented
Then they're not basic language features are they?

Are you a fucking gold fish? It's like you always forget everything before the last post.
>>
>>52543692
it's the way of the sperg
>>
>>52543644
Multiple inheritance is disgusting
>>
>>52543592
>with just operator overloading you'd run out of symbols really quickly
You do realise operators can consist of more than one symbol?
>>
>>52543703
THIS

JAVA ÜBERMENSCH
>>
File: 1436550309041.png (491 KB, 724x674) Image search: [Google]
1436550309041.png
491 KB, 724x674
>>52543667
doing oop with c and c being an oopl are two different things
>>
>>52543703
>delicious
FTFY
Enjoy your 2000-deep class hierarchies or copy-pasta code all over the place.
>>
>>52543712
so you'd have code like a b c;

or

bitch nigger;


great...
>>
>>52543718
Tell that to >>52543569
>>
>>52543692
>Then they're not basic language features are they?
No one said so

>Are you a fucking gold fish?
Ditto. The question was whether or not C can be considered OOP.

Neither inheritance nor virtual functions are necessary to be classified as OOP. I just pointed this out.
>>
>>52543592
But they are _not_ redundant. Operator overloading provides a terse way to call functions with non-terse names. Let M be some arbitrary monoid with an arbitrary binary operator ⋆, and x, y, z ∈ M. Then compare x ⋆ y ⋆ z to x.arbitraryBinaryOperator(y.arbitraryBinaryOperator(z)).
>>
>>52543079
>>52543233
> OCaml
Why if we have Rust now?
>>
>>52543713
But Java has multiple inheritance...
>>
>>52543729
nice meme
>>
File: f3h2eqZr.jpg (79 KB, 1080x540) Image search: [Google]
f3h2eqZr.jpg
79 KB, 1080x540
i stopped reading here. on page 272. did they think they were fucking kawaii or something?
>>
>>52543720
There's that thing called composition you know...

Only good OOP is Go's (if it didn't lack polymorphism)
>>
>>52543731
>rust
Laughing_whores.jpg
>>
>>52543735
you can implement multiple interfaces but you can't subclass more than one class.
>>
>>52543725
What? Most languages I have used had operators with more than one symbol.

>=, <=, !=, ==
>>
>>52543728
>No one said so
It's what started this discussion!

Fuck you, I'm done talking to you.
>>
>>52543741
post pdf
>>
>>52543735
No it does not.
>>
>>52543750
In other words, multiple inheritance.
>>
>>52543756
you would be so fucking disgusted you would vomit out of your eyeballs if i did
>>
>>52543751
you'll run out of them if you use them like functions you idiot

and they're horribly nondescript outside of their standard functionality.
>>
>>52543743
I laughed so much that I couldn't laugh anymore. Well played.
>>
>>52543762
>The Java programming language supports multiple inheritance of type, which is the ability of a class to implement more than one interface. An object can have multiple types: the type of its own class and the types of all the interfaces that the class implements. This means that if a variable is declared to be the type of an interface, then its value can reference any object that is instantiated from any class that implements the interface. This is discussed in the section Using an Interface as a Type.

https://docs.oracle.com/javase/tutorial/java/IandI/multipleinheritance.html
>>
>>52543767
kill yourself idiot
>>
>>52543771
This is why I ask for a pdf, I want to see how shit it is.
>>
>>52543777
You won't run out of them any more than you would run out of function names. I didn't say anything about them being descriptive, just that most languages support operators with multiple symbols, unlike what you claimed.
>>
>>52543789
>I have literally no idea what inheritance is
t. java devs
>>
>>52543793
>wahh someone pointed out my ignorance
Grow up.
>>
>>52543789
the "multiple inheritance" in java is a restrictive form where you can only implement multiple INTERFACES (which are not classes by themselves) and you can NOT derive from more than one base class. it's not what you typically mean when you say multiple inheritance.
>>
>>52543805
I can't find a pdf of the whole thing just the first 2 chapters. i only own a physical copy. It makes extensive use of scanf and has many many typos and shit that makes the program not compile or run
>>
>>52543835 (Me)
like if you lay it out like a family tree, then each class in the "family" will inherit from exactly one parent. classes can also implement interfaces, but those interfaces do not have a family tree of their own.
>>
>>52543538

Please respond.
>>
>>52543874
>but those interfaces do not have a family tree of their own.
That's wrong if you mean inheriting other interfaces.
>>
>>52543897
a subclass inherits the interface from its parent class. there is only one "trunk".
>>
>>52543741
>a little faster getch
Are we back to conio.h DOS days?

>main()
>no return type
>no void
>claims it's updated for C11
lol
>>
>>52543924
a subclass can use other interfaces additionally and the interfaces can also inherit from multiple other interfaces
>>
>>52543932
main() is a valid signature
>>
>>52543932
that's what i'm saying and this was my first programming book and i can't believe pearson, a company i used to work for would allow having its name on such shit
>>
>>52543741
>Your computer knows 256 different characters. Each of them is found in something called the ASCII table, located in Appendix A, “The ASCII Table.” (ASCII is pronounced ask-ee. If you don’t know-ee, you can just ask-ee.) Anything your computer can represent can be a character
>>
>>52543948
1: Not in C11
2: You actually need the (void) or the signature will not be the one that the standard supports.
>>
File: screen.png (51 KB, 596x656) Image search: [Google]
screen.png
51 KB, 596x656
>>52543948
ok buddy
>>
>>52543969
void is only needed in prototypes, tard.
>>
>>52543989
Who told you this shit?
>>
File: inheritance.png (31 KB, 781x1024) Image search: [Google]
inheritance.png
31 KB, 781x1024
>>52543938
ah, didn't know that or i didn't have that in mind. still, it's not quite the same as the kind of multiple inheritance where you can derive from multiple parent classes.
>>
>>52543948
http://stackoverflow.com/a/29190987
>>
>>52543984
what am I supposed to be looking at here? it compiles fine

>return 0
kek
>>
>>52543753
>It's what started this discussion!
Are you high? What started the discussion was someone claiming that C is object oriented....

You said "MUH INHERITANCE" and I pointed out that inheritance isn't a prerequisite for being object-oriented.

>Fuck you, I'm done talking to you.
There's no need to be upset anon.

>>52543750
>you can implement multiple interfaces
And this isn't multiple inheritance how exactly?
>>
>>52543969
standards conforming and valid are not mutually inclusive

>>52544014
did you even read what you linked?
>>
>>52544040
No implementation is inherited therefore it's not multiple inheritance you fucking inbred.
>>
>>52544040
you can't inherit from multiple parent classes you dipshit.
>>
File: f3h2eqZrr.jpg (470 KB, 2322x4128) Image search: [Google]
f3h2eqZrr.jpg
470 KB, 2322x4128
>>52544018
but i get a warning for returning an int, which is what the book says you have to do at the end of every program.
just dont buy this book.
>>
>>52544048
>did you even read what you linked?
Yes
>>
>>52544062
It actually allows to get the same results.
Just needs some more boilerplate.
>>
>>52544040
>I pointed out that inheritance isn't a prerequisite for being object-oriented

http://cs.smu.ca/~porter/csc/common_341_342/notes/oop_3pillars.html
>>
Am I strange if I find Haskell to be very ugly?
Nice language but I don't get why so many people claim it is beautiful...
>>
>>52544084
you actually can't get exactly the same results without merging two parent classes into one. an interface can only have public methods and public final variables.
>>
>>52544099
Do you find ALL Haskell ugly? Like any language you can write bad code in it if you want.
>>
>>52544002
c standard, tard.
>>
>>52544118
prove it fag
>>
>>52544109
public static final variables, even
>>
>>52544124
Who exposes member variables directly in Java?
>>
>>52544090
he's right, to do oop you only need objects. inheritance is not required.
>>
File: IpsYFZC.jpg (444 KB, 2322x4128) Image search: [Google]
IpsYFZC.jpg
444 KB, 2322x4128
>scanf(" $%f")
>just find the file and double click it.
>>
>>52544131
it's perfectly fine to do it, especially final variables.
>>
File: 160315.jpg (52 KB, 590x844) Image search: [Google]
160315.jpg
52 KB, 590x844
Redpill a C++ guy on Web dev.

Do Javascript and php serve the same purpose?
What about python and ruby for Web dev? What are their use cases?
>>
>>52544115
I mean, most Haskell code I find on github... Dunno if it is so bad (I know some Haskell, but pretty basic things)
>>
>>52544099

You don't know Haskell good enough. At first it seems ugly, but at some point it'll all make sense and make debugging and refactoring so much easier
>>
>>52544185
Likely.
But still... meh.
>>
>>52544170
Not if it contains something mutable.
>>
>>52544206
Not him, but why?
>>
File: scr.png (63 KB, 630x513) Image search: [Google]
scr.png
63 KB, 630x513
>>52544123
lel, are you really this retarded ? please don't be this retarded.

pic, and there many examples in the standard with int main() {...}
>>
Blog about your day
>>
>>52544221
Because final doesn't protect the (same) object from being changed?
>>
>>52544236
Sorry, misunderstood, I don't even know what you're talking about...
>>
>>52544183
What do you find ugly about this?

map :: (a -> b) -> [a] -> [b]
map f (x:xs) = f x : map f xs
map _ [] = []
>>
>>52544123
>>52544228
also, at 6.7.6.3 Function declarators (including prototypes)

14 An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied.

get #rekt
>>
>>52544228
What the fuck? This is not this PDF of the standard.
And read the stackoverflow link.
>>
>>52544289
Not him, but everything
>>
>>52544231
I spent the morning with my boyfriend and then played around with knockout.js for a bit. it's 4pm now so pretty quiet day so far. probably going to make dinner and watch some anime together in a while
>>
>>52544293
>>52544294
Not to mention that you kiddo have to still prove that main() without the int part is valid.
>>
>>52544328
That's my day expect the being awake at morning part, the boyfriend or anyone part, the js part, make dinner part (unless coffee and cigarettes count), and together part
>>
>>52544310
How would you rather it looked?
>>
>>52544328
What anime?
>>
>>52544362
>unless coffee and cigarettes count
Do you live in an ex-USSR state?
>>
>>52544231
i got so disgusted with a programming book that i decided to stop reading it even though i payed for it. Also i beat the first boss in dark souls 1
>>
File: tGKIDM8.jpg (115 KB, 650x650) Image search: [Google]
tGKIDM8.jpg
115 KB, 650x650
>>52544334
what do you not understand in

>An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters.

http://www.open-std.org/jtc1/sc22/wg14/www/standards

>The latest publically available version of the C11 standard is the document WG14 N1570, dated 2011-04-12. This is a WG14 working paper, but it reflects what was to become the standard at the time of issue.

now search for
int main() {
in the standard
>>
>>52544383
Welcome to the N.H.K.
>>
>>52544328
web devs everyone
>>
>>52544401
Still waiting for you to prove that you do not need int in main.

>>The latest publically available version of the C11 standard is the document WG14 N1570, dated 2011-04-12. This is a WG14 working paper, but it reflects what was to become the standard at the time of issue.
I know that, why do you post random things?

Why haven't you read http://stackoverflow.com/a/29190987 yet? Funny you talk about damage control but you ignore everything I post, lol
>>
>>52544374
What does it even do? Define a recursive map function?
func map(f, l) {
if (l = null) {
return null
} else {
return pair(f(l.first), map(f, l.rest))
}
}
>>
What is your normal day like, /dpt/?

>Stay idle 70% of my time on the job, mostly on reddit and /g/
>The other 30% is spending my time fixing non-issues
>60k a year

Web design is where it is, gentlemen.
>>
>>52544386
Nope, Europe.
>>
File: B-boo!.png (584 KB, 1000x1000) Image search: [Google]
B-boo!.png
584 KB, 1000x1000
Stupid question, but in OCaml, how can I know for certain my function is performing tail-recursion instead of creating a bunch of stack frames? I mean I don't do anything else with the recursive call's return value, is that good enough to say it's going to be tail-recursive?
>>
File: 161017757_44042348.jpg (67 KB, 590x632) Image search: [Google]
161017757_44042348.jpg
67 KB, 590x632
>>52544444
the standard itself has main() {} in their examples, the semantics of the language rule that () and (void) are the same when it come to function definition (not a prototype). why the fuck are you still arguing ?

>stack overflow has more authority than the standard itself.
dude, you are going full retard. i don't care a shit about stack overflow, it's a refuge for mediocre programmers like you
>>
>>52544493
>He fell for the meme
>>
>>52544176
Sup, fellow CPP guy. Javascript runs on your browser, while php runs on the server.

python and ruby are shit for webdev. I don't know any cases where the python/ruby is actually better than Javascript/php.
>>
>>52544468
You honestly find that less ugly than the Haskell code? To each their own I suppose.
>>
>>52544493
use a loop
>>
>>52544501
>standard itself has main() {} in their examples
Nope, nice shiposting

>stack overflow has more authority than the standard itself.
nice try proving him wrong lol
>>
>>52544513
It has all those things that make shit readable like clear keywords, indentation, clear blocks, etc.
>>
>>52544310
what about

map :: (a -> b) -> [a] -> [b]
map f = \case
[] -> []
x:xs -> f x : map f xs
>>
>>52544501
DAMAGE CONTROL
A
M
A
G
E

C
O
N
T
R
O
L
>>
>>52544547
horrible
>>
>>52544289
ridiculously terse with no meaningful function name or variable names or anything like you have to read the entire thing to have the vaguest idea of what it does

too many fucking symbols

>>52544099
no it's one of the ugliest languages in existence
>>
File: 6Qc1svk9zc.jpg (157 KB, 1920x1080) Image search: [Google]
6Qc1svk9zc.jpg
157 KB, 1920x1080
I'm a website developer thinking of moving to game development (Still thinking what kind of game development). Any advice from any game developers? c:
>>
>>52544501
proof or gtfo
>>
>>52544564
>>52544571
map :: (a -> b) -> [a] -> [b]
map = fmap
>>
>>52544509
I've never used php, heard everyone saying that it's bad but improved with recent versions.
Ruby on rails or php?
>>
>>52544544
>Nope, nice shiposting

from 6.7.6.3 Function declarators (including prototypes)
 void addscalar(int n, int m,
double a[n][n*m+300], double x);
int main()
{
double b[4][308];
addscalar(4, 2, b, 2.17);
return 0;
}
void addscalar(int n, int m,
double a[n][n*m+300], double x)
{
for (int i = 0; i < n; i++)
for (int j = 0, k = n*m+300; j < k; j++)
// a is a pointer to a VLA with n*m+300 elements
a[i][j] += x;
}


from 6.7.6.3 Function declarators (including prototypes)
         #include <stddef.h>

size_t fsize3(int n)
{
char b[n+3]; // variable length array
return sizeof b; // execution time sizeof
}
int main()
{
size_t size;
size = fsize3(10); // fsize3 returns 13
return 0;
}
>>
>>52544133
No, you only need polymorphic messages.
>>
>>52544493
If it's a tail call then it's tail recursive :^)
>>
>>52544581
sounds like you're too retarded to make a proper game you should just give up and use a babby engine like unity and go to >>>/vg/agdg
>>
>>52544593
PHP (imo)
>>
>>52544581
C++
>>
>>52544547
what does a name at the beginning of a line mean?
what does "::" mean?
what does "->" mean? return? why is it chained? is that some currynigger shit?
what do a and b mean in that position?
what do the brackets mean?
what does f mean in that position?
why the hell is there a backlash?
what do the brackets mean?
what does x and xs mean?
what does the colon mean?
what does the other colon mean?
how is case terminated?
>>
>>52544594
>int main()
nice back-pedalling, it's not main() {} (something that you were supposed to prove that the standard allows)
>>
>>52544547
disgusting

>>52544592
still disgusting
>>
>>52544606
It 'sounds' like you're too socially awkward to go outside so you should just keep doing what you're doing and don't give up. <3

>>52544610
I'll check it out!
>>
>>52544493
If you don't sequence operations after the recursive call, then it's a tail-call.
>>
>>52544546
>clear keywords, indentation, clear blocks, etc.
The code is so short it doesn't need keywords or indentations. One could say your code isn't readable as it has zero type information, something which is essential in statically typed languages.

If you wanted you could write it as this:
map func list =
if null list then
[]
else
head list : map func (tail list)


Colon in Haskell is analogous to cons in other languages.
>>
>>52544622
#include <stdio.h>
int main(int argc, char** argv) {
printf("hello world!\n");
}

What does int mean?
What does a name between int and parentheses mean?
What does () mean?
What does #include mean? Import? Why is the file in brackets? Is that some template shit?
What do " and \ mean in that position?
What do the semi-colons mean?
What does f mean in that position?
Why the hell is there a backslash?
What do the semi-colons mean?
What does argc and argv mean?
What does the star mean?
What does the other star mean?
How is main terminated?
>>
>>52544581
>reddit meme
>c:
>webdev
my advice for you is to first fuck off, then die
>>
>>52544713
make sure you fuck off first
>>
File: 1445490144309.jpg (306 KB, 992x767) Image search: [Google]
1445490144309.jpg
306 KB, 992x767
>>52544538
But I want to be hip and cool.

>>52544663
Hmm, okay I was wondering if there was a way to test it, but I guess that will have to do.
>>
>>52544571
https://en.wikipedia.org/wiki/Map_(higher-order_function)

I'm not sure what name would be more meaningful than map when it's a commonly used term.

In mathematics f is a commonly used to denote a function, and x is commonly used to refer to a variable a function is applied to. Since (x:xs) splits it into a head and tail, xs is literally a group of x (pronounced eccses).

Objectively I don't see how it's that terse when you spend a little time getting to know the language. Nobody is going to understand mathematical notation without learning it, so why should it be any different with Haskell? A little learning goes a long way.
>>
>>52544493
first search on google
https://cseweb.ucsd.edu/classes/sp15/cse130-a/static/tailrecursion.pdf
>>
What's the best Java book for someone with around 3 years of experience? Started with Head First Java which was okay, but I'd like a decent book now to continue developing my skills.
>>
A lot of you guys have legit autism.
>>
>>52544674
you could just as well do something like
list(T) func map(T func(T) f, list(T) l)


and your example is still kinda shit - function calls without parenthesis are disgusting and who the hell uses brackets for lists?
>>
>>52544748
so you're programming essentially a glorified math expression

what are you going to use it for?
>>
>>52544176

Python, ruby, node.js (JavaScript), php are used for the back end (servers)

JavaScript runs in browsers (front-end, client side) and can interact with the DOM to bring about behavior.

Don't listen to the memes about what is bad and what is good. Everything is a tool and it comes down to personal preference and what you want to do.
>>
>>52544804
and a lot of you webkeks will never make a commercial game unless you use a hand-holding tool like unity to make some shitty youtube bait to put on steam greenlight
>>
>>52544809
Only absolute beginners program their own map, it's already built into every functional language.
>>
File: bower.json.jpg (105 KB, 394x700) Image search: [Google]
bower.json.jpg
105 KB, 394x700
>>52544821
Node is also the fastest by a mile.
>>
>>52544834
map in OCaml is not tail rec.
>>
>>52544735
>Hmm, okay I was wondering if there was a way to test it, but I guess that will have to do.
I'm not sure why you would want to do that but you could just run GDB to see that the tail calls are optimized if you don't believe it.
>>
>>52544842
Then OCaml is garbage.
>>
>>52544842
Nobody uses the default standard library in OCaml because it is not meant for actual use, it is the minimal set of operations required to build the compiler. That's why Core exists.
>>
>>52544798
Effective Java, perhaps?
>>
>>52544859
>Core
>30MB executables after running GNU strip
choose both
>>
>>52544622
>what does a name at the beginning of a line mean?
That's the name of the function we are defining.

>what does "::" mean?
"Has type" as in, "map has type..."

>what does "->" mean? return? why is it chained? is that some currynigger shit?
Yes, it's currying. It simply means what's on the function takes what's on the left of the arrow and returns something that takes what's on the right. That's why the last item can be seen as the return type, as it cannot be applied to anything else.

e.g.
add :: Int -> Int -> Int
add x y = x + y

addOne = add 1 (has type of Int -> Int)
two = addOne 1 (has type of Int)


>what do a and b mean in that position?
They are variables, they can be any type possible such as Int, Bool, etc.

>what do the brackets mean?
A list.

>what does f mean in that position?
It's an argument to map of type (a -> b)
>>
>>52544909
>being this dumb
>>
File: run.gif (13 KB, 84x62) Image search: [Google]
run.gif
13 KB, 84x62
Would anyone mind posting the programming challenges for their kouhai? thx doc
>>
>>52544807
>function calls without parenthesis are disgusting
Subjective. Writing f(x) is valid Haskell if you are so inclined.

>who the hell uses brackets for lists?
Many languages. Though similar but not the same, mathematics uses brackets for matrices.
>>
>>52544707

PART 1/2

C++ wizard

>What does int mean?
Int means that the function retuns an integer.

>What does a name between int and parentheses mean?
the name of your function

>What does () mean?
It shows what your function receives from outside.

>What does #include mean? Import? Why is the file in brackets? Is that some template shit?
It means it imports important common functions in order to you dont have to actively put them on your code. The file on brackets is one f the standards In-Out header of functions.

>What do " and \ mean in that position?
" " mean the start and end of your string. \ doesnt mean anything by itself, but with n (\n) it makes the string go to the next line.

>What do the semi-colons mean?
They mean the end of a command.

>What does f mean in that position?
Nothing. Printf is a function that was inheretid from the stdio.h you included in the header.

>Why the hell is there a backslash?
Read the answer above.

>What do the semi-colons mean?
Read the answer above.

>What does argc and argv mean?
They give the programmer access to the command prompt where the program was called. argc is an integer and argv is a vector.

>What does the star mean?
Read above.

>What does the other star mean?
Read above.

>How is main terminated?
A function is written within brackets { }.
>>
File: Bait.png (220 KB, 387x545) Image search: [Google]
Bait.png
220 KB, 387x545
>glorified math expression
If I had a nickel
>>
>>52544983
This is the dumbest post on 4chan currently. Congrats. Haven't seen someone be this wrong in a while.
>>
2/2

Haskell faggot
>what does a name at the beginning of a line mean?
LIKE WHAT? DIDNT YOU TAKE MATH 605 TO KNOW THAT?

>what does "::" mean?
HAHA, I KNOW IT AND YOU DONT

>what does "->" mean? return? why is it chained? is that some currynigger shit?
IT GIVES YOU SOMETHING, LIKE I GAVE YOUR MUM AIDS LAST NIGHT

>what do a and b mean in that position?
NEURAL COMPUTATIONAL STIMULI

>what do the brackets mean?
YOU WANNA START SOMETHING AND END SOMETHING? THAT IS WHAT THE BRACKETS ARE FOR

>what does f mean in that position?
IS THE NAME OF THE FUCK YOU WANNA MAKE

>why the hell is there a backlash?
IF YOU DONT KNOW YOU DONT DESERVE TO KNOW

>what do the brackets mean?
DIDNT I JUST SAY TO YOU?

>what does x and xs mean?
XIR AND XISS

>what does the colon mean?
THE COLON CANCER YOU GAVE ME

>what does the other colon mean?
THE AIDS

>how is case terminated?
>HE DOESNT INDENT HIS CODE
>>
>>52544863
I've heard good things about Effective Java. I'll check it out, thanks man!
>>
>>52544972
>Subjective. Writing f(x) is valid Haskell if you are so inclined.
Doesn't even have to f(x), (f x) would be fine too
>Many languages. Though similar but not the same, mathematics uses brackets for matrices.
The most similar concept from math to lists would be tuples so use parenthesis
>>
who coq here?
>>
>>52543233
>let
>>
>>52544074
You get a warning because you haven't fucking declared what the return type is.
>>
>>52545074
It understands induction proofs? Neat.

But that's barely programming at this point.
>>
>>52545074
Sorry I don't swing this way. It's perfectly cool with me that you're a homo though.
>>
File: ey.jpg (4 KB, 180x180) Image search: [Google]
ey.jpg
4 KB, 180x180
>>52543959
>mfw 0.499999999999999999 is a character
>>
File: 1453068998593.png (507 KB, 595x639) Image search: [Google]
1453068998593.png
507 KB, 595x639
>>52545115
>induction proofs are barely programming
>>
>>52545095
every language should have a let equivalent. Most do infact, besides Java. Hard luck Prajeet.
>>
>>52543116
>NO OPERATOR OVERLOADING
Doesn't Java have something like
System.out.println("Hello " + "World");
>>
>>52545160
It's called variable definition.
>>
>>52545139
>induction proofs are programming
I'm sorry but just because it uses recursive data structures doesn't make it programming.
>>
>>52545170
'let' is type inferred and immutable Prajeet.
>>
>>52545184
Coq is hardly programming, I agree. But induction proofs are programming.
>>
>>52545064
Haskell has a tuple type.

main = print(length(1.0, 2.0))

length :: Floating a => (a, a) -> a
length (x, y) = sqrt(x^2 + y^2)


Does it still look ugly?
>>
>>52545234
>Does it still look ugly?
extremely
>>
>>52545184
>>52545208
I don't mean that doing an induction proof necessarily means you're programming something. But you can program something by writing an induction proof.
>>
>>52545248
What's wrong with it? If it's the type signature then what about now?

main = print(length(1.0, 2.0))

length (x,y) = sqrt(x^2 + y^2)
>>
head fibs = 0
head (tail fibs) = 1
tail (tail fibs) = zip _+_ fibs (tail fibs)
>>
>>52545272
still ugly with that mixing of the parameters into the assignment.
that's nicer in scheme (even with the short-hand)
>>
>>52545325
>assignment
It's called definition.
>>
>>52544142
>Assuming user will input dollar sign

How did this get published? Actually nvm, what publishers even know the difference between programming and markup languages.
>>
>>52545342
then don't use the classical assignment (or equality) operator
>>
>>52545325
That's how most languages do function definitions.

float length(float x, float y)
{
return sqrt(x*x + y*y);
}


In fact, write it all on one line and change the opening brace to an equals sign, and you have something that looks very similar to the Haskell version.
>>
>>52544176
>http://php.net/manual/en/types.comparisons.php
>(array() == NULL) returns true

Absolutely disgusting.
>>
>>52545377
And it looks retarded when you use "="
give me my (define (length x y) ....) dammit
>>
>>52545356
Classical according to whom? ALGOL used := for assignment.
>>
>>52545356
But it IS equality.
>>
>>52545395
You really prefer:
(define (foo x y) (+ y x))

to
foo x y = y + x

?
>>
>>52545398
and "=" for equality not definition.

>>52545418
yes, very much
>>
>>52545428
Definition IS equality.
>>
>>52545439
No, it really isn't.
>>
>>52545460
How is it not?
>>
>>52545166
No user-defined operator overloading. String concatenation is an exception to this.
Really they should have used ".." or anything else, so as to not confuse people in examples like "2" + "5" returning "25".
>>
>>52545466
Because equality describes (that doesn't have to be true)) a relationship, a definition defines things.
>>
>>52545516
>that doesn't have to be true
???
>>
>>52545395
are you math illiterate or something ? = made sense, especially when procedures are first class values.

foo x y = x + y
bar = foo
>>
>>52545516
Equality is quite a bit more complex than you think.

Propositional equality can be true or false.

Definitional equality is a judgement that something means the same thing as something else. A proof of propositional equality can be derived from definitional equality -- it is always true.

Both are different forms of equality, but unfortunately they tend to use the same symbol in mathematical notation. Not in programming, though -- definitional equality is usually written (x = y) while propositional equality is usually written (x == y).
>>
>>52545516
>>52545657
And before you bring up "but the assignment operator", assignment is basically the same thing as definition in a single static assignment language like Haskell (or mathematics in general).
>>
>>52545516
What about intensional equality?
>>
what's the easiest (or most efficient) way to send events between languages?

Like from javascript to java
>>
>>52545727
Sockets.
>>
>>52545744
yeah that's what I was thinking
ok then
>>
>>52545727
you can hook between JavaScript and most languages. basically you can host a JavaScript runtime within Java and invoke methods in it and subscribe to events from Java
>>
>>52544176
In addition to >>52545386

>Note that php comparison is not transitive:
>"php" == 0 returns true
>0 == null returns true
>null == "php" returns false

Sometimes the memes are real. Don't use PHP.
>>
i tried to copy this code to play with but in java

https://www.youtube.com/watch?v=MqZgoNRERY8

http://txti.es/bitshiftvariationsincminor

i copied this from the comments but i'm guessing it's incorrect because it works fine mostly but in certain parts there's a horrible noise and then it goes back to normal etc.

help pls

# include <stdio.h>
char* notes1 = "BY}6YB6%";
char* notes2 = "Qj}6jQ6%";
int getNote(int volume, int mask, int octave, int instrument){
int selection = 3 & volume >> 16;
char* selected = selection ? notes1:notes2;
int baseNote = selected[octave % 8] + 51;
int note = (baseNote * volume) >> instrument;
int result = 3 & mask & note;
return (result << 4);
}

int main(){
for(int i=0;;i++){
int n = i >> 14;
int s = i >> 17;
int ins1 = getNote(i, 1, n, 12);
int ins2 = getNote(i, s, n^i>>13, 10);
int ins3 = getNote(i, s/3, n + ((i>>11)%3), 10);
int ins4 = getNote(i, s/5, 8 + n -((i>>10)%3), 9);
int combined = ins1 + ins2 + ins3 + ins4;
putchar(combined);
}
}
>>
>>52545657
>Both are different forms of equality, but unfortunately they tend to use the same symbol in mathematical notation.
Since when? You use ":=", or "=" with a little def on top.
>>
>>52545862
here's what i have in java

    static volatile boolean exit;

public static void main(final String[] args) throws LineUnavailableException {
final int bufferSize = 2048;
final AudioFormat audioFormat = new AudioFormat(44100, 8, 1, true, false);
final DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat, bufferSize);
final SourceDataLine soundLine = (SourceDataLine) AudioSystem.getLine(info);
soundLine.open(audioFormat, bufferSize);
soundLine.start();
final byte[] buffer = new byte[bufferSize];
new Thread(new Runnable() {
short foo;
short bar;
final short[] a = { 0, 771, 34, 1235, 4112, 373, 9600, 82 };
final char[] notes1 = "BY}6YB6%".toCharArray();
final char[] notes2 = "Qj}6jQ6%".toCharArray();

int getNote(final int volume, final int mask, final int octave, final int instrument) {
final int selection = 3 & volume >> 16;
final char[] selected = selection != 0 ? notes1 : notes2;
final int baseNote = selected[octave % 8] + 51;
final int note = baseNote * volume >> instrument;
final int result = 3 & mask & note;
return result << 4;
}

@Override
public void run() {
int i = 0;
while(!exit) {
for(int j = 0; j < bufferSize; j += 4) {
++i;
final int n = i >> 14;
final int s = i >> 17;
final int ins1 = getNote(i, 1, n, 12);
final int ins2 = getNote(i, s, n ^ i >> 13, 10);
final int ins3 = getNote(i, s / 3, n + (i >> 11) % 3, 10);
final int ins4 = getNote(i, s / 5, 8 + n - (i >> 10) % 3, 9);
final int combined = ins1 + ins2 + ins3 + ins4;
buffer[j] = (byte) combined;
buffer[j + 1] = (byte) combined;
buffer[j + 2] = (byte) combined;
buffer[j + 3] = (byte) combined;
}
soundLine.write(buffer, 0, bufferSize);
}
}
}).start();
final Scanner s = new Scanner(System.in);
s.nextLine();
s.close();
exit = true;
}
>>
>>52545872
f(x) = 2x + 1
>>
>>52545882
special short-hand for functions, not really a proper definition
Thread replies: 255
Thread images: 31

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.