[plt-scheme] Paren Paralysis Sufferers Unite

From: Gregory Marton (gremio at acm.org)
Date: Wed Oct 21 22:32:46 EDT 2009

>>     ( foo / bar / clum / ink )
>> means
>>     ( foo ( bar ( clum ( ink ))))
> This is similar to the way that the $ infix operator (function 
> application) is used in Haskell.
>     foo (bar (clum (ink)))
> becomes
>     foo $ bar $ clum $ ink
> John Clements once teased me for using $ in a short snippet of Haskell I 
> wrote. Like all syntactic sugar, overuse increases the chance of diabetes. 
> (There, I have left an opening for a pun, if anyone cares to pursue it.)

This is also reminiscent of the use of / in categorial grammars.  Slashes 
are used to associate lambda calculus expressions with recognized parts of 
a string.  Each lexical item has a pattern, a signature (type), and a 
semantics, so
     "John" : NP :- "John"
     "loves" : (S \ NP / NP) :-
        (lambda (obj) (lambda (subj) (loves subj obj)))
     "Mary" : NP :- "Mary"

With this lexicon, the string "John loves Mary" is parsed by first 
recognizing the three lexical items, then using the forward slash in the 
signature for "loves" to mean "apply forward", which is to say, apply the 
semantics associated with "loves" to the semantics of the thing to its 
right (which must have a matching signature with the rightmost element of 
the signature for "loves").  You thus get a new meaning

     "loves Mary" : (S \ NP) :- (lambda (subj) (loves subj "Mary"))

This can now apply backwards to the argument "John", making
     "John loves Mary" : S :- (loves "John" "Mary")

Purely in Scheme, the directionality of the slash doesn't matter.  It's 
neat that in both cases it means "apply" -- I'm sorely ignorant of the 
roots of these things, so I can only guess that they're causally related.

I wrote a parser for such expressions that uses (sorry) Guile as its 
underlying semantic interpreter, and have been toying with the semantics of 
various expressions of English.  I'd love to talk with folks about it if 
there's interest.  I have thought about porting it to PLT.


------ __@   Gregory A. Marton                 http://csail.mit.edu/~gremio
--- _`\<,_                                                     617-775-3005
-- (*)/ (*)                  In charity there is no excess.

Posted on the users mailing list.