home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2XLSP1.ZIP / BEEP.LSP < prev    next >
Text File  |  1988-07-19  |  2KB  |  60 lines

  1. ; beep.lsp -- for OS2XLISP
  2. ; Andrew Schulman 25-April-1988
  3.  
  4. ; illustrates:
  5. ;   calling OS/2 functions (DOSBEEP and VIOWRTCHARSTRATT)
  6. ;   named parameters
  7. ;   what happens when you write sample programs at 3am
  8.  
  9. (define dosbeep (getprocaddr doscalls "DOSBEEP"))
  10. (define viowrtcharstratt (getprocaddr viocalls "VIOWRTCHARSTRATT"))
  11.  
  12. (define (dos-beep freq dur)
  13.     (call dosbeep (word freq) (word dur)))
  14.         
  15. (define (vio-wrt msg row col attr)
  16.     (call viowrtcharstratt msg
  17.         (word (length msg)) (makelong row col) (addr (word attr)) (word 0)))
  18.  
  19. ; problem with preceding is that have to remember order:  does frequency
  20. ; come before duration?.  Does col before row, or after?  What about msg?
  21. ; Who the hell can remember!  Would prefer to have named parameters, that can
  22. ; be entered in any arbitrary order (cf. Jon Bentley, "More Programming
  23. ; Pearls," chapter on self-describing data).  Lisp makes this easy with
  24. ; the &key keyword.  Also, the parameters have default values, though these
  25. ; are not always that useful!
  26.  
  27. (define (dos-beep &key (freq 1000) (dur 100))
  28.     (call dosbeep (word freq) (word dur)))
  29.         
  30. (define (vio-wrt &key (msg "I'll drink to that") (row 10) (col 10) (attr 50))
  31.     (call viowrtcharstratt msg
  32.         (word (length msg)) (makelong row col) (addr (word attr)) (word 0)))
  33.  
  34. ; the following three calls are identical (and not just because they're
  35. ; all commented out!)
  36.  
  37. ; (dos-beep :freq 1000 :dur 100)
  38. ; (dos-beep :dur 100 :freq 1000)        ; different order from definition
  39. ; (dos-beep)                            ; use default values
  40.  
  41. ; (cls) is a function defined in the file INIT.LSP
  42. (cls)
  43.  
  44. (vio-wrt :row 3 :col 0 :attr 5
  45.     :msg "This is supposed to sound like a computer in a '50s movie")
  46. (vio-wrt :row 4 :col 0 :attr 5 :msg "Do not fold, spindle, or mutilate!")   
  47.  
  48. (dotimes
  49.     (i 35)
  50.     (define x (random 2000))
  51.     (vio-wrt :msg (format nil "~A" x) :row 10 :col 10 :attr 15)
  52.     (dos-beep :dur 200 :freq x))
  53.         
  54. ; the one problem with these named parameters is that if a function is
  55. ; set up to use them, then you HAVE to use them (unless you go for the
  56. ; defaults)
  57.  
  58. (set-cursor 24 0)
  59.  
  60.