Entry
LISP: Allegro Franz Lisp: Microsoft: Windows: Button: Simple: Math: Operation: How multiply? [power]
Jan 25th, 2004 14:54
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 25 January 2004 - 09:32 pm --------------------
LISP: Allegro Franz Lisp: Microsoft: Windows: Button: Simple: Math:
Operation: How multiply? [power]
---
Steps: Overview:
1. -Create a new application
1. Run Allegro Lisp
2. -Put a button on the form
1. Click once on the leftmost button on the palette
2. Click once on the form
3. That will place a button on the form
3. -Put some code in the event for this button
1. Double click on the button
2. -click button 'Events'
in the 'Inspect' window
3. -Double click on the 'On click' event line
4. -That will add some default code
--- cut here ---------------------------------------------------------
;; Code for the dialog :form1
(in-package :common-graphics-user)
(defun form1-button4-on-click (dialog widget)
(declare (ignore-if-unused dialog widget))
t)
--- cut here ---------------------------------------------------------
4. -To show the value (so you set 'x=3', then show 'x' on the title
of the button, just add the following lines:
; this is equivalent to 'x=3'
(setq x 3)
; this is equivalent to 'x = x * 4'
(setq x (* x 4))
; first search for the button4 in the existing controls,
; and assign this to a variable
(setq mybutton (find-component :button4 (parent widget)))
; then set its property 'title'
(setf (title mybutton) x)
5. -So all together that gives the following code:
--- cut here ---------------------------------------------------------
;; Code for the dialog :form1
(in-package :common-graphics-user)
(defun form1-button4-on-click (dialog widget)
(declare (ignore-if-unused dialog widget))
; this is equivalent to 'x=3'
(setq x 3)
; this is equivalent to 'x = x * 4'
(setq x (* x 4))
; first search for the button4 in the existing controls,
; and assign this to a variable
(setq mybutton (find-component :button4 (parent widget)))
; then set its property 'title'
(setf (title mybutton) x)
t)
--- cut here ---------------------------------------------------------
6. -Run this code
1. Click on the '>' in the menu
2. Ignore the possible warning, by clicking he
3. Then click on the button
1. It will change its title to 4 * 3, or thus '12'
+----------------------+
| |
| 12 |
| |
+----------------------+
---
---
Note similarly you can use:
---
; addition 'x = x + 4'
( setq x ( + x 4 ) )
---
; subtraction 'x = x - 4'
( setq x ( - x 4 ) )
---
; division, 'x = x / 4'
( setq x ( / x 4 ) )
---
; power: 'x = x ^ 4'
( setq x ( expt x 4 ) )
; does not work:
; (setq x ( ^ x 4 ) )
; does not work:
; (setq x ( ** x 4 ) )
; does not work:
;(setq x ( power x 4 ) )
---
; power of e: 'x = e^4'
( setq x ( exp 4 ) )
---
; trigonometry: 'x = sin( x )'
( setq x ( sin x ) )
; trigonometry: 'x = cos( x )'
( setq x ( cos x ) )
; trigonometry: 'x = tan( x )'
( setq x ( tan x ) )
---
---
; inequality: smaller: 'x < 4'
( < x 4 )
; inequality: greater: 'x > 4', which shows 'T' (=TRUE) or 'F'
(=FALSE)
( > x 4 )
; inequality: smaller or equal: 'x <= 4'
( <= x 4 )
; inequality: greater or equal: 'x >= 4'
( <= x 4 )
; inequality: not: not 4
( not 4 )
; inequality: not: 'x <> 4'
( not ( = x 4 ) )
; does not work
; ( <> x 4 )
; does not work
; ( != x 4 )
; does not work
; ( ! x 4 )
; does not work
; ( unequal x 4 )
---
---
Note:
And of course you can use e.g. floating point numbers also.
; multiply: x = 2 . 3.14, which gives 6.28
( setq x ( * 3.14 2 ) )
---
---
Note:
LISP uses a 'prefix' notation, that is first you write the operator,
then
the one, two, or more operands.
e.g.
( + 3 4 )
while you yourself would write usually (which is 'infix' notation),
so the operator ('+') comes in the middle:
3 + 4
---
---
Internet: see also:
---
ANSI Common Lisp
http://www.franz.com/support/documentation/6.2/ansicl/dictentr/expexpt.
htm
----------------------------------------------------------------------