Tag Archives: shadowing

In a shadow of the globals

While working on void and later true and false I realized I would like to make those names reserved, despite the fact they are not keywords. It seemed odd — I made an arbitrary decision because void was so ubiquitous. Or because it was placed in global namespace? It was so lame, definition of void looked like any other object, and yet out of the blue it was selected by me that it should be reserved name. What if another object happens to be that important, should I also hard code its name into compiler to make it reserved as well?

Or was it global namespace indeed? And that was all it mattered?

There are plenty of languages which allow you to put a function, a variable into a global namespace with typical advice that you should keep global entities to minimum. Skila was one of those languages.

But not any longer, add as many variables to global namespace as you like.

Yes, sure, go ahead.

Just keep in mind shadowing of namespaces in Skila is disabled. It is a trick which solves my dilemmas about making arbitrary decision with names, and it also enforces the discipline of polluting the namespaces, no more talking, just rules. Take a look how it works:

namespace DirtyPlayground
  let x Int = 5; 
  def func(x Int) // error

The first x effectively makes a reservation for its name for entire namespace (and its descendants), thus you cannot shadow it by declaring any local variable.

Tagged ,

Weekend with virtuals and abstracts

What is love without tenderness? No matter how interesting or frustrating the courses are out there, I cannot work too long without polishing Skila. Since it was a bit like come-back weekend I focused on rather boring issues:

  • added syntax for un-shadowing (un-hiding) the methods from the inherited class (as I announced previously),
  • the “new” modifier works the same way as in C#. However Skila raises an error, not a warning, if it is missing,
  • there is “abstract” class (cannot be instantiated) and “virtual” one (all methods become virtual).

Plus some implementation details to check whether abstract method has a body, or non-abstract does not have any body, and so on. That‘s why I wrote “boring” — nothing spectacular here, but this work had to be done.

Next weekend looks way more interesting though — spécialité du chef on the horizon! First of all I plan to introduce exposing methods from a field of the class — thanks to it writing wrappers in container class will no longer be necessary, they will be generated automatically. Even bigger feature I have in mind — pinned constructors and “SELF” which would behave like implicit generics. Read more about the latter in the previous post I wrote.

For some time now this blog is under constant spam attack advertising losing weight. I have some respect for nowadays spammers, they got clever — every time the message looks absolutely legitimately, and the only trace of the spam is the spammer signature or nickname. The ironic fact is that for several years I wasn’t able to lose weight, but this year is different — thanks to strict (but tasty) diet which I came up with by myself and added body training from “Convict Conditioning” by Paul Wade I lost unwanted kilograms in 2 months and now I am good. So thank you spammers, I’ll pass.

Tagged , , , , ,

All little Saturday things

I confess — I am a traitor. Over a week ago I enrolled in Coursera course “Discrete Optimization” by Prof. Pascal Van Hentenryck and it is frustratingly interesting if I may say that. Since I love computational challenges I was hooked in since the first assignment. I tried to keep the weekend only for Skila, but I failed — writing one thing, and thinking about other makes no sense, so I switched and worked on DO almost entire Sunday. But don’t despair, I am a thorough guy, I wrote down how many hours I borrowed from Skila.

It doesn’t mean I did nothing — however only a little additions and improvements:

  • I optimized backend in case of non-virtual types (simply no virtual table),
  • in backend layer interfaces are classes with empty methods — this allows to safely call a method when derived class hides it,
  • I added standalone functions — this required surprisingly some work,
  • I already mentioned covariance when it comes to polymorphic methods,
  • Skila supports 4 types of expressing the base for numbers like in Python — “124” for decimal, “0xCAFE” for hexadecimal, “0o57” for octal and “0b010101” for binary,
  • numbers can be expressed with padding as in Ruby — “450_010” is exactly the same as “450010” only reading is easier,

Next point is exposing back shadowed methods — I have in mind three cases:

using base::foo(Int);
using base::foo(*);
using base::foo;

The first one brings up method foo with given signature, joker “*” in the second line brings all foo methods. And third one is a shortcut — if there is only one method foo in inherited class it will be brought up. If there are more — compiler will give you an error.

And that’s all for the Saturday, I am running back to DO assignments…

Tagged , , , , , , , , , , , ,