« first day (724 days earlier)      last day (169 days later) » 

user1804599
12:00 AM
Yeah.
 
user1804599
I like x compareTo b better than x.compareTo(b).
 
user1804599
I can't really comment on the code. I know nothing about such trees.
 
It is surprisingly difficult to find good information on 2-3 trees.
Even though they're already 45 years old.
I am trying to shuffle a collection in Scala.
def shuffle[T, CC[X] <: TraversableOnce[X]](xs: CC[T])(implicit bf: CanBuildFrom[CC[T], T, CC[T]]): CC[T]
dat signature
 
user1804599
Nothing special, really.
 
user1804599
CanBuildFrom is just a type class.
 
user1804599
12:06 AM
It's pretty nice.
 
@рытфолд Hm, string interpolation is really neat!
 
user1804599
Yeah.
 
I wonder why I never missed that feature before :)
 
user1804599
It's completely configurable.
 
user1804599
You can have xml"…" that interpolates XMLElems, for example.
 
12:07 AM
What else does one expect from Scala? :)
 
user1804599
Or sql"…" that returns a prepared statement with bound values, so you have no SQL injection but you do have nice string interpolation syntax.
 
I'm even using it for this now:
override def toString = s"($a)"
 
user1804599
Nice.
 
How can I make sure that a method inside an object is only called from within the same package?
 
user1804599
private[mypackagename] def foo() = …;
 
user1804599
12:10 AM
You can put anything within the brackets as long as foo is defined in it.
 
Ah, I thought it was literally private[package] :)
case object Tree {
  def apply(): Tree = Empty
  def apply(a: String): Tree = Leaf1(a)
  private[garden] def apply(a: String, b: String): Tree = Leaf2(a, b)
  private[garden] def apply(a: String, b: String, c: String): Tree = Internal1(Leaf1(a), b, Leaf1(c))
}
 
user1804599
No, but you can do private[`package`] if your package is named package!
 
I want to make those multi-arity factory methods package-private so clients cannot accidentally create wrongly ordered trees.
Wait, what happens if I add a public def apply(a: String*) and call apply("hello", "world")?
Will it call the 2-arg overload from within the package and the variadic method from outside the package?
 
user1804599
@FredOverflow ambiguous
 
user1804599
That's even ambiguous when using a variadic method that is defined in Java, which is annoying when using Java APIs designed that way.
 
12:15 AM
@рытфолд Really? That's a common pattern in Java code.
@рытфолд Hm, works just fine here.
 
user1804599
Oh, maybe they fixed it.
 
def apply(as: String*) = as.foldLeft[Tree](Empty)((b, a) => b.insert(a))
 
user1804599
def apply(as: String*) = as.foldLeft[Tree](Empty)(_.insert)
def apply(as: String*) = as.foldLeft[Tree](Empty)(_.insert(_))
 
user1804599
Why is [Tree] needed?
 
Without it, I get the following error:
type mismatch; found: garden.tree required: garden.Empty.type
Doesn't make much sense to me.
 
user1804599
12:22 AM
Oh, right. :P
 
user1804599
@FredOverflow It expects an Empty.type, but you give it a tree.
 
user1804599
But tree is not a subtype of Empty.type.
 
def apply(as: String*) = as.foldLeft(Empty: Tree)((b, a) => b.insert(a))
 
user1804599
Yeah that should work as well.
 
user1804599
The problem is similar to this one:
 
user1804599
12:23 AM
21
A: Why is the std::accumulate function showing the wrong sum of a vector<double>

рытфолдstd::accumulate is declared as such: template <typename InputIt, typename T> T accumulate(InputIt first, InputIt last, T init); The second template argument to std::accumulate is deduced as int because 0 is of type int. Pass a double instead, like 0.0.

 
@рытфолд The first version does not work, but the second one does.
 
user1804599
Nice.
 
user1804599
And this? def apply(as: String*) = as.foldLeft(Empty: Tree)(_.insert _)
 
missing parameter type for expanded function
 
user1804599
Meh.
 
user1804599
12:25 AM
_ is weird.
 
yes
println(Tree("Scala", "rocks", "and", "Java", "sucks", "C", "is", "bad", "and", "so", "is", "C++"))
(((C C++) Java (Scala)) and ((bad is) rocks (so sucks)))
nice
 
user1804599
nice
 
user1804599
Now make Tree[T] a subtype of Seq[T]!
 
I'm not gonna go there again...
9
Q: Lost in the inheritance graph of Scala's collections

FredOverflowToday I wanted to learn about the supertypes of List: sealed abstract class List[+A] extends AbstractSeq[A] with LinearSeq[A] with Product with GenericTraversableTemplate[A, List] ...

 
user1804599
:P
 
user1804599
12:28 AM
In Perl 6 you can find the order in which classes are searched for methods:
 
user1804599
> Str.^mro
(Str) (Cool) (Any) (Mu)
 
user1804599
If you call a method on Str it will look in those classes in that order.
 
