Tuesday, March 14, 2006

Using schmoozing

My colleague's blog, ostensibly about legume-based foodstuffs and the macroscopic effects of quantum mechanical spin has another post on our current work project, the Neptune Language. I was going to anonymously add a contribution to his latest missive in the comments section (it needs livening up), but Blogspot won't let me use the <pre> tag in comments so I'll have to throw away any pretence at being an interested but disinterested bystander and use my own brand new blog to snipe kibbitz provide feedback.

He describes the suggestion as a straw man, but there's no point in having a straw man if no one is prepared to beat it up, so let me don the boxing gloves. From his blog entry:

File my_file = ...;
using (InputStream in : my_file) {
// read file
}

This is all very well if the only thing you ever want to do to the file is read it, but what if you want to write to it or even lock it?

Clearly a more general mechanism is needed. I suggest that in addition to the using keyword, any construction of the form:

xxx(type y : obj) {
...
}

is simply syntactic sugar for

obj.xxx(fun(y) { ... });

This way we can get rid of the 'nasty' special case syntax of 'for' on collections and several other constucts :-).

Now that's what I call a straw man :-).

2 Comments:

At 08:44, Blogger plesner said...

Language design by blog -- I'm pretty sure that's never been tried before ;-).

Yeah, using the using statement for file i/o the way I wrote probably doesn't work. You only have to tweak it a little, though. For instance you could implement file access by using my_file.reader and my_file.writer instead of just my_file.

As for the general block method shorthand I think the syntax is uncomfortably close to the syntax for implicit self sends when there are no variable declarations: xxx(obj) means this.xxx(obj) whereas xxx(obj) { ... } means obj.xxx(fun { ... }). That might be confusing.

 
At 12:49, Blogger Erik Corry said...

Well, that ambiguity is why I wanted to restrict it to either the word 'using' or a construction with a colon in the parentheses.

In order to make it more readable you could say that the method name has to be a gerund. :-)

 

Post a Comment

Links to this post:

Create a Link

<< Home