[q-lang-users] [cowan: Chicken Scheme to Q interface almost ready for beta]
Brought to you by:
agraef
From: John C. <co...@cc...> - 2006-08-31 04:59:07
|
I'm really, really close to releasing the beta version of my egg for Chicken Scheme, which provides Chicken programmers with convenient access to the Q interpreter. There are only four points left: 1) Some code has not yet been fully tested. 2) I have to write some HTML documentation. 2) Improper tuples like "(1,2|3)" aren't yet being converted from S-expressions to Q binary representation. I expect they will be rare in Q expressions as opposed to rules: there is no S-expression representation of rules. 3) There is a conflict of expectations between Scheme and Q programmers around applications with multiple arguments. The Q application "f x" is written in S-expression form as (q:call f x); the "q:call" symbol marks it as an application rather than a list. (There are good reasons for not using a quote on the Scheme side.) Since Q is currying but Scheme is not, I allow "f x y" to be written as (q:call f x y) on the Scheme side, and that is treated as if it were (q:call (q:call f x) y). In particular, (q:call + 1 2) will properly reduce to 3. The difficulty arises when a binary operation is given more than two arguments. While testing, I tried normalizing (q:call + 1 2 3) and got back the surprising result (q:call 3 3). At first I thought there was a bug, but then I realized that the equivalent form was (q:call (q:call (q:call + 1) 2) 3), or in Q notation "(+) 1 2 3", which in fact means "((+) 1 2) 3" or simply "(1 + 2) 3", which indeed reduces to "3 3". Nevertheless, this *is* surprising, and means that to represent "1+2+3" as an S-expression one must write nested q:call lists. I thought of treating applications where the second element is an operator specially, but that would make it impossible to write the equivalent of "(1 + 2) 3" should one wish to do so. I'm very much open to suggestions on this one. Should I leave things alone? Should I introduce another q:xxx flag to mark calls of binary operators (required only if there are more than two arguments)? Or something else? If the last, what? -- But the next day there came no dawn, John Cowan and the Grey Company passed on into the co...@cc... darkness of the Storm of Mordor and were http://www.ccil.org/~cowan lost to mortal sight; but the Dead followed them. --"The Passing of the Grey Company" |