Thoughts about z-talk

Decided to write down some ideas about z-talk.

The language

Z-talk is, of course, a lisp. It's lisp-1. It will support traditional CL-style macros as well as first-class continuations. It will be much like PG's Arc and Clojure but differ in that it will not compile for JVM and will not use Racket (mzscheme) which will make it very lightweight much like Scheme48. But it will differ from Scheme48 in that it will support CL-style macros and will not require any top-level declarations that are inspected in compile time. It will support automatic compilation and storing byte-code cache much like in Python.


I've been back and forth on the question of what to implement z-talk in and now I think C++ (mostly plain C) will do just fine. Another option that is very attractive is to use PreScheme compiler... You know what? I just changed my mind back again. PreScheme is very small, easy to use and seems much more powerful than C++ or C. OK, back to PreScheme! Stick to it!

Anyway z-talk will compile to byte-code. Compilation unit is one expression (not one file). Conses, vectors and strings are mutable. But I'm thinking about making variable bindings to be fixed forever. This might greatly simplify the implementation of environment structures and allow inlining procedures. Users will be advised to use mutable boxes (or cells, whatever the name) to modify lexically bound values. But I'm still not sure about that.

Data representation

Values in z-talk are ether immediate or non-immediate. Immediate values are represented by single machine word exactly as in Chicken scheme. But there are fewer types of them in z-talk: fixnums, characters and nil. Nil is of its own type and is not a symbol. There is however symbol nil bound to nil value. Lists are terminated by nil. No boolean type. Nil is false, any other value is true.

Non-immediate values are pointers to the objects stored in blocks. There is a separate list of blocks for each object type. Blocks are aligned so that it is easy to find the beginning of a block by dropping the last few bits in a pointer to an object. This is to avoid storing the type tags in every object. Type tag is stored in the header of each block instead.

Small objects of fixed size are stored just like that. Memory is allocated from a singly-linked lists of free cells.

Objects of variable size are stored differently. Vectors are referenced by descriptors very much like in STL vectors in C++. Descriptors are stored the same way as any other small fixed-sized objects. Strings are much like vectors. Symbols are unique in that all equal symbols are just pointers to the same location. Still haven't decided what is the best layout scheme for symbols but here is one important constraint: it must be easy to look them up by the representation. So they must be arranged in some kind of hash.

WJF 9 Day 2

Day 2 has passed. It turned out that I missed a lot on day 1 because I got to bed early. There were juggling games, cambat and round 1 of juggling jukebox. Fortunately, yesterday all this continued. I even attended combat master class.

Well, here is what happened yesterday. I missed Beginning 3 Balls workshop by Frank Chilese and came to Jason Garfield's 5-7 balls master class. Here is Jason explaining something.

I was at 3 ball cascade masterclass a day before that. It was interesting but that one was acutally usefull.

I was standing in the group who learned 5 balls, on my left are those learning 6 balls and in front are those learning 7 balls.

I was pretty much the worst juggler at the event. Well, except maybe some parents. But they were not really into juggling at all. Although most of them attended beginner's master classes anyway.

After that there were juniors' and advanced competitions. Here is the scene:

A couple of photos from the juggling games. Vladik doing 5 balls 5 up 360 inside the chicken box:

Jonah trying to do the same with rings. (Turned out then that nobody could manage to do it in this box.)

And that's a short video from the combat training by Joe Showers.

WJF 9 Day 1

I started to write this when it was 5am in Vegas. Still can't get used to the local time.

Anyway, yesterday was day 1 of WJF 9. Apparently not all the jugglers arrived yesterday because I still haven't seen Vova Galchenko, Olga Kay, Doug Sayers and many others. Don't know may be they all registered when I took a break to grab a bite.

And also I fell asleep at 7pm yesterday. I set the alarm clock not to miss the evenings juggling games, but when it ringed I just automatically turned it off and slept until 4 am. Really hope that it won't happen today.

Anyway I met Mark from Scotland who's at the WJF event first time and Stieve from Las Vegas who missed only one WJF event. You probably already know Stieve from his How to juggle 5 ball cascade video.

Almost everyone who were at the gym practiced for all the time they were there. It was at least 7 hours with small breaks. No wander they all are so good!

I didn't take many pictures yesterday but I recorded a short video of an impromptu combat battle.

And that's a picture from Jason's 3 balls cascade master class.

WJF 9 Day 0

Today is day 1 of WJF 9 — 9th World Juggling Federation convention.

But I'll tell you about yesterday's unofficial beginning, lets call it day 0.

