# Using elisp code with table formula problem

I've got these working

``````#+NAME: expogrowth1
| 1 |   2 |
| 2 |   4 |
| 3 |   8 |
| 4 |  16 |
| 5 |  32 |
| 6 |  64 |
| 7 | 128 |
| 8 | 256 |
#+TBLFM: @2\$2..@\$2> = @-1\$2*2
``````

and

``````#+NAME: expogrowth2
| 1 | 2 | 3 |  4 |  5 |  6 |   7 |
| 2 | 4 | 8 | 16 | 32 | 64 | 128 |
#+TBLFM: @2\$2..@2\$> = @2\$-1*2
``````

but this won't work

``````#+NAME: expogrowth4
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|   |   |   |   |   |   |   |
#+TBLFM: @2\$1..@2\$> = '(mapcar (lambda (arg) (expt arg 2)) (list @1\$1..@1\$>))
``````

This is not exactly the same, but eventually I'd like to have a real exponential growth table working with the elisp version. I'm following this, and the code from it works, but my own code to simply square the numbers from the top row won't work, and I can't see why.

You are overcomplicating things: yes, there is a string conversion problem as @db48x has pointed out in his answer, but assuming that the last table should produce the same results as the other two, the formula is much simpler:

``````#+TBLFM: @2\$1..@2\$> = '(expt 2 (string-to-number @1))
``````

In words: for every cell in the second row, get the corresponding cell in the first row (a string), convert the string to a number and then raise 2 to that exponent.

What your formula would do (after fixing the string conversions) would be to assign a list of values to each cell in the LHS range.

Use the formula debugger; you can turn it on with `C-c {`. You’ll see something like this:

``````Substitution history of formula
Orig:   '(mapcar (lambda (arg) (expt arg 2)) (list @1\$1..@1\$7))
\$xyz->  '(mapcar (lambda (arg) (expt arg 2)) (list @1\$1..@1\$7))
@r\$c->  '(mapcar (lambda (arg) (expt arg 2)) (list #("1" 0 1 (fontified t face org-table)) #("2" 0 1 (fontified t face org-table)) #("3" 0 1 (fontified t face org-table)) #("4" 0 1 (fontified t face org-table)) #("5" 0 1 (fontified t face org-table)) #("6" 0 1 (fontified t face org-table)) #("7" 0 1 (fontified t face org-table))))
\$1->    '(mapcar (lambda (arg) (expt arg 2)) (list #("1" 0 1 (fontified t face org-table)) #("2" 0 1 (fontified t face org-table)) #("3" 0 1 (fontified t face org-table)) #("4" 0 1 (fontified t face org-table)) #("5" 0 1 (fontified t face org-table)) #("6" 0 1 (fontified t face org-table)) #("7" 0 1 (fontified t face org-table))))
Result: #ERROR
Format: NONE
Final:  #ERROR
``````

You can see that the arguments are substituted in as strings, and fontified strings at that. You’ll need to convert them to numbers before you can call `expt` on them. The document you’re reading gives several different ways to do that; which one is best for you depends on what you’re trying to do.