nolta/julia — comment on commit 133a9f655f336f1c21b1388f6f5431d2f4e37314
File:  line 0
By StefanKarpinski:

The `:` prefix works a little differently in Julia than in Ruby. In Ruby it is only used for symbols. In Julia, it actually introduces general expression quoting, a la `` ` `` in Lisp (not `'` since you can always interpolate into quoted Julia expressions). When the thing that follows the `:` is an identifier like `foo`, then what's produced is the quoted expression representation of an identifier — i.e. a symbol. However, when the thing that follows the `:` is some other kind of expression, then a different expression representation if produced. In the case of numeric literals like `4`, they are their own literal representation — so `:4` just evaluates to `4`. Same thing with `:1.5` => `1.5` or `:"foo"` => `"foo"`. If you put something more complicated after the `:` like `:(a+b)` you can get an actual `Expr` object:

```
julia> :(a+b)
+(a,b)

julia> typeof(ans)
Expr
```

As to the business of `start:step:stop` versus `start,stop,stride`, I can't see why either is really any better than the other. I don't think this is a "wart" of Matlab — there are many, but afaict, this isn't one of them. Since we borrow the colon syntax for ranges from Matlab, it seems sensible to retain the overal behavior of ranges in Matlab — doing anything else would confuse the hell out of Matlab users (including me). Sure, Fortran has a different ordering, but then again it also has a completely different sytax, so there's no real danger of confusion.

I completely agree, however, that `s[:4]` just giving the fourth character in the string is a problem. It really needs to be an error, because otherwise that's just too damned easy to do. Perhaps we should require parens — as in `:(4)` — when the colon is used with anything but an identifier.