[tempo] Convert variable from string to number

  • Follow


I'd like to convert (the value of) a variable inside a tempo template from
a string to a number. This doesn't work:

(tempo-define-template "whatsis"
'("Tempo template to attempt variable conversion ..." 'n
    (P "Enter the number: " whatever NOINSERT)
    "The number is "
    (tempo-lookup-named 'whatever)
    "." 'n
    "whatever is "
    (if (stringp (tempo-lookup-named 'whatever)) "" "not ")
    "a string." 'n
    "Next, try to convert the string to a number. Here goes: "
    (string-to-number (tempo-lookup-named 'whatever))
    "." 'n))

This gets as far as "Here goes:", then I get

    Lisp nesting exceeds `max-lisp-eval-depth'

Eventually, I want to be able to do (e.g.) arithmetic with the values I've
entered at prompts (as opposed to simply inserting the strings). (For
example, think of a template where you enter two numbers, and it later
prints the sum.)

I can do append and concat to (tempo-lookup-named 'whatever), but not
vconcat. I can (setq foo (tempo-lookup-named 'whatever)), but then I can't
do string-to-number to foo. Looks like there's something fundamental here
I'm not understanding. What is it?

(This is emacs 22.1 (Windows), if it matters.)

Bruce Ikenaga

0
Reply Bruce 5/9/2009 7:05:56 PM

Hello,

Bruce Ikenaga <bikenaga@bellatlantic.net> writes:

> I'd like to convert (the value of) a variable inside a tempo template from
> a string to a number. This doesn't work:
> 
> (tempo-define-template "whatsis"
> '("Tempo template to attempt variable conversion ..." 'n
[...]
>     (string-to-number (tempo-lookup-named 'whatever))
>     "." 'n))

I have not a Emacs here for testing the above, but try this:

(tempo-define-template "whatsis"
'("number 5" 'n
  5))

Documentation of tempo-define-template:
,----
| The elements in ELEMENTS can be of several types:
| 
|  - A string. It is sent to the hooks in `tempo-insert-string-functions',
|    and the result is inserted.
[...]
|  - Anything else. It is evaluated and the result is parsed again.
`----

I think for numbers the last rule matches: Number is evualuted, the
result is evualuted again...

Maybe it helps to convert the numbers back to strings:

(tempo-define-template "whatsis"
'("string 5" 'n
  (number-to-string (+ 2 3))))

Greetings from Hamburg
Sebastian Waschik
0
Reply Sebastian 5/10/2009 4:33:03 PM


1 Replies
397 Views

(page loaded in 0.085 seconds)

Similiar Articles:













7/23/2012 10:57:57 AM


Reply: