A TEXT POST

A Proposition for a new Language

  • Is a lisp: There’s always something to be said for homoiconicity.
  • Is neither a lisp-1 or lisp-2: It’s like a lisp-1 in that there is only 1 namespace, and like a lisp-2 in that there is a seperation between functions and other values. It would have static typing to differentiate functions and other values (but in the lisp tradition, dynamic typing for everything else). The reason for this will become clear shortly.
  • Lowers the barrier to entry by allowing infix function form: By knowing what is and is not a function at compile time, it is possible to freely put functions anywhere in the s-expression and let the compiler move them to the beginning. Normally an expression like (1 + 2) would be an error because 1 is not a function, but the programmer knows that + is a function and that that’s what needs to be evaluated. With static function typing, the compiler will rewrite expressions to evaluate the first function in the expression.

    You can also sharpquote any function that you don’t want to be evaluated, allowing infix functions like compose: (#'reverse o #'sort). I choose sharpquote because it servers a purpose similar to sharpquoting in common lisp, but a shorter prefix might be preferable.

  • Has literal data structure syntaxes: Clojure has it right with how it treats non-cons-cell data structures, but the syntax interferes with standard lisp conventions, for example:

    (cond [(cons? n) (...)]
          [else      (...)])
    

    Instead of how clojure uses different baracket types directly, it requires a # prefix before the brackets:

    • Vectors use the mathematical angle bracket notation: #<1 2 3>.
    • Sets use parenthesis: #(1 2 3)
    • Maps use the standard curly brackets: #{:hello "world" :foo "bar"}
    • Tables (addressed later on) use square brackets, and start with a list of fields: #[@field1 @field2 @field3]
    • Linked lists are just quoted lists: '(1 2 3)

    Of course all of these a just shorthand for calls to vector, set, map, table, etc.

  • Has SQL-like tables: Relational databases provide a very expressive way to query data efficiently, so why not have it native in the language, complete with a literal syntax for tables and field names? Field names are prefixed with an @ character and by convention are only used as field names in literal tables, and in queries.

    Table literals are represented as a list of field names, followed by the rows of the table. The number of field names at the beginning of the table is used to determine the number of columns in the table. An example table could be something like:

    #[@id @u-name  @p-word
      1   "adrusi" "f6632c24dd46eb3982fa936c9832da8c"
      2   "jdoe"   "a31405d272b94e5d12e9a52a665d3bfe"]
    

    Queries are essentially SQL, but with more lisp-like names and syntax:

    (def users
      #[@id @username
        1   adrusi
        2   jdoe
        3   pancakeman49])
    (def follow-relations
      #[@id @follower-id @followee-id
        1   2            1
        2   3            1
        3   1            2]
    (defn (followers-by-username username)
      (select (select (select all-fields
                       from users
                       as followers
                       where (eq? (followers @id) (relevant-relations @follower-id)))
               from follow-relations
               as relevant-relations
               where (eq? (relevant-relations @followee-id) (followee-user @id)))
       from users
       as followee-user
       where (eq? (followee-user @username) username))))
    

    The select syntax is just a macro that normally expands to calls to map, filter and other such functions (which are defined generally and work on tables as a list of maps).

    Also shown in that example is that table rows are functions of their field names (and vice-versa). Not shown are other structures like joins and unions which also work as expected.

    Apart from being an expressive addition to the language, built in SQL also helps libraries remain consistent. There should also be a hook for the same syntax to work for other database systems, ones outside of RAM. These won’t have access to the full language in where and on clauses, but otherwise should look the same, which should also help with scalability. When making a quick prototype you use a database in RAM, but then as needed you can migrate to sqlite, and then to postgres, without changing any query code.

  • Algebraic data types. These would be available for use in pattern matching, and could also be optionally used to generate compile time warnings. All standard library functions would be implemented in terms of algebraic data types and type classes unless they don’t fit that model.

  • Pattern matching is a must in every new languages, and it works especially well with with algebraic data types which let you define your own patern-matching structures.
  • A logic programming library. Prolog works very well for some use-cases, but is just too pure for most. However, logic programming can work very well for certain calculations within a larger system, so embedded prologs are a welcome addition to every language.

Well that’s a wrap, I would strongly appreciate comments on what you like and don’t like.

A TEXT POST

The end of the Hackers

It’s no secret that I think computer science (in the form of coding) should be taught in schools, starting at a young age, somewhere between eight and ten. Earlier I found this article about a campaign called “Code is the New Latin” which aims to promote the teaching of computer science in public schools. While I agree with what it says and support it, I’m beginning to feel that there would be some negative side effects.

I started learning to code when I was eleven. It became my passion, and I strived to learn more. Since I wasn’t being given any formal lessons in the subject, I had to find my own resources and teach everything to myself. I’m not going to go into details about my journey, but in the end I learned a lot.

Not only did I learn about programming and computer science, I learned about how to learn. In school you’re fed information, and you will learn if you’re willing to do so. I don’t have any real experience with it, but I can be quite sure in saying that outside of a school, you have to know how to learn on your own if you want to keep up; especially in a rapidly changing field like computer science.

Sure there are some resources available that are more like schools—conferences and seminars and the like, but in order to be as good as possible in your line of work, most of what you learn needs to come from yourself, not from infrequent presentations and 5-class courses.

And judging from my experiences, there are two subjects in where students commonly teach themselves. One is art (including music) and the other is technology (hacking, coding, etc.).

Most children who become interesting in a visual art begin before they even start school, by the time they have their first art class, they already know that they love to draw, or paint, or sculpt, etc. Children who love music usually already know this before their first music class that goes beyond singing and banging on drums.

