help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is the type of user input?


From: Kevin Rodgers
Subject: Re: What is the type of user input?
Date: Wed, 27 Oct 2004 14:36:24 -0600
User-agent: Mozilla Thunderbird 0.8 (X11/20040916)

Hattuari wrote:
> The following code demonstrates the problem I'm having:
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;; create a property list and use it to map long strings
> ;; to short strings
> (setq paste-gl-type-map ())
>
> (setq paste-gl-type-map (plist-put paste-gl-type-map 'GLbyte     'b))
> (setq paste-gl-type-map (plist-put paste-gl-type-map 'GLshort    's))
> (setq paste-gl-type-map (plist-put paste-gl-type-map 'GLint      'i))
> ;;...
>
> (plist-get paste-gl-type-map 'GLbyte) ;; test function call
>
>
> (defun paste-gl-array(gl-type gl-components gl-vector)
>   "Map OpenGL types to corresponding sufixes.(GL\'type\' )"
>   (interactive "sType: \nnNumber 1 to 4: \nsVector: ")
>   (message " gl-type=%s, gl-components=%d, gl-vector=%s , suffix=%s"
>            gl-type gl-components gl-vector
>            (plist-get paste-gl-type-map gl-type))
>
>   )
> ;; end of application code
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> When I use the code by first `M-x eval-buffer' and then `M-x
> paste-gl-array<RET>GLbyte<RET>4<RET>v<RET>', the result is a message
> displayed in the echo area as follows:
>
> gl-type=GLbyte, gl-components=4, gl-vector=v , suffix=nil
>
> Notice that gl-type is displayed with the value I entered in the minibuffer
> when it is passed to the first %s in the message string.  It seems not to
> be treated as a string when passed to plist-get, hence the 'suffix=nil'.

gl-type is a string.  Since the paste-gl-type-map property list is keyed
by symbols, plist-get returns nil.  The %s message specifier can be
applied to any Lisp object, and symbols and strings are formatted the
same.

The solution is to either (1) read gl-type with the %S code or (2) call
plist-get with (intern gl-type).

> OTOH, when I evaluate this expression in an emacs-lisp buffer
> (paste-gl-array 'GLbyte 4 'v), I see the following in the echo area:
>
> gl-type=GLbyte, gl-components=4, gl-vector=v , suffix=b
>
> That is the desired result.  Why is this not the result of calling the
> function as an interactive command as described above?
>
> I will continue to look for an answer in the documentation, but any help
> from someone who knows the answer would be appreciated.

It's not that hard to find:

`C-h f message' has a link to the doc string for `format', which has a
link to the doc string for `princ' in its description of %s:

,----[ C-h f princ RET ]
| princ is a built-in function.
| (princ OBJECT &optional PRINTCHARFUN)
|
| Output the printed representation of OBJECT, any Lisp object.
| No quoting characters are used; no delimiters are printed around
| the contents of strings.
|
| OBJECT is any of the Lisp data types: a number, a string, a symbol,
| a list, a buffer, a window, a frame, etc.
|
| A printed representation of an object is text which describes that object.
...`----

--
Kevin Rodgers


reply via email to

[Prev in Thread] Current Thread [Next in Thread]