« first day (791 days earlier)      last day (102 days later) » 

10:39 AM
0
A: Switching on Strings

fredoverflowThis problem inspired me to learn about Scala macros, and I might as well share my solution. Here is how I use the macro: switch(s, 42, "foo", "bar", "baz") The associated values are counted up automatically. If this is not what you want, you can change the implementation to accept ArrowAssoc...

 
user1804599
@fredoverflow awesome!
 
user1804599
@fredoverflow You should file a bug report with scalac anyway.
 
user1804599
scalac should just optimise this case like javac does.
 
3:54 PM
@райтфолд What is more evil, a local variable or a try/finally?
public int popTemp()
{
    boolean result = stack.top();
    stack = stack.pop();
    return result;
}

public int popFinally()
{
    try {
        return stack.top();
    } finally {
        stack = stack.pop();
    }
}
 
user1804599
4:15 PM
@fredoverflow the former is more readable.
 
user1804599
In Eiffel you'd do it even more nicely:
 
user1804599
pop: INTEGER
    do
        Result := stack.top
        stack := stack.pop
    end
 
user1804599
:)
 
@райтфолд Pascal also uses a result variable, if I remember correctly.
 
user1804599
No, you assign to the subroutine name.
 
user1804599
4:21 PM
Suffers from the same problems as ctors being declared with the class name.
 
user1804599
It's confusing and makes refactoring hard.
 
user1804599
(D and Eiffel ftw)
 
Can you nest functions in Eiffel? How would you assign to the outer Result? :)
 
user1804599
No, you can't.
 
user1804599
There are lambdas, though.
 
user1804599
4:24 PM
But I don't think they can assign to the outer result.
 
user1804599
Ctors in Eiffel are named:
 
user1804599
class A
create make make_with_size
feature
    make do … end
    make_with_size(n: INTEGER) do … end
end

x := create {A}.make
x := create {A}.make_with_size(42)
 
5:25 PM
 920: aload_0
 921: invokespecial #192                // Method ignoreMultiLineComment:()V
 924: goto          0
 927: aload_0
 928: invokespecial #195                // Method ignoreSingleLineComment:()V
 931: goto          0
@райтфолд Yay, tail recursion finally works :)
 
user1804599
6:07 PM
@fredoverflow Yay!
 
8:38 PM
 
user1804599
Terrible; who doesn't start their Java package name with their reverse domain name?
 
Well, I got rid of the only .java file in that project, anyway :)
 
user1804599
Should be org.fredoverflow.freducide.language, not language.
 
user1804599
I implemented == today. :)
 
user1804599
If you pass anything but a Boolean, the VM crashes due to uncaught std::bad_cast!
 
8:40 PM
Almost every language gets equality wrong. Escpecially JavaScript.
 
user1804599
@fredoverflow Mill gets it right.
 
== can only compare Booleans? That's retarded.
 
user1804599
@fredoverflow I haven't implemented ad-hoc polymorphism yet.
 
user1804599
vm.setGlobal("std::always::infix==", make<Subroutine>([&] (VM&, std::size_t, Value** argv) {
    auto& a = dynamic_cast<Boolean&>(*argv[0]);
    auto& b = dynamic_cast<Boolean&>(*argv[1]);
    return make<Boolean>(a.value == b.value);
}));
 
Making the language executable must be very satisfying.
 
user1804599
8:42 PM
Equality in Mill is quite straightforward.
 
I haven't reached that stage yet.
Instead, I waste my time with micro-optimizations :)
 
user1804599
is and isnt compare identity, where identity is typically overridden for immutable types.
 
user1804599
== and != compare structure, so even though arrays are mutable, two non-identical arrays can compare structurally equal with ==.
 
user1804599
Hash code and identicality are both automatically derived from the identity, which is a byte string.
 
user1804599
So identity(1) and identity(1) are always equal.
 
user1804599
8:44 PM
But identity(array()) and identity(array()) are always inequal, since arrays are mutable.
 
user1804599
array() == array(), however.
 
user1804599
I am thinking of eq and ne for numeric equality (so integer 1 would equal float 1.0 under eq) although I'm not sure about that yet.
 
user1804599
So, in short:
 
user1804599
struct X { $x: Int } # mutable because of '$' sigil
struct Y { x: Int } # immutable!

check new X { $x: 1 } isnt new X { $x: 1 }
check new Y { x: 1 } is new Y { x: 1 }
 
user1804599
identity(new Y { x: 1 }) would return something like "main::Y(std::always::Z32(1))" and identity(new X { $x: 1 }) something like "main::X(8934809895435)".
 
user1804599
8:56 PM
@fredoverflow I got the overloadable identity from Perl 6. :p
 
user1804599
9:22 PM
If I had a Turing machine I would use the infinite amount of tape to strangle Java programmers with.
 
@райтфолд I would suggest shortening that to "If I had a Turing machine, I would use the infinite tape to strangle Java programmers."
 
user1804599
Tweets are immutable.
 
user1804599
9:50 PM
room topic changed to Java Sucks: Horribleness redefined. [boilerplate] [checked-exceptions] [covariant-arrays] [design-patterns] [erased-generics] [inheritance-hierarchies] [java] [mutability] [singleton] [use-site-variance] [wildcard]
 
@райтфолд That's a nice collection of tags!
@райтфолд Was the github user switch notified by my last commit? :)
 
user1804599
Yes, I think so.
 
user1804599
 
16 commits today? And I thought I was a bad boy...
Meh, italic I looks like a slash.
I /
 
user1804599
/
 
10:04 PM
@fredo latest
 
@JohanLarsson Are you making a stack exchange site?
 
.se is Sweden
 
user1804599
[progmatic.se]
 
user1804599
Not a Stack Exchange site!
 
R# autogenerated comments, must remove them or write something useful.
 
10:10 PM
> CConvenience wrapper for listening to property changes
Stuttering comments?
 
that was me :)
wrapper is not right either
 
user1804599
I described the equivalence operators: github.com/mill-lang/mill/blob/develop/doc/…
 
10:31 PM
looks very tidy
 
user1804599
Thanks.
 

« first day (791 days earlier)      last day (102 days later) »