user1804599
I wonder what happens if you override mro.
 
probably not a good idea
How do you know about that upcoming Perl 6 stuff?
 
user1804599
12:30 AM
I'm in #perl6 on freenode.
 
So you are cheating on Java Sucks? ;)
 
user1804599
> sub filter-profanity(Str $s) { $s.subst(/Java/, '****', :g) }
sub filter-profanity (Str $s) { #`(Sub|140453629731736) ... }
> <Scala rocks and Java sucks C is bad and so is C++> ==> map &filter-profanity ==> map &uc ==> join(' ')
SCALA ROCKS AND **** SUCKS C IS BAD AND SO IS C++
 
12:53 PM
in Java, 2 mins ago, by FredOverflow
class Wrapper
{
    private Object obj;

    public void set(Object obj)
    {
        this.obj = obj;
    }

    // Is toString a recursive method?
    public String toString()
    {
        return obj.toString();
    }
}
 
user1804599
@FredOverflow Only if the wrappee is of type Wrapper.
 
So it cannot be decided at compile-time?
 
user1804599
No.
 
user1804599
In fact.
 
user1804599
class X {
    @Override
    public String toString() { Wrapper w = new Wrapper(); w.set(this); return w.toString(); }
}
 
12:56 PM
ah, mutual recursion :)
 
user1804599
Can't wait till ECMAScript finally allows TCO.
 
user1804599
Then you can finally emulate stackful coroutines.
 
2:14 PM
@рытфолд I replaced the asInstanceOf code with polymorphism.
lines of code before refactoring: 115
lines of code after refactoring: 115
 
user1804599
Cool.
 
user1804599
Perl 6 has an interesting feature.
 
user1804599
my $foo = 1;
{
    let $foo = 2;
}
say $foo; // 2

my $bar = 1;
try {
    let $bar = 2;
    die;
    CATCH { }
}
say $bar; // 1
 
user1804599
let resets the value iff the scope in which it is used throws an exception.
 
@рытфолд No wait, it's actually down to 103, because I don't need the elements method anymore :)
 
user1804599
2:39 PM
@FredOverflow Perl 6 has an interesting approach with respect to equality and hash code.
 
user1804599
There's no equals and hashCode. Instead there's a single method which returns a unique ID that you can override, and that is checked for equality or hashed instead.
 
@рытфолд What does private class mean in Scala, private to the translation unit?
 
user1804599
Depends on where you use it.
 
top level
 
user1804599
Package-private.
 
2:50 PM
So private and private[garden] is the same for top level classes?
 
user1804599
I think so, yes.
 
user1804599
> Cat
===SORRY!=== Error while compiling <unknown file>
Undeclared name:
    Cat used at line 1. Did you mean 'Rat'?
 
user1804599
So many animals.
 
37
A: private[this] vs private

denis phillipsThere is a case where private[this] is required to make code compile. This has to do with an interaction of variance notation and mutable variables. Consider the following (useless) class: class Holder[+T] (initialValue: Option[T]) { // without [this] it will not compile private[this] va...

omg Scala y u so complicated?
19
A: Default public access in scala

DebilskiIn Java it’s far easier to choose ‘package-private’ as the default because it is one out of only three possibilities there. In Scala you can choose between public access (public), package-private access with inheritance (protected[C]), package-private access without inheritance (private[C]), cla...

wow
I think Ceylon only has two access modifiers.
 
user1804599
public is a good default.
 
user1804599
2:55 PM
It's what you want most of the time.
 
user1804599
@FredOverflow LasagnaScript has none.
 
user1804599
Everything is public. :D
 
The default in Ceylon is private, and if you want public, you write shared. That's all.
 
user1804599
In LasagnaScript private is underscore prefix by-convention.
 
user1804599
Since there's no way to do private in JavaScript.
 
2:56 PM
> The "best" default is the most restrictive option. Otherwise, the developer of a module might accidently make something something shared that they don't intend to make shared, and be forced to either continue to support the unintentionally-shared operation for the rest of the life of the module, or break clients.
> There would be nothing the compiler could do to warn you when you accidently left off a private annotation. On the other hand, if you accidentally leave off a shared annotation, the compiler will let you know about that.
 
user1804599
I disagree.
 
user1804599
The developer should know what they are doing.
 
I agree with the quote and disagree with you.
 
user1804599
I don't.
 
How often do you not use final in Java when you should?
 
user1804599
3:01 PM
Never.
 
user1804599
Mostly because I never use Java.
 
So is that 0% of the cases or 100% of the cases? :)
 
user1804599
0%!
 
4:26 PM
java.util.TreeSet is about twice as fast as my 2-3 tree.
I guess that's why nobody uses 2-3 trees in practice :)
On the other hand, my 2-3 tree is persistent.
Which makes it suitable for analyzing nested scopes and stuff, as you demonstrated.
 

« first day (724 days earlier)      last day (169 days later) »