Path: utzoo!attcan!uunet!samsung!zaphod.mps.ohio-state.edu!usc!bbn!jr@bbn.com From: jr@bbn.com (John Robinson) Newsgroups: comp.emacs Subject: Re: Need read-number function Message-ID: <51906@bbn.COM> Date: 8 Feb 90 15:41:55 GMT References: <4300068@m.cs.uiuc.edu> <13690@phoenix.Princeton.EDU> Sender: news@bbn.COM Reply-To: jr@bbn.com (John Robinson) Organization: BBN Systems and Technologies Corporation, Cambridge MA Lines: 41 In-reply-to: eliot@phoenix.Princeton.EDU (Eliot Handelman) In article <4300068@m.cs.uiuc.edu>, reingold@m.cs writes: > >I need a function read-number that would behave like (interactive "n"); >that is, it would keep trying until a numeric value was typed. In article <1990Feb8.132524.1694@talos.uu.net>, kjones@talos (Kyle Jones) writes: >Yah, I had to code this one myself. I don't know if a function like >this should be standard in the distribution or not. Common Lisp's >elephantiasis is largely due to adopting functions from everyone's >toolbox. [defun omited]. It occurred to me that you could generalize Kyle's function into somthing like: (read-thing prompt checker-function &optional initial-contents) which asks for a lisp object until it gets one with the right type, as passed by the checker-function. Maybe ought to be a macro, or should accept symbols like 'integer, 'string instead of a function name and dispatch on them. In article <13690@phoenix.Princeton.EDU>, eliot@phoenix (Eliot Handelman) writes: >How's about this: > >(defun read-number (number) > (interactive "nNumber: ") > number) Yeah, my initial reaction too. This requires the additional observation that, to call it from inside lisp code, you need to say: (call-interactively 'read-number) ... and there is no easy way to pass it a prompt at run time. For that, you would probably want to replace the defined function in the call-interactively with a lambda-expression, but I'm not sure it is possible to get the (interactive) part right if you do. Or (ugh) evaluate the defun inside the caller... -- /jr, nee John Robinson Life did not take over the globe by combat, jr@bbn.com or bbn!jr but by networking -- Lynn Margulis