Arc Forumnew | comments | leaders | submitlogin
Unifying characters, strings AND symbols?
2 points by are 5934 days ago | 3 comments
Would have been interesting to hear PG's thoughts on unifying characters, strings AND symbols...

Here are my 2 cents':

- A string would be either the empty string, or a non-empty sequence of strings of length 1.

- A string would also have an _associated value_ (nil by default), that can be of any type (including functions, macros, special forms or other strings). A string would then also be a key-value pair, and a keyed hashtable could be treated conceptually as a collection of strings with no duplicates.

- A non-whitespace, no-paren (alphanumeric?) string will return its associated value (= be evaluated) in an Arc expression if you _don't quote it_, making such unquoted strings convenient for using as variable or function names. In addition, if such an unquoted string immediately follows a left-paren in an Arc expression, its value will be treated as a function and applied. (All this is different for special forms and macros, of course.)

- To quote a string, you would use double-quotes around it, to keep it from being evaluated, and returning itself rather than its associated value. Quoted strings are then string literals, and in this usage, the associated value will often be nil. String literals of length 1 are used as character literals.

- A non-whitespace, no-paren (alphanumeric?) string can alternatively be quoted by prepending a single-quote, in the same manner that you quote a composite Arc expression by prepending a single-quote before the leading left-paren. If you intend to use the associated value of the string, this is the preferred way of quoting it (for clarity).

- To return the associated value for a string that includes whitespace or parens (or non-alphanumeric parts?), you would have to do explicit evaluation by using eval with the double-quoted string. This would discourage (but not disallow) using such strings for variables and definitions.

I'm guessing this proposal is inconsistent and unworkable, but I'm throwing it out there anyway...



2 points by randallsquared 5934 days ago | link

I like the idea of symbols as a special case of strings, but I'm not as sure of the details. In particular,

    In a double-quoted string, you will have to escape parens, double-quotes and single-quotes by prepending a single-quote.
seems like a bad idea to me. Perhaps I don't understand why a double-quoted string wouldn't already be satisfactorily quoted?

-----

1 point by are 5934 days ago | link

Thanks; you're probably right that this is unnecessary, and wouldn't help the Arc parser much anyway.

You would have to escape double-quotes, though.

I like how Smalltalk handles this by allowing both single- and double-quotes as string delimiters:

"This is a string which includes two 'single quote' characters, which aren't escaped"

'This is a string which includes two "double quote" characters, which aren't escaped either'

This wouldn't work for Arc, though, if you also want to be able to use a _single_ single-quote for quoting symbols.

I've removed the sentence you quoted from my proposal.

-----

2 points by ehird 5934 days ago | link

wrong

smalltalk "abc"= comment

-----