Originally posted by loinburger
View Post
Announcement
Collapse
No announcement yet.
Write Some ****ing Code
Collapse
X
-
Originally posted by Hauldren Collider View PostThat's...a fairly complicated operation to make atomic. At least, if you have a non-primitive data structure you are comparing and swapping.Code:Class LockFreeQueue { AtomicReference head Node tail Class Node { Object obj AtomicReference next = new AtomicReference(null) } Object dequeue { Node current = head.get Node next = current.next if(head.compareAndSwap(current, next)) { return current.obj } else { return dequeue } } void enqueue(Object obj) { Node node = new Node(obj) if(tail.next.compareAndSwap(null, node)) { tail = node } else { enqueue(obj) } } }
Originally posted by Hauldren Collider View PostIs that underscore the wildcard value like in ML?Last edited by loinburger; November 4, 2014, 20:46.<p style="font-size:1024px">HTML is disabled in signatures </p>
Comment
-
OK, I still can't understand what that Scala code is doing. Is there some sort of implicit function there in the parentheses, without a rocket operator? That's wacky as ****.
EDIT: It looks like what's happening is that it runs the print statement then it takes the second statement as the lambda argument, but that's just weird as **** to me because in my mind, that expression should not be a function. Actually I think it should typeerror, if Scala were being reasonable.If there is no sound in space, how come you can hear the lasers?
){ :|:& };:
Comment
-
Seq(1, 2, 3).map(i => println("Hi"); i + 1) is saying "apply the function [println("Hi"); i + 1] to each element of Seq(1, 2, 3), where 'i' represents the current sequence element"
So it prints "Hi" three times, once per element in the sequence; then it returns Seq(1 + 1, 2 + 1, 3 + 1) -> Seq(2, 3, 4)
Why doesn't Seq(1, 2, 3).map(println("Hi"); _ + 1) do the same thing? I don't know and I don't care, you're not supposed to have side-effects in map functions anyway<p style="font-size:1024px">HTML is disabled in signatures </p>
Comment
-
I'm guessing the reason is because it is actually evaluating the expression in the parentheses in the second one. The evaluation of the argument in the first one evaluations (i => println("Hi"); i + 1) as a function, whereas the second one evaluates (println("Hi"); _ + 1) as print, ignore return value of print, then create function i=> i+1. Obviously this is all ridiculous but the fact that _ + 1 returns a function value is weird as **** to me and is my main hangup.If there is no sound in space, how come you can hear the lasers?
){ :|:& };:
Comment
-
Yeah, I googled "scala map underscore", and what's happening is that map(i => println("Hi"); i + 1) passes the [println("Hi"); i + 1] function to the map function, while map(println("Hi"); _ + 1) executes [println("Hi")] and then passes [_ + 1] to the map function. Which makes sense and at the same time is stupid as hell.
It might be possible to do something like map(println("Hi"); i => i + 1), but I'm much too lazy to open up an interpreter to find out of this works<p style="font-size:1024px">HTML is disabled in signatures </p>
Comment
-
Okay I lied, I found an online interpreter, and Seq(1, 2, 3).map({println("Hi"); i => i + 1}) has the same output as Seq(1, 2, 3).map({println("Hi"); _ + 1}) (this interpreter requires the braces, mine doesn't, go figure). So now if another douchebag asks me about this I can immediately hang up on him before he can waste any more of my time.<p style="font-size:1024px">HTML is disabled in signatures </p>
Comment
-
It is my opinion that if you actually abuse the syntax that way for any reason you're a bad person. Why the **** does _ + 1 evaluate to a lambda? Jesus christ. Yes I get that it's pattern matching. Still ridiculous.If there is no sound in space, how come you can hear the lasers?
){ :|:& };:
Comment
-
Yeah, a code block executes the statements and returns the result of the last statement, e.g.Code:val x: Int = { val temp = 20 20 * 2 } println(x)
Code:val x: Int = { val temp = 20; 20 * 2 } println(x)
Last edited by loinburger; November 5, 2014, 12:31.<p style="font-size:1024px">HTML is disabled in signatures </p>
Comment
-
Do you guys think of me when you write semicolon?DISCLAIMER: the author of the above written texts does not warrant or assume any legal liability or responsibility for any offence and insult; disrespect, arrogance and related forms of demeaning behaviour; discrimination based on race, gender, age, income class, body mass, living area, political voting-record, football fan-ship and musical preference; insensitivity towards material, emotional or spiritual distress; and attempted emotional or financial black-mailing, skirt-chasing or death-threats perceived by the reader of the said written texts.
Comment
-
DISCLAIMER: the author of the above written texts does not warrant or assume any legal liability or responsibility for any offence and insult; disrespect, arrogance and related forms of demeaning behaviour; discrimination based on race, gender, age, income class, body mass, living area, political voting-record, football fan-ship and musical preference; insensitivity towards material, emotional or spiritual distress; and attempted emotional or financial black-mailing, skirt-chasing or death-threats perceived by the reader of the said written texts.
Comment
Comment