From: peng
Subject: help me understand some codes
Date: 
Message-ID: <1102448488.b4c77cceb19ca8234f2fcef7b0faa090@tng>
peng wrote:
> *hi there,
> I need your help to understand the syntax of each row in below lisp
> codes written in ACL. especially the use of " -> ","->*" and
> declaration here.
> 
> ;---
> (defun well-sorted-p (x &optional subst (sort top-sort))
> ;; determines if expression is well sorted
> ;; it does this by doing well-sorting on the expression
> ;; with the restriction that no instantiation be done
> (prog->
> (quote t -> *%checking-well-sorted-p%*)
> (well-sort x subst sort ->* subst)
> (declare (ignore subst))
> (return-from prog-> t)))
> ;---
> 
> Thank in advance for your kindly help. * 


I also give the well-sort definition here, though actually I can't
understand this funcion completely too. Why "cc" is so often used?

;---
(defun well-sort (cc x &optional subst (sort top-sort))
(dereference
x subst
:if-variable (cond
((or (eq top-sort sort) (subsort-p (variable-sort x)
sort))
(funcall cc subst))
(*%checking-well-sorted-p%*
)
((subsort-p sort (variable-sort x))
(funcall cc (bind-variable-to-term x (make-variable
sort) subst)))
(t
(let ((sort (sort-intersection sort (variable-sort
x))))
(unless (eq bottom-sort sort)
(funcall cc (bind-variable-to-term x
(make-variable sort) subst))))))
:if-constant (when (or (eq top-sort sort) (subsort-p (constant-sort
x) sort))
(funcall cc subst))
:if-compound (let* ((head (head x))
(args (args x))
(fsds (function-sort-declarations head)))
(cond
((null fsds)
(well-sort-args cc args subst nil))
(t
(case (function-arity head)
((:alist :plist)
(dolist (fsd fsds)
(when (fsd-subsort-p fsd sort)
(well-sort-alist cc (first args) subst
fsd))))
(:list*
(dolist (fsd fsds)
(when (fsd-subsort-p fsd sort)
(well-sort-args cc (first args) subst
fsd))))
(otherwise
(when (and (function-associative head) (cddr
args))
(setq args (list (first args) (make-compound*
head (rest args)))))
(dolist (fsd fsds)
(when (fsd-subsort-p fsd sort)
(well-sort-args cc args subst fsd)))))))))
nil)
;---



--
peng
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------
 

From: Fred Gilham
Subject: Re: help me understand some codes
Date: 
Message-ID: <u7k6rtaer4.fsf@snapdragon.csl.sri.com>
Peng wrote:
> I need your help to understand the syntax of each row in below lisp
> codes written in ACL. especially the use of " -> ","->*" and
> declaration here.

If you could post the entire file it would be easier to help you.

It's hard to figure out what is going on without more context.

-- 
Fred Gilham                                     ······@csl.sri.com
I mean what's Stanford doing teaching Java?  That's not education,
it's vocational training.                        -- Bruce Stephens
From: Carl Shapiro
Subject: Re: help me understand some codes
Date: 
Message-ID: <ouy3byhnqz8.fsf@panix3.panix.com>
peng <···········@mail.codecomments.com> writes:

> peng wrote:
> > *hi there,
> > I need your help to understand the syntax of each row in below lisp
> > codes written in ACL. especially the use of " -> ","->*" and
> > declaration here.
> > 
> > ;---
> > (defun well-sorted-p (x &optional subst (sort top-sort))
> > ;; determines if expression is well sorted
> > ;; it does this by doing well-sorting on the expression
> > ;; with the restriction that no instantiation be done
> > (prog->
> > (quote t -> *%checking-well-sorted-p%*)
> > (well-sort x subst sort ->* subst)
> > (declare (ignore subst))
> > (return-from prog-> t)))
> > ;---
> > 
> > Thank in advance for your kindly help. * 

The -> operator establishes local variable bindings.

For example

  (prog->
    (fn arg1 arg2 -> var)
     ... ) 

is equivalent to

  (let ((var (fn arg1 arg2)))
    ...)

also

  (prog->
    (fn arg1 arg2 -> var1 var2)
     ...)

is equivalent to

  (multiple-value-bind (var1 var2)
    (fn arg1 arg2)
     ...)

The ->* operator establishes local function bindings.

For example

  (prog->
    (mapcar (list 1 2 3 4) ->* x)
    (print x))

is equivalent to 

  (mapcar #'(lambda (x) (print x)) (list 1 2 3 4)) 

> I also give the well-sort definition here, though actually I can't
> understand this funcion completely too. Why "cc" is so often used?

This is not obvious, but the rebinding of *%checking-well-sorted-p%*
short circuits the dereference variable case.