This is G o o g l e's cache of http://sixteenvolts.blogspot.com/2006/04/eliminate-some-unnecessary-redundancy.html as retrieved on 16 Sep 2006 04:43:32 GMT.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
This cached page may reference images which are no longer available. Click here for the cached text only.
To link to or bookmark this page, use the following url: http://www.google.com/search?q=cache:A6LXxEANbDAJ:sixteenvolts.blogspot.com/2006/04/eliminate-some-unnecessary-redundancy.html+site:sixteenvolts.blogspot.com&hl=en&ct=clnk&cd=234


Google is neither affiliated with the authors of this page nor responsible for its content.

Send As SMS

« Home | Don't go there » | Confusion never stops » | Procrastination » | Honey, I picked up our new baby today » | Meanwhile, the birds are dying » | One long, sustained scream » | Are you angry yet? » | Lost in Yonkers » | It's in the white of my eyes » | All 78 episodes of Star Trek »

Eliminate some unnecessary redundancy

(Warning: this post is not at all interesting unless you are a programmer / computer science major.)

Even though I explained the workings of the language in my new book, it's been over a year since I last actually modified the source code for my Zilk programming language. Since I built that language pretty much on a whim as I went along since it was just a learning experiment, and the whole thing was originally supposed to be at most a simple toy language roughly equivalent to the interpreted Basic of the old Commodore 64 computers, I didn't really design it properly. I would do many things differently both in the language itself, the compiler and the runtime environment if I started a project from scratch. But even so, I am happy how it eventually turned out, especially the integration to Java so that Java classes can be used inside Zilk as if they were ordinary Zilk classes.

Today I finally made one small change that had annoyed me since ever, but hadn't found the energy to do it. After this change the language is insensitive to punctuation and it is not needed, although it is allowed for extra clarity. The compiler knows where each expression ends from the whitespace, so why should the programmer indicate this with syntactic salt? The statements don't need to be separated with semicolons or anything like that, but also expressions in lists and parameter lists need no commas between them. For example,

def sum |a b c|
a+b+c # implicitly return the value of last expression
enddef
println sum(1 2 3) # outputs 6

would work as you'd expect. I liked the syntax of vertical bars that Ruby uses for block parameters so much that I decided to use them also with ordinary function parameter lists.

The change that I just made corrected the silly choice of using an asterisk to explode lists into elements. Doing things this way suddenly made commas important, because in the code

a is [2 3]   # is for assignment, eq for comparison
println sum(1, *a)
println sum(1 *a)

the first function call works just fine, calling sum(1 2 3), whereas the second tries to multiply integer 1 with list a, resulting in a runtime error. D'oh. Since the ampersand character wasn't used for anything in Zilk yet, I chose the ampersand to be the list explosion operator, removing this syntactic ambiguity.

The Zilk language was originally inspired by the two great languages Python and Ruby, although giving much more weight to the latter. For example, that each statement is by itself a legal expression and that the names of fields start with @ are taken straight from Ruby. The syntax of Python, of course, heavily depends on whitespace in form of indentation that defines the program structure, which looks neat but gives the Pythonistas pain now that they would like to add real lambdas to the language. Since whitespace separates expressions in Zilk, unlike in Ruby it makes a huge difference whether you write

sum(1 2 3)  # function call
sum (1 2 3) # two separate expressions

since the second line is not actually a function call, but it consists of two separate expressions sum and (1 2 3), which are evaluated in sequence. The first one silently evaluates to a function object, and the second one, which is actually three expressions grouped in a code block, silently evaluates to the value of its last expression (the same way as in Scheme), which is 3. For a more complex example that also illustrates that all statements are expressions,

println (1 println 2 if false 3 else "Hello" endif)

would output

2
Hello

Since I also like the Prolog language, one idea I have been tinkering with would be to create a language that essentially works like Prolog but whose syntax would be more traditional and thus more to the liking of programmers who are familiar with the imperative languages. I am sure that such a language would be an interesting exercise, but I don't really know where to even begin. Prolog is, of course, already by itself so elegant, complete and self-containing that it's hard to see how it could be any way different. Other than the trivial modifications such as losing the silly convention that anything that starts with a capital letter is a variable and replacing this by the use of some special character such as $ or @.

Comments

Links to this post

Create a Link

Contact

ilkka.kokkarinen@gmail.com

Buttons

Site Meter
Subscribe to this blog's feed
[What is this?]