Saturday, 15 November 2008

Programming language idea

Well, it's an idea about programming language without a programming language.

Think about writing a script that generates assembly. It's doable. Sometimes it's even *almost* sane thing to do, eg. when working on spellchecker I've had a crazy idea about generating code that does dictionary lookup for a hardcoded word set (It's no rocket science, just compare, jump, compare, jump...). But it's so low level and not cross-platform.

I've done some C generation from Python several times (eg. to make last year's april fool's joke - it's on this blog). The problem is that C is often not flexible enough (GCC would choke on 100MB file for dictionary; TCO, call/cc and other fancy stuff is hard...). Not C, not assembly...

There is LLVM - a perfect target.

Moving on: a scripting language that would generate all this mess.

It should be very, very meta one. Like lisp, but with syntax. A pluggable one.

My idea is to write a language that would have pluggable lexer (one lexer would switch to another one when it would encounter some sequence of characters - think of reader macros on steroids), then a huge layer of macros (tons of macros. Like Nemerle). Add a lispy semantics on top of it (few orthogonal concepts that combine together nicely) and my evil plan is 10% complete.

You would be able to create literal syntax for your new, shiny DSL inside your script, then semantics that would generate optimal machine code for it and boom!

It would enable some crazy stuff. Think of all super-duper assertions library creator would be able to enforce compile time with it! You like that D enables you have optional purity control? You can add it to your script.

It wouldn't be general purpose tool (it would probably be to wired and demanding to do everyday work), but I can see applications where you have to be extremely fast (OS kernels, games) or you are very domain-specific stuff (think of all those code-generating tools like lex, bison, antlr).

More or less related things to do/blog about in future:
- DBus + gvim - a possible step towards an headless IDE
- Actor-based OS

random stuff

Beep, beep! I'm still (more or less) alive.

University takes me lots of time, which is my primary excuse for not blogging
for so long time. Projects are like gas - they fill up all available space^H^H^H^H^H time.

Interesting (for geeky enough definition of "interesting") stuff I've done recently:

  • Spellchecker. It's a quite smart one -- written in python and C, it uses trie (ternary search tree) for storing dictionary. It's super-fast to load data (there are no pointers, so loading it is just one read of binary file, and you can use it).

    Then you can use TST to quickly (it's quicker than hashmap) check if a word belongs to vocabulary or retrieve (it's still bleeding fast) a list of words that are no further (in Levenstein's (edit) distance) than misspelled one.

    Then it uses longest common subsequence algorithm to get parts that don't match and compares those parts using knowledge about typical spelling errors in Polish. It can correct "grzegrzułka", "zomp" and "fzhut". In summary: it's cool.

  • I'm preparing a talk about scala. It's work in progress. You can see some slides here. I'll give this talk on 3th December as a part of BIWAK

  • Oh, yes, BIWAK. We (BIT science club) have started a series of talks called BIWAK.

  • Oh, yes, science club. I've done some work on platform game with cool physics, but there is nothing cool to show off yet.

  • I've published some of my .rc files

  • Hooray new swimming pool! Hooray hiking! Hooray birthdays and weddings. Hooray real life.

Monday, 22 September 2008

Back to Poland

<terminator-voice>I'm back!</terminator-voice>
10 weeks of my internship at Resolver Systems passed like ten days. It was amazing experience - I learned a lot and I had great time. Many thanks to all my co-workers, you are great!

I had a great opportunity to attend first day of PyCon UK - it was really cool. I got some ideas I'd like to transplant to SFI festival.

TODO:
- expand this post
- LLVM
- programming language ideas
- vim + python
- more

Saturday, 21 June 2008

LaTeX thoughts and lack of time

I haven't written here for quite a long time — it's because of current semester's ending. I had a lot of work to do with my projects (btw: it's one of them; another video). For every project one has to write a documentation. And I know only one way to write documents that doesn't suck hard. It's the way of TeX. I have written quite a lot of LaTeX documents last month. Here is what I learned:
  • \newcommand and \newenvironment are your friends
  • Making your comands and env names uppercase lets you avoid clashes with predefined ones.
  • Try to be semantic from very beginning if it's easy. For example: you mention electronical parts or Java classes all over your document. Add \newcommand{\Class}[1]{#1} in the beginning of your document and wrap all class names with \Class{}. It would be easy do make all class names typed with some special font later on.
  • If your documents take a lot of time to compile
    • break it intro few files and \input them. Comment out inputs you don't work on currently.
    • use draft option
  • Thinking about writing documents in TeX as of programming helps a lot!
    • Being a nazi with DRY principle makes your document sources look very semantic and the output is prettier. You do more tweaking if you can do it in one place instead of 20 places.
    • Do the simple thing that gives you desired result. If you repeat yourself ⇒ abstract out repetition intro new command(s) and/or environment(s).
    • Refactor!


