Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Function Evaluation Problems in ACL

2 views
Skip to first unread message

Warren Lucas

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to

Lisp List Readers:

I am experiencing a rather annoying problem while using ACL 5.0.1 for
NT. It is described below. Any help you can
provide would be very much appreciated!
In summary, I have attempted to apply (or funcall) a previously defined
function to a list of values and get very wrong
answers. When I apply the same function to the same list of values by
hand, I get the correct answer.

;; Sample Ouput Start
-------------------------------------------------------------------------

RUN-PROBLEM: Searching for Constrained/Optimal Solution #10

FIND-SOLUTION: fun = FN-505

FIND-SOLUTION: (symbol-function fun) = #<Function FN-505>

FIND-SOLUTION: objective-index = 0

FIND-SOLUTION: ovar-map = (0 1 2 3 4 5 6 7 8 9 10 11 12)

FIND-SOLUTION: new-vals = (0.39154148 1.5258789e-5 0.5694376 0.9998627
0.9999542
0.99994993 0.99994993 0.99994993 0.99994993
2.9996753 1.3113022e-4 5.0e-5)

FIND-SOLUTION: (get-elements-by-map ovar-map new-vals) =
(0.39154148 1.5258789e-5 0.5694376 0.9998627 0.9999542 0.99994993
0.99994993
0.99994993 0.99994993 2.9996753 1.3113022e-4 5.0e-5)

FIND-SOLUTION: fnval = (9.2287815e+9)

;; Sample Output End
-------------------------------------------------------------------

The value for "fnval" is not correct, but is the same for all solution
attempts. Each
attempt has a different set of values. When I apply the function
"FN-505" to the previous
list of values, I get "(-5.581772)", which is correct, as shown below.


PROBLEM-DEFS(46): (fn-505 0.39154148 1.5258789e-5 0.5694376 0.9998627
0.9999542 0.99994993
0.99994993 0.99994993 0.99994993 2.9996753
1.3113022e-4 5.0e-5)

(-5.581772)

The code fragment reporting these results is shown below. I also
noticed that when I use
"funcall" instead of "apply", the correct answer is shown most of the
time (approx.
80-90%).

;; Code fragment Begin
----------------------------------------------------------------

(format t "~%FIND-SOLUTION: fun = ~A~%" fun)
(format t "~%FIND-SOLUTION: (symbol-function fun) = ~A~%"
(symbol-function fun))

(format t "~%FIND-SOLUTION: objective-index = ~A~%" objective-index)
(format t "~%FIND-SOLUTION: ovar-map = ~A~%" ovar-map)
(format t "~%FIND-SOLUTION: new-vals = ~A~%" new-vals)
(format t "~%FIND-SOLUTION: (get-elements-by-map ovar-map new-vals) =
~A~%"
(get-elements-by-map ovar-map new-vals))

;; Debug Option A
;;(setf fnval (eval `(funcall ,(symbol-function fun)
,@(get-elements-by-map ovar-map
new-vals))))

;; Debug Option B
(setf fnval (apply (symbol-function fun) (get-elements-by-map
ovar-map new-vals)))

(format t "~%FIND-SOLUTION: fnval = ~A~%" fnval)

;; Code Fragment End
-----------------------------------------------------------------------------------------------

Surely I am missing something very fundamental about LISP. Can you help
here?


Thanks,

Warren


--

____________________________________________________
Warren K. Lucas
Assistant Professor
Department of Civil and Environmental Engineering
368 Clyde Building
Provo, Utah 84602
(801) 378-6234
wkl...@byu.edu
____________________________________________________

Drew McDermott

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
Warren Lucas wrote:

> Surely I am missing something very fundamental about LISP. Can you help
> here?

The code looks okay to me. The only slight bug is

(setf fnval (eval `(funcall ,(symbol-function fun)
,@(get-elements-by-map ovar-map
new-vals))))

The argument to funcall needs to be quoted:

(setf fnval (eval `(funcall ',(symbol-function fun)
,@(get-elements-by-map ovar-map
new-vals))))

I can't see how this bug caused your problem. The apply version seems all right (no one would
write the eval version in practice, but I can see you're desperate).

What does fn-505 actually do?

-- Drew McDermott

Barry Margolin

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
In article <3981F6A2...@yale.edu>,

Drew McDermott <drew.mc...@yale.edu> wrote:
>The argument to funcall needs to be quoted:
>
>(setf fnval (eval `(funcall ',(symbol-function fun)
> ,@(get-elements-by-map ovar-map
> new-vals))))

Why? In Common Lisp, everything except symbols and lists is
self-evaluating, so they don't need to be quoted.

If GET-ELEMENTS-BY-MAP could return a list containing symbols or lists,
he would need to quote each of its elements, i.e.

,@(mapcar #'(lambda (x) `',x)
(get-elements-by-map ...))

But since it looks like it always returns a list of numbers (at least in
this case, presumably because it returns items from its input list, which
is all numeric) this isn't necessary.

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

Erik Naggum

unread,
Jul 29, 2000, 3:00:00 AM7/29/00
to
* Warren Lucas <wkl...@byu.edu>

| I am experiencing a rather annoying problem while using ACL 5.0.1 for
| NT. It is described below.

Not well enough to help you, since the answer (obviously) does not
lie in what you describe (otherwise you would have found it).

| Any help you can provide would be very much appreciated!

Well, I just wonder why you use symbol-function when both funcall
and apply will do that on their own if given a symbol.

| When I apply the same function to the same list of values by hand, I
| get the correct answer.

Then it is likely that you call the function with different values.
What is the value of new-vals after a call to get-elements-by-map?
Does two invocations of that function return the same value? What
happens if you don't make that call, as it seems to be pointless in
your example, anyway? In essense, does any of these functions
modify any of their arguments? Does fn-505 use a &rest specifier?

#:Erik
--
If this is not what you expected, please alter your expectations.

0 new messages