Could Implicit Topics be Implemented Cleanly in a Language?
I was getting bored, so I started cranking out my own HTML templating language in Perl 5.14 just because I could. Partially as a bit of fun, but more realistically because reading too much PHP code makes me want to gouge my eyes out with a can opener. Seriously, the mere existence of PHP offsets any aesthetic advantages this world gains via rainbows and sunsets.

Stop moaning PHP folks, I'm kidding and you know it  :)  PHP's simplicity at dynamically handling HTML is a strength, despite what any 50000-line framework users may say otherwise.

Regardless, I was thinking about how implicit topics would work in such a language. Perl has them via $_, but they're kinda nasty -- They're inconsistent, must be explicitly allowed by subs via prototypes, and they're exposed to the user via a reference variable, not to mention having to work out which built-ins use them and which ones don't.

What I'm talking about is wiring the concept of implicit topics straight into the language, with some very well defined rules. E.g. all iteration constructs assign it for each element and closures use it for the first argument (an easy way of having Ruby-do block elegance).

Now, here's the key bit: rather than defining a default 'it' variable, you just define strict semantics where the default topic is inferred and where it isn't. For example, a function that has one less argument than expected will use it as the first argument. Or whatever. You don't expose topics via a variable, rather by the <i>language</i>.

In a language like Lisp or Ruby this would be hard to do, since they don't really like language-level constructs like loops and prefer their own ways, whether it be macros or blocks + methods.

But in a language that embraces language-wired constructs like Perl, this could work really well.

But, and here's another thing, the language forces you to explicitly refer to things if there's a new topic being discussed. For example, if you had a for loop, the topic of the inner loop would be its own current element, not the outer current element. Perl users already do this, but other language-users may not be familiar with the concept.

So, could implicit topics be implemented <i>cleanly</i> into a language, with scoped topics that force the coder to be explicit when ambiguous?

This makes sense in English. We digress into subtopics were we discuss something else, and then we 'scope back out' to the 'super' topic and then make it clear the topic is what we were discussing before. It automatically then means the 'super' topic again. Our speech is dynamically scoped!

So, do you think it could be done cleanly, or will it always make code less readable? Post your thoughts below.

Also, what would the best way be for me to go about trying to parse this?
Could Implicit Topics be Implemented Cleanly in a Language?
===

I was getting bored, so I started cranking out my own HTML templating language in Perl 5.14 just because I could. Partially as a bit of fun, but more realistically because reading too much PHP code makes me want to gouge my eyes out with a can opener. Seriously, the mere existence of PHP offsets any aesthetic advantages this world gains via rainbows and sunsets.

Stop moaning PHP folks, I'm kidding and you know it  :)  PHP's simplicity at dynamically handling HTML is a strength, despite what any 50000-line framework users may say otherwise.

Regardless, I was thinking about how implicit topics would work in such a language. Perl has them via $_, but they're kinda nasty -- They're inconsistent, must be explicitly allowed by subs via prototypes, and they're exposed to the user via a reference variable, not to mention having to work out which built-ins use them and which ones don't.

What I'm talking about is wiring the concept of implicit topics straight into the language, with some very well defined rules. E.g. all iteration constructs assign it for each element and closures use it for the first argument (an easy way of having Ruby-do block elegance).

Now, here's the key bit: rather than defining a default 'it' variable, you just define strict semantics where the default topic is inferred and where it isn't. For example, a function that has one less argument than expected will use it as the first argument. Or whatever. You don't expose topics via a variable, rather by the <i>language</i>.

In a language like Lisp or Ruby this would be hard to do, since they don't really like language-level constructs like loops and prefer their own ways, whether it be macros or blocks + methods.

But in a language that embraces language-wired constructs like Perl, this could work really well.

But, and here's another thing, the language forces you to explicitly refer to things if there's a new topic being discussed. For example, if you had a for loop, the topic of the inner loop would be its own current element, not the outer current element. Perl users already do this, but other language-users may not be familiar with the concept.

So, could implicit topics be implemented <i>cleanly</i> into a language, with scoped topics that force the coder to be explicit when ambiguous?

This makes sense in English. We digress into subtopics were we discuss something else, and then we 'scope back out' to the 'super' topic and then make it clear the topic is what we were discussing before. It automatically then means the 'super' topic again. Our speech is dynamically scoped!

So, do you think it could be done cleanly, or will it always make code less readable? Post your thoughts below.

Also, what would the best way be for me to go about trying to parse this?