Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yup, it's basically a LISP. And it has a kind of polymorphism (using UpValues) that makes it possible to do something akin to OOP. Here's the beginnings of a set implementation in Mathematica:

  SortedSet[x_List] := SortedSet @@ Union[x];
  SortedSet /: Plus[a_SortedSet, b_SortedSet] := Union[a, b];
  SortedSet /: Plus[a_SortedSet, Minus[b_SortedSet]] := Intersection[a, b];
  Format[set_SortedSet] := AngleBracket @@ set;
Now you can use + and - on these sorted sets, and they'll format in the frontend as SortedSet[Range[3]] -> <1, 2, 3>. And part indexing, MemberQ, FreeQ, and pattern matching will Just Work.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: