User loginNavigation |
LtU ForumInteresting? closure/object ideaI've been designing a language for my kids to use (goal: low barrier to entry, gentle learning curve up to serious power); one of the design choices has been to make closures easy to write. After reading Paul Graham's ILC 2003 talk, I started wondering how much I would need in the language to permit objects to be done as a library. Objects are equivalent to closures, but I wanted to leave room for a convenient syntax. (If nothing else, a lot of the system facilities I'll want to bind to, such as GUI toolkits, are OO, so being able to speak OO lowers the impedance mismatch.) So, the first thing I thought of was to break encapsulation (again, this was triggered by Graham's talk), to expose the bindings contained in a closure. So, if we do OK, so that can be used to make objects convenient. Then I started wondering about inheritance. After some false starts, I hit upon the idea of letting the right-hand argument of "." be a general expression. So, for example, C2=C.{var double={x*=2}}
creates
class Point(x,y) {
to moveBy(dx,dy) {
x+=dx; y+=dy;
}
to abs() {
sqrt(x*x+y*y);
}
}
maps to:
Point=
{x,y: {
var moveBy={dx,dy: x+=dx; y+=dy;};
var abs={sqrt(x*x+y*y);};
}
}
and:
class PointWithFlip(x,y): Point(x,y) {
to flip() {
var tmp=x; x=y; y=tmp;
}
}
maps to:
PointWithFlip=
{x,y: Point(x,y).{
var flip={var tmp=x; x=y; y=tmp;}
}
}
That is, to create a I'm pretty happy with this idea; it should let me teach my kids closures, rather than objects as such, but without blocking them from doing OO should it be useful. And, of course, I suspect that being able to get an arbitrary expression evaluated within a closure will turn out to be pretty powerful--with that, you could do things on the fly for which OO requires a subclass. And it doesn't distort the core language much, because you have to be able to construct closures inside closures anyway. Is this something that's been studied before? If it has, of course, I'd like to read about it before trying to implement it. Writing a DSL for Java
The site java.net has an article on extending Java with Tasks, code blocks executing in a separate thread. This particular extension may not be very exciting, but perhaps it will introduce the idea of DSLs to a new group of programmers.
The article uses a parser generator called VisualLangLab that seems to be "Yacc with a GUI". Since the goal of the article is to extend the Java language, they need a Java grammar to start with. VisualLangLab comes with a Java 1.4 grammar, so that is what is used. This means that the Task extension cannot be used with a 1.5 compiler; even though the extension only touches parts of the Java grammar that have not changed between 1.4 and 1.5 (I guess). Could this problem be circumvented if the standard libraries provided a representation of the grammar used in the current platform? Language design: Escaping escapesMost languages use special characters or special sequence of characters to denote the use of special directives. For instance, in C format strings: "\n" denotes new line, and if you wanted to have backquote n, you'd have to write "\\n". In VB, since " is used to delimit strings, you'd use "" to mean double quotes. eg. "He said ""Boo""!" In each case, if you wanted to show source code in the same language, it gets very painful, since you'd have to escape escapes. For instance to show the example of <img> tag in HTML, I'd have to do this: <img src="example" > In C you'd do this: printf("For example: printf(\"Hello World\\n\"); prints \Hello World\"\n");
Are there any languages or patterns which handle this kind of situation more elegantly? Examples of patterns:
Succ Zeroth International Obfuscated Haskell Code Contest ResultsSee the results! Proceedings of Scheme Workshop 2004Proceedings of the Fifth Workshop on Scheme and Functional Programming The proceedings from this year's Scheme Workshop, co-located with ICFP in Snowbird, Utah, are available online. The proceedings include the R6RS status report. Laszlo - So good, I had to change my underwear
A reliable, free, Flash development tool is really good news for amateur web designers. This will probably be a huge success. Paul Graham's invited talk at ILC 2003Hope this hasn't been posted yet. House , hOp - the Haskell Operating SystemBored by those lemmings who use wildly popular operating systems such as the HURD? hOp features VGA screen text and PS2 keyboard support, House adds a PS2 mouse driver and linear framebuffer graphics support. Reserve your copy of hOppix today! away from interpreter hacking and toward enhancing stdlibAndrew Kuchling writes:
Shoot-out: most annoying compiler error messageToday, I ran into a compiler error message which was hopelessly uninformative. Since I am up for something light-hearted, I thought I might as well just ask if anyone remembers his most annoying compiler message. I guess anything goes, well maybe except for the "e345: internal error message" kind of type. |
Browse archives
Active forum topics |
Recent comments
1 day 10 hours ago
2 days 7 hours ago
3 days 11 hours ago
3 days 12 hours ago
1 week 1 day ago
1 week 1 day ago
1 week 1 day ago
4 weeks 2 days ago
5 weeks 14 hours ago
5 weeks 19 hours ago