There are some things I wanted to write about, but I haven't got time. Here is my public TODO list:
  • Why Eiffel standard library is so cheesy that it makes me want to write program in brainf*ck instead of Eiffel (which is quite a nice language), and what can we learn from that (in "I promise, I'll never code something similar" way of learning)
  • Why hovercrafts rock and how it is like to discharge 8 Duracell bateries in 20 minutes of playing with your homemade, bluetooth controlled one. (It's much more Witek's one than mine, but still)...
  • Hooray, yet another post about monads!
  • Hooray, yet another post about Scala!
  • Erlang, OOP and functional programming
  • I switched to zsh

Maybe one day one of those will turn intro full-blown post. Maybe.

Friday, 2 May 2008

organize your python imports in vim

My first script at vim.sf.net. You can grab it here. Source code of it and unittests (nose is great!) are on my mercurial repo.

Have fun!

Sunday, 20 April 2008

bash fun vol. 2

Forget previous post. Bash has functions: goj@abulafia ~ $ tail ~/.bashrc
function apply() {
cmd=$1
shift
for x in $*; do $cmd $x; done
}

function go() {
$@
cd ${!#}
}

Much better now. :)

Monday, 14 April 2008

bash fun

Quote by Terrence Parr:
My Motto: "Why program by hand in five days what you can spend five years of your life automating?"


We do a lot of actions that make a directory interesting for us and then we want to cd intro that directory. Consider:

hg init my_repo; cd my_repo
mkdir -p a/b/c/d; cd a/b/c/d
mv my_file /tmp; cd /tmp


Boring, repetitive and not DRY.

Lesson 1: You can do something like this:
mkdir -p a/b/c/d; cd !$

Better, but not good enough for me. I'd like to type
go hg init my_repo
go mkdir -p a/b/c/d
go mv my_file /tmp


So we need to create a short bash script, don't we?

How do we get last argument of the script (we'll need that). Provided that $1 is the first argument, $2 - second and $# - argument count and $@ all arguments as an array... yes, you guessed it. It's ${!#}

How nice and intuitive. Try those: $$# ${$#} ${${#}} $@[$#].

So do we have all that we need?
goj@abulafia tmp $ cat go
#!/bin/bash
$@
cd ${!#}


goj@abulafia tmp $ ./go echo ~
/home/goj
goj@abulafia tmp $


Epic FAIL. ./go script is executed in child shell. When it terminates it's parent's CWD is unaffected. We have to source it:

goj@abulafia tmp $ . ./go echo ~
/home/goj
goj@abulafia ~ $


But this syntax sucks. Luckily, alias is our friend:

goj@abulafia tmp $ echo 'alias go=". go-source-me"' >> ~/.bashrc
goj@abulafia tmp $ mv go ~/bin/go-source-me


You have to have ~/bin in your PATH.

goj@abulafia tmp $ go echo ~
/home/goj
goj@abulafia ~ $


Ta-dam!