PDA

View Full Version : :value-type for formula expression ?


Lim Chee Beng
08-26-2004, 06:49 PM
The following codes run well in defun format in OSD Modeling.

(in-package :training)
(use-package :OLI)

(defun fp (fcn)
(setf x 0)
(setf y -5)
(loop while (<= y 5) do
(setf z (apply fcn (list x y)))
(display (list x y z))
(setf y (+ y 1))
)

)

If I key in the the following in the command line, Modeling is able to display the list of (x y z) according to the formula expression.

(training::fp '(lambda (x y) (exp (- (+ (* x x) (* y y))))))


Appreciate if anybody can suggest how to use "sd-defdialog" to replace the "defun" codes. What is ":value-type" in this case? Or, need to change "apply" statement ?

(in-package :training)
(use-package :OLI)

(sd-defdialog 'fp
:dialog-title "Function plot"
:variables
'(
(fcn :value-type :?????
:title "Function f(x,y)"
:initial-value '(lambda (x y) (exp (- (+ (* x x) (* y y)))))
)
)
(setf x 0)
(setf y -5)
(loop while (<= y 5) do
(setf z (apply fcn (list x y)))
(display (list x y z))
(setf y (+ y 1))
)
)

Thom Ivancso
08-28-2004, 05:20 AM
Hello Lim,

Not sure if this is the answer you are looking for or not. This is the way I would try to kick the routine off as long as you were not trying to add different values for (x,y). If those need to have different values then more code would need to be written to handle that.


(in-package :training)
(use-package :oli)

(sd-defdialog 'function-plot
:dialog-title "Function plot"
:toolbox-button t
:variables
'(
(FCN :toggle-type :wide-toggle
:title "Function f(x,y)"
:push-action (sd-call-cmds (fp '(lambda (x y) (exp (- (+ (* x x) (* y y)))))))
)
)
)

(defun fp (fcn)
(setf x 0)
(setf y -5)
(loop while (<= y 5) do
(setf z (apply fcn (list x y)))
(display (list x y z))
(setf y (+ y 1))
)

)


Hope this helps
Cheers
Thom

Lim Chee Beng
08-29-2004, 05:42 PM
Hi, Thom.
Sorry that I didn't explain correctly.
I wish the sd-defdialog interface will have the flexibility for user to enter various different functions like the original (defun fp (fcn) .... ) . Hope this is clear enough. :o
Is that possible?

Thx.

Wolfgang
09-26-2004, 06:39 AM
so.. you would like to enter the function itself in the dialog and then call it in the ok-action of the dialog, right?

I think you have to use something similiar to:
(fcn :value-type :string
:initial-value "(lambda (x y) (exp (- (+ (* x x) (* y y)))))"
....
(setf z (apply (read-from-string fcn) (list x y)))


put your function into a string and read out the string. Of course you should enter a valid lisp form as string. A good check-function might be useful.

the out put I got is:
(0 -5 1.388794S-11)
(0 -4 1.125352S-7)
(0 -3 1.234098S-4)
(0 -2 0.01831564S0)
(0 -1 0.3678795S0)
(0 0 1.0S0)
(0 1 0.3678795S0)
(0 2 0.01831564S0)
(0 3 1.234098S-4)
(0 4 1.125352S-7)
(0 5 1.388794S-11)

is this right?

Lim Chee Beng
09-26-2004, 04:30 PM
Yes, it works excellent with initial value. However, other function in string (eg. "(lambda (x y) (cos (sqrt (+ (* x x 2) (* y y)))))") that user enter in dialog box is invalid.

I just found that :value-type :list works fine.

(fcn :value-type :list
:initial-value '(lambda (x y) (exp (- (+ (* x x) (* y y)))))
....
(setf z (apply fcn (list x y)))

When I define :value-type :list , user is not allowed to key in new function/list directly in dialog box, that's why I thought it is wrong. But, I found that user has to enter function/list at user input line instead of dialog box :o , eg. '(lambda (x y) (cos (sqrt (+ (* x x 2) (* y y))))). It seems to work now for any function user enter.
Thx for help.

Wolfgang
10-06-2004, 11:41 AM
Hi,

also other functions are working fine for me.

Here's the code I'm using.

Lim Chee Beng
10-06-2004, 05:15 PM
Yes, this is great and convenient to input with ":value-type :string" and "sd-show-general-text-editor"!
However, the general text editor cannot validate input string like LIST input, because LISP expects any string. We probably need additional validation of function in string input.
On the other hand, LIST input at user input line is rather tedious. But Modeling LISP will validate user input function before accepting.
Thx.

Wolfgang
10-09-2004, 03:37 AM
string

as I already said

Of course you should enter a valid lisp form as string. A good check-function might be useful.

so just checking number of opening and closing round brackets would help a lot. This can be done in the check function.

I think using the general text editor is the best way (instead of command line and type list)

You can also try to work with a combination of both. Getting the formula as a string using :string and pushing the result into a variable of type :list.

Lim Chee Beng
10-11-2004, 01:53 AM
100% agree, the general text editor is the best way.
BTW, does anybody want to offer a good check-function for LISP function validation? :D
Thx a lot, Wolfgang.