From: Simon Brooke
Subject: Re: Syntax question
Date: 
Message-ID: <CxBq69.2G3@rheged.dircon.co.uk>
In article <··········@ucc.su.OZ.AU> ······@acm.org (Adrian Cho) writes:

   I am writing a chart comparing the syntax of a number of languages for an 
   English sentence.
   For example:

   English:    Jack, put the box on the table

   Smalltalk:  Jack putThe: box onThe: table

   C:          putOn( Jack, box, table )

   C++:        Jack.putOn( box, table )

   Would someone in this newsgroup be kind enough to e-mail to me 
   (······@acm.org)
   the equivalent for the language of this newsgroup.  I think the above 
   example
   is self-explanatory.  Jack, box, and table are entities or objects and 
   'put on' is an action
   or verb.   Please use the correct case and indicate which language it is 
   since I have posted
   this to a number of groups! <g>

   Any help is much appreciated.

   Thanks

   Adrian

   ······@acm.org


Well, you did ask! I don't actually have a function for put on, but
here follows an example of put into, which is more complex and thus
more interesting. I'm not holding this up as an example of fine code!

Language: Cambridge LisP

How to call it:
-----------------------------------------------------------------------

(PutInto 'jack '(put the larger green box into the drawer of the table))

-----------------------------------------------------------------------


The function:
-----------------------------------------------------------------------

(de PutInto (player line)
					%% Two arguments: the player
                                        %% performing the action;
                                        %% a list of tokens representing a
					%% command in English.

       (let*
          ((l (Flatten (subst (DescribeIt) 'it line)))
					%% Substitute a description
					%% of the last object handled
					%% for the token 'it' in the
					%% command input.
             (cands
                (append
                   (RBurdenOf player)
                   (RObjectsAt (LocationOf player))))
					%% Candidate objects are all
					%% objects carried by the player
					%% (treating containers recursively)
					%% and all objects in the players'
					%% immediate environment.
             (subject (IdentifyObject l cands))
					%% The subject (the thing to be put 
					%% in) is the first of the candidates
					%% described in the command input.
             (container
                (IdentifyObject
                   (member 'the (or (member 'into l) (member 'in l)))
                   cands)))
					%% The container is the first of the
					%% candidates described after an
					%% instance of 'the' following an
					%% instance of 'in' or 'into'
					%% (this is a hack which depends on
					%% the fact that in Cambridge LisP
					%% member returns the tail of the
					%% list from the saught object on).
          (cond
             ((null subject) (Report '(What is it you want to put?)))
					%% Lots of idiot checking required
					%% when handling unrestricted input.
             ((null container)
                (Report
                   (list
                      '(Where do you want to put the)
                      (NameOf subject))))
             ((null (ContainerP container))
                (Report
                   (list 'The (NameOf container) 'isn!'t 'a
                      'container)))
             ((null (WillFit subject container))
                (Report
                   (list 'The (NameOf subject) 'won!'t 'fit 'in 'the
                      (NameOf container))))
             (t (put
                   (LocationOf player)
                   'objects
                   (Remove subject (ObjectsAt (LocationOf player))))
					%% If the subject was just lying
					%% around, it isn't any more...
                (put
                   player
                   'burden
                   (Remove subject (BurdenOf player)))
					%% if the player was holding the
					%% subject, s/he isn't any more...
                (UnPack subject cands)
					%% otherwise, the subject was
		                        %% contained in one of the other 
					%% candidates, so unpack it.

					%% One of these three calls
					%% will unlink the subject 
					%% from its present place; the other
					%% two will fail silently. I don't
					%% care which.
                (put
                   container
                   'contents
                   (cons subject (ContentsOf container)))
					%% Link the subject into the container.
                (setq *it* subject)	%% Remember the we've handled the
					%% subject, in case there's a reference
					%% to 'it'.
                (Report
                   (list
                      (cond
                         ((eq player *activePlayer*) 'You)
                         (t (list 'The (NameOf player))))
                      'put 'the (NameOf subject) 'into 'the
                      (NameOf container)))) ))) )
-- 
·····@rheged.dircon.co.uk

			-- mens vacua in medio vacuo --