emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [Orgmode] Applying a user-defined function to cols in table


From: Nick Dokos
Subject: Re: [Orgmode] Applying a user-defined function to cols in table
Date: Sat, 13 Sep 2008 00:19:04 -0400

charles snyder <address@hidden> wrote:

> I am trying to apply a function to one column in a table and output the 
> result to another column. The function looks like this:
> 
> (defun yahoo (stock_symbol)
>    (let (url contents fields price-string price)
>      (setf url "http://finance.yahoo.com/d/quotes.csv?s=";)
>      (str+! url stock_symbol)
>      (str+! url "&f=sl1d1t1c1ohgv&e=.csv")
>      (setf contents (http-get url))
>      (setf fields (split-sequence #\, contents))
>      (setf price-string (second fields))
>      (setf price (read-from-string price-string))
>      price))
> 
> This table looks like this:
> 
> |  !   | stockname | symbol | shares | curr_price |
> |  1  |      apple     | aapl   |    800 |            |
> |  2  |    google       | goog  |   2100 |         |
> #+TBLFM: $5= yahoo $3
> 
> (I'm using org 6.06b, gnu emacs 22.2 on a mac.)
> 

Here is a simple example of a user-defined function. I think this proves
it's possible:

| 1 | 3 |
|   | 2 |
#+TBLFM: $2 = foo($1)

(defun calcFunc-foo (x)
   (+ x 2))

See [[info:calc:Defining%20Functions][info:calc:Defining Functions]] for
the details.

IOW, you'll have to rename your function and fix the TBLFM line at the
very least. Whether the function itself works as desired will be left as
an exercise for the interested reader !-)

HTH,
Nick




reply via email to

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