home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / lisp / 2080 < prev    next >
Encoding:
Text File  |  1992-07-22  |  2.1 KB  |  50 lines

  1. Path: sparky!uunet!mcsun!uknet!edcastle!chemeng.ed.ac.uk!stow!haitham
  2. From: haitham@Chemeng.Ed.Ac.Uk (Haitham Lababidi)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: converting from strings to ___
  5. Message-ID: <1992Jul23.090403.23596@chemeng.ed.ac.uk>
  6. Date: 23 Jul 92 09:04:03 GMT
  7. References: <1992Jul22.194639.10131@cs.brown.edu>
  8. Sender: news@chemeng.ed.ac.uk
  9. Reply-To: haitham@Chemeng.Ed.Ac.Uk
  10. Organization: Edinburgh University Chemical Engineering Department.
  11. Lines: 36
  12. Originator: haitham@stow
  13.  
  14. In article 10131@cs.brown.edu, map@cs.brown.edu (Mike Perkowitz) writes:
  15. >
  16. >i'm working on a system where i'm getting user input through Motif widgets
  17. >(using CLM). in one part, the user can specify values for certain parameters
  18. >through a text widget. the problem is that the value held by the text widget
  19. >will always be a string. i need to be able to treat that string as a number or
  20. >even as any arbitrary value (t/nil, for example). what it really seems like i
  21. >need to be able to do is just "remove the quotes" from the string and turn it
  22. >into a symbol or something. does anybody have any ideas? is this doable? to
  23. >what extent? any assistance would be greatly appreciated...
  24. >
  25. >thanks,
  26.  
  27. Try the following function:
  28.  
  29. (defun my-read-string (string)
  30.   (let (val errorp error-string)
  31.     (handler-case
  32.      (setf val (read-from-string string nil :empty-string))
  33.      (condition (error-condition)
  34.                 (setf error-string error-condition
  35.                       errorp :read-error val nil)))
  36.      (when (eq val :empty-string) (setf val nil errorp :empty-string))
  37.      (when (and errorp (eq errorp :read-error))
  38.        (format t "Error: read-from-string:~%~%~A" error-string))
  39.      (values val errorp error-string)))
  40.  
  41. You can then easily direct the error (if any) to a "notice-prompt" originated from
  42. the widget you are reading from.
  43.  
  44.  
  45. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  46.     Dr. Haitham Lababidi                       Tel  +44 31 650 4862
  47.     Department of Chemical Engineering         Email haitham@uk.ac.ed
  48.     Edinburgh University                                              
  49. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  50.