From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Applying a user-defined function to cols in table Date: Sat, 13 Sep 2008 00:19:04 -0400 Message-ID: <15469.1221279544@gamaville.dokosmarshall.org> References: Reply-To: nicholas.dokos@hp.com Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KeMc0-00048I-Vv for emacs-orgmode@gnu.org; Sat, 13 Sep 2008 00:19:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KeMbz-00047e-Tw for emacs-orgmode@gnu.org; Sat, 13 Sep 2008 00:19:56 -0400 Received: from [199.232.76.173] (port=42754 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KeMbz-00047Y-Jy for emacs-orgmode@gnu.org; Sat, 13 Sep 2008 00:19:55 -0400 Received: from qmta07.westchester.pa.mail.comcast.net ([76.96.62.64]:37814) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KeMbz-00054L-ES for emacs-orgmode@gnu.org; Sat, 13 Sep 2008 00:19:55 -0400 In-Reply-To: Message from "charles snyder" of "Fri, 12 Sep 2008 20:49:23 CDT." List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: charles snyder Cc: emacs-orgmode@gnu.org charles snyder 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