Those who arrived yesterday or earlier (me) had a chance to register, get to know each other and have an evening juggling session.

Here is a couple of photos I took yesyerday.

And a couple of videos. Here is Jason trying to do a 5 balls 3 up 360 — 5 up 360 connection.

And Vladik juggling 9 balls.

Today is the official beginning. There is going to be much more people. I hope I'll take more pictures.

Binary pkgsrc packages for Mac OS X Maverics (Darwin 13.0.0)

Pkgsrc is a great packaging framework, originally developed for NetBSD.

It's too much hassle to build binary packages from sources everywhere you install pkgsrc. There is pkgin that solves the problem. But unfortunately pkgsrc team doesn't build binaries for Mac, so there is no official repository. Some people, like  Jonathan Perkin, build the packages and publish them.

The Jonathan's binaries are built for old Mac OS (which is good) but they are built for i386. Sometimes you need a library that you want to use for development, in that case you need a 64-bit ABI support.

Recently I built a few packages for current pkgsrc with 64-bit ABI and decided to publish them too. Here it is.

To install pkgin utility (that is very much like apt-get on debian based linux distros) all you need to do is run:

curl | gzip -dc | sudo tar -C /usr -xf -

What this does is it fetches pkg.tar.gz tarball and unpacks it's content to /usr. That is one directory pkg-current and a symlink pkg that points to pkg-current.

After you extracted the tarball, you need to add /usr/pkg/sbin and /usr/pkg/bin to your path. That can be done by putting this paths to /etc/paths.d/90-pkgsrc-current or by adding PATH=$PATH:/usr/pkg/sbin:/usr/pkg/bin to .profile in your home directory.

I build everything on Maverics (OS X 10.9), so you need to upgrade if you're still using an older version (Maverics is free by the way).

Try it and tell me if anything is wrong. For now there is not much in the repo. There will be more as they're built.

Almost forgot! Here are some pkgin basics:

pkgin update # (re)fetch packages index

pkgin search zsh # look for something zsh-alike in repository

pkgin install mercurial # install mercurial control version system

How to remove everthing that pkgin installed? I configured pkgsrc so that it installs everything under /usr/pkg-current even packages' meta info and pkgin db. So 

sudo rm -rf /usr/pkg-current /usr/pkg

is enough to kill the whole thing.

Second of two First Aid classes

On Saturday we've been to the second of two First Aid classes conducted by Ilya Zabelin and Alexander Mostov.

This time it was even more interesting and fun.

 The photos are from the practice. Half of us played injured, others played, well, themselves. After each session Ilyia and Sasha explained what was wrong and what was right.

Here we're at a “night club” where some drunks injured others (also drunk). The one with the light is Sasha Mostov playing a junkie.

Everything was great. And again, very practical and usefull.

First Aid course

Last saturday I’ve been to the first of two First Aid classes that is conducted by professional First Air instructors Ilya and Alexander. Actually Ilya now works at Yandex but still does First Aid as a hobby. Alexander is an instructor at EFR, Red Cross and Moscow Rescue Service. 

Here are a few photos from the class.

Alexander & Ilya.

Tanya learns to do chest compressions.

Everyone tried to move an injured but then gave up :-).

That was a full day class. 8 hours with one 45 minutes break and 5 minutes break every 2 hours. Very interesting.Very practical.
Looking forward to the next class next Saturday.

Rvalue reference in C++11

Everything I'm gonna say is probably well known or at least it should be. However, when I encountered this, I was very surprised. Enough to be willing to write a post about it.

Look at that piece of code:

template<class T> void append(vector<T> &v, const T &x) { v.push_back(x); }

template <class T> void append(vector<T> &v, T &&x) { v.push_back(move(x)); }

vector<string> v;

string s = "a magic string";

append(v, s);

What do you think s will be after append(v, s)? Well, there is no surprise here yet, it's "a magic string".

But if we change the code so that append would add x to a global vector:
vector<string> v;
template<class T> void append(const T &x) { v.push_back(x); }
template <class T> void append(T &&x) { v.push_back(move(x)); }
Then a magical thing will happen. In this case type T in the expression append(s) will be deduced as the rvalue reference to string, not const reference to string. So s will be no longer valid after the call to append(s).

If you want to be sure, that s is moved only when you write move(s), or when you call append with a temporary, you must write another version of append, that doesn't do anything except calls append(const T &): 

template<class T> void append(T &s) { append<const T &>(s); }

The more I learn about C++11, the more I love it!