 ; Spon - a function which creates other functions.
 ; Copyright 1995 by Rocket Software
 ; The lament of R&D: "Now all we need is a use."

 ; Spawn - a simpler example.
 (DEFUN C:SPAWN (/ fnam)
  (setq fnam (getstring "Function name: "))
  (setq bb (list DEFUN (read (strcat "C:" fnam)) ()
                      '(command "redraw")
                      '(princ)))
  (eval bb)
 (princ))

 (DEFUN C:SPON (/ fnam)
  (setq *error* ())
  (setq fnum (getint "Start number: "))
  (setq numm (getint "Number of cycles: "))
  (repeat numm
          (setq fnum (1+ fnum))
          (eval (list 'DEFUN
                      (read (strcat "C:CR" (itoa fnum)))
                     '(/ pa rad rad2 angg colo)
                     '(setq blip (getvar "blipmode"))
                     '(setvar "blipmode" 0)
                     '(setq pa (getpoint "Point: "))
                     '(setq colo -1)
                     '(setq rad (/ (getvar "viewsize") 10))
                     '(setq rad2 (/ rad 2))
                     '(setq angg 0)
 ; Note: quoting a line is simple and adequate if it is static.
 ; If the parent function is sending variables to the spawned function then
 ; the (read (strcat etc.)) form must be used.
 ; The parentheses in sublists which are to be Read must balance or the read
 ; function will crash.  The Quote function is more forgiving - it covers
 ; everything until the parentheses balance.
                      (read (strcat "(setq incr (/ pi (/ "
                                     (rtos (float fnum) 2 1) " 2)))"))
                      (read (strcat "(repeat " (itoa fnum)
                                    "(grdraw (polar pa angg rad2)"
                                    "(polar pa angg rad) colo)"
                                    "(setq angg (+ angg incr)))"))
                     '(setvar "blipmode" blip)
                     '(princ))))
 (princ))