开发者

Programming Languages that Make Use of Special Characters

I'm working on a general-purpose programming language. In addition to the modern requirement of Unicode support in strings and identifiers, I'm considering supplying alternate spellings of some operators, specifically:

  • Relational ( for <= >= !=)

  • Bitwise and Setwise ( for & |)

  • Logical ( ¬ for && |开发者_JS百科| !)

  • Arrows ( for -> =>)

I know that APL and Fortress make use of special characters—and the former is often the butt of jokes about it—but these are both very much geared toward academic and scientific use. Do special characters have any place in a modern, non-academic language?


Special characters have any place in a modern, non-academic language?

Yes, but because on most desktops the support for special characters is still awful (bad editors, bad fonts, you name it),

  • You better be planning ten years ahead.
  • You better be very sure there is a good, usable alternative using only ASCII characters.

I would never advocate a preprocessor: there is too much temptation and room for abuse, and unless it is done very carefully, a preprocessor makes it much harder to write good IDEs and static-analysis tools.

Some people like a postprocessor, i.e., a prettyprinter, that takes sequences of ASCII characters and renders them as something else. While I have always found this style dreadfully confusing, it is quite popular and successful among some Haskell programmers.


In my opinion they have no place in a language, but definitely belong in a default preprocessor. You may get the APL-keyboard problem though. (and possible visual ambiguity).

A limited example of this as a pre/post processing would be cweaved code.


The special characters and are reserved words in Scala. is used for introducing generator bindings whereas is used in the function definitions to separate parameter lists from the function body.

Examples:

for {
  word ← List("Hello", "World")
  character ← word
} println(character)

val square = (x: Int) ⇒ x * x

It should be noted that Scala compiler also allows the ASCII alternatives of the above symbols (i.e. <- and =>).


Isabelle (the theorem prover) allows LaTeX-style command sequences as valid inputs. Various front-ends then do appropriate things to turn these into special characters. The nice result of this is that it's still just vanilla ASCII text, but you can have all the nice pretty display characters looking as you expect in an editor that is aware of those characters.


It's an interesting concept, but aren't you worried that multiple spellings of the same thing will make parsing the code more difficult, especially for IDE's? Not to mention the additional time taken to teach what those symbols mean to incoming new programmers? If you're supporting unicode and therefore possibly other languages (variables in japanese?), these make another layer of inscrutability. In addition, how useful have you found their logical opposite, the C trigraph ( http://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C )? :-)


The one language I've used that relies on non-ASCII characters is TI-BASIC, which uses for assignment, // for comparison, has built-in constants π and , a function, etc.

On the PC, I doubt that'd I'd use non-ASCII operators much, simply because it's so much quicker to type != than it is to look up in character map.


I like the idea of using the proper characters a lot. However, in order to use then I would really want a keyboard that had extra punctuation keys to be used for them. And while we're at it, things like { } ( ) " ? + * should all be on their own keys too.


Not sure about a general purpose language, but these have a place in a DSL for a domain where they're sensible. And it can certainly be done in some modern languages. For an example in Scala, see this blog post.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