From mboxrd@z Thu Jan 1 00:00:00 1970 From: "charles snyder" Subject: Applying a user-defined function to cols in table Date: Fri, 12 Sep 2008 20:49:23 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0965955336==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KeKGN-0000er-0R for emacs-orgmode@gnu.org; Fri, 12 Sep 2008 21:49:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KeKGL-0000cg-Jh for emacs-orgmode@gnu.org; Fri, 12 Sep 2008 21:49:26 -0400 Received: from [199.232.76.173] (port=39123 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KeKGL-0000cd-GI for emacs-orgmode@gnu.org; Fri, 12 Sep 2008 21:49:25 -0400 Received: from rv-out-0708.google.com ([209.85.198.240]:54014) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KeKGL-0002DC-5z for emacs-orgmode@gnu.org; Fri, 12 Sep 2008 21:49:25 -0400 Received: by rv-out-0708.google.com with SMTP id k29so1181513rvb.6 for ; Fri, 12 Sep 2008 18:49:23 -0700 (PDT) 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: emacs-orgmode@gnu.org --===============0965955336== Content-Type: multipart/alternative; boundary="----=_Part_51720_20075441.1221270563091" ------=_Part_51720_20075441.1221270563091 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi 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.) I have tried some other variants without success. Is this even possible? Thanks! -- Charles L. Snyder, MD Professor of Surgery www.clsnyder.com ------=_Part_51720_20075441.1221270563091 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Hi

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.)


I have tried some other variants without success.
Is this even possible?

Thanks!

--
Charles L. Snyder, MD
Professor of Surgery
www.clsnyder.com
------=_Part_51720_20075441.1221270563091-- --===============0965955336== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --===============0965955336==-- 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