Common Lisp-style macros in Racket

Today I put myself together and read a couple of sections of Racket documentation. Now I finally know how to implement Common Lisp-style macros in Racket. I'm still not 100% sure it will work exactly as expected but common cases work right.

Here it is:

(define-syntax define-macro
  (syntax-rules ()
   ((_ name fn)
    (define-syntax (name stx)
      (datum->syntax stx (apply fn (cdr (syntax->datum stx))))))))

(define-macro mac
  (lambda (sig . body)
    (cond ((symbol? sig) `(define-macro ,sig ,@body))
          ((pair? sig)   `(define-macro ,(car sig) (lambda ,(cdr sig) ,@body)))
          (else           (error "wrong use of mac")))))

This will give you macro-defining macro mac as in Paul Graham's Arc, except that I defined it in a Scheme way. You will easily figure out how to use it from this example:

(mac (with var exp . body)
    `((lambda (,var) ,@body) ,exp))

(with a 2 (+ a  4)) ; => 6

Binary pkgsrc packages for FreeBSD-10.0

I started to build packages from pkgsrc on my FreeBSD machine.

If you want to try, run:

fetch -q -o - http://umc8.ru/~a/packages/FreeBSD-10.0/current/pkg.tar.bz2 | bzip2 -dc | sudo tar -C /usr -xf -

This fetches and extracts the minimal distribution of pkgin.

After that you'll have to add /usr/pkg/sbin and /usr/pkg/bin to your path to be able to run pkgin.

If you don't know how to use pkgin, you will probably want to have a look at the docs.

If you're happy with pkgin, I'm glad that I could help.

If not, please tell me why. Then run sudo rm -r /usr/pkg /usr/pkg-current and continue living with FreeBSD's pkgng.

Ripple daemon in pkgsrc wip

Just added rippled (Ripple peer-to-peer network daemon) to pkgsrc wipRipple is a peer-to-peer payment system created by Ripple Labs Inc.

Here is how you can install it on Mac OS X. First, you need to bootstrap pkgin, see my previous post.

And then run: pkgin update && pkgin install rippled

If you're not using Mac OS X, you can still build it yourself using pkgsrc.

If you're not using pkgsrc, you're missing out ;-).

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

As I already wrote, I build pkgsrc packages for Mac OS X. Some time ago I update to Darwin 13.1.0.

To use the new repository, you need to change the path in /usr/pkg/etc/pkgin/repositories.conf to http://umc8.ru/~a/packages/Darwin-13.1.0/current/All

If you want to install everything from scratch run the following:

curl http://umc8.ru/~a/packages/Darwin-13.1.0/current/pkg.tar.bz2 | bzip2 -dc | sudo tar -C /usr -xf -

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

To those who want to know more about pkgin, look at the pkgin official web page.

If you have any questions, ask here or send me an email.

P. S. If you want to try pkgin but afraid that it will be difficult to remove it, please notice that I configured it so that everything can be removed with just this one command: rm -rf /usr/pkg /usr/pkg-current

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.

Implementation

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 http://umc8.ru/~a/packages/Darwin-13.0.0/current/pkg.tar.gz | 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.