Coding is different. As far as I know, no six year olds discover that they love programming that young. From what I’ve seen, kids start to show interest between ten and twelve.

While I think they would find a mandatory computer science course fun and learn a lot from it, it worries me that learning programming, which traditionally requires the young hackers to explore and learn for themselves, would become just another interesting school subject.

I love math in school, but I rarely research maths independently unless it connects to programming*. It worries me that the same would happen to computer science if it became a normal part of the curriculum, that it would bring an end to the era of teen hackers.

I’m talking about people like Comex, Thomas Suarez, myself and plenty of my friends.

Most of the young hackers are entirely self taught, yet still are equal or sometime superior to adults who have years of experience and a college education behind them.

Maybe I’m just being overly sentimental, but I feel like society would be at a loss if the hackers faded away.


* For example, I taught myself trig a few years before I would learn it in school so that I could implement a logo interpreter.

A PHOTO

Taken with instagram

A TEXT POST

UNIX on a Jailbroken iPhone

So I jailbroke my iPhone a few days ago, and one of the first things I installed (the main reason I jailbroke it) was MobileTerminal, the only real terminal available for iPhone. Unfortunately, MobileTerminal is IMO a very shitty emulator. For one, there is no multi-tasking support, so if I switch to Safari to look something up, then switch back to MobileTerminal, it logs me out and starts a new session.

Despite this, I installed some of the programs I use most, including vim, a package manager (apt-get with a small repository), a Haskell interpretter (`hugs, I couldn’t get ghc to install). I also tried to install gcc, but while I got the compiler working fine, I couldn’t get the headers to work, so it’s useless for all intents and purposes.

I initially tried to get around the multi-tasking problem by using lynx, the text-based web browser. That was fine for simple stuff, but the web just isn’t designed to be particularly accessible to text-based browsers anymore.

I thought of tmux at first, but when it wasn’t on cydia, or the iPhone apt repository, and since I can’t use gcc really, I abandoned the idea. After a while (today) I realized that I could use GNU screen instead. So what I do now is run a single screen session and then do all my commands in that, and then when my terminal emulator restarts I just do ascreen -r` to attach to the existing session.

I hope this is useful to others who want to use the phones as a mobile UNIX system (are there any others)?

A PHOTO

a USB to mini USB cord with a sex change attached to a naked flash drive. ghetto in a silicon valley kind of way (Taken with instagram)

A PHOTO

What do you mean I don’t have a MacBook pro? (Taken with instagram)

A PHOTO

I’m starting rails development, and I’m liking my setup. It uses iTerm’s split panes to show my vim editor, a shell to do various stuff, like commits, generating stuff, running migrations and running tests.

A TEXT POST

Vim and iTerm2

I use iTerm2 as my terminal emulator, and although at first I didn’t realize how powerful it is, after using it with vim, It’s clearly many times better than Terminal.app.

The first cool feature I found is that iTerm2 can emulate a 265-color xterm, so I can use nice color schemes outside of gvim. I use the solarized light colorscheme for both vim and iTerm.

More recently I discovered that iTerm2 supports xterm mouse reporting, so when I need it I can enable mouse support in vim. I don’t want it on all the time because then I may as well use gvim, but I mapped a command to enable and disable mouse support to ,mm and ,mn respectively (, is my leader key). The mouse is most useful for resizing windows and copying text from vim to use in other programs (I’m still working on this).

iTerm2 also supports a non-standard escape sequence to change the cursor style between box, vertical bar and underline. I prefer a vertical bar in insert mode but an underline everywhere else, so I used some code from the iTerm2 documentation to make vim automatically change the cursor style in insert mode. Since this is non-standard, I was worried that my .vimrc would become unportable, but I hacked up a solution.

I added the line export ITERM=1 to my bashrc. In my vimrc, I can now check if the $ITERM environment variable is equal to 1, and if so enable the non-standard cursor control. This means that at home I can use my luxury cursors, but when on another computer, I don’t run into compatibility issues.

A TEXT POST

My Thoughts on Vim

Vim is an amazingly powerful text editor, but until very recently, when I got it set up perfectly I’ve felt that it’s messy. This is because a lot of vim’s power come from its extensibility. The problem with that is that a lot of the most powerful things are made by a third party plugin that might have been thrown together in a few days and is filled with bugs. These bugs are usually small and unnoticeable, but when you have 20 plugins, 15 of which have some tiny glitches, then it’s like death by 10,000 paper cuts. Fortunately, vim provides a lot of customization power to the user, which means that it’s possible to fix a lot of the glitches by doing things like mapping commands to do something else. This is great for an advanced user, but a novice would be bound to feel like their vim is a complete mess because they don’t know how to remap keybindings to do the right thing, and they can’t be expected to.

I think that once the initial hurdle of memorizing the vital commands and understanding the modal nature of vim is passed, the hardest part of learning vim is learning how to tame the mess that vim can so easily become.

A TEXT POST

For Vim and NERDTree Users

Here’s a useful command. It opens up NERDTree in vim’s current working directory:

:NERDTree `pwd`

And then when you’re browsing to filesystem in NERDTree and want to set a directory as the current working directory, you can type cd with the directory selected in NERDTree and it will do just that.

I have a few mappings for NERDTree in my .vimrc. They are as follows:

nmap <leader>nt :NERDTreeToggle <CR>
nmap <leader>nn :NERDTree `pwd` <CR>

If you find it useful to open NERDTree in the directory of the file you’re currently editing, then you can map something to :NERDTree %