* Applying a user-defined function to cols in table
@ 2008-09-13 1:49 charles snyder
2008-09-13 4:19 ` Nick Dokos
0 siblings, 1 reply; 2+ messages in thread
From: charles snyder @ 2008-09-13 1:49 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 943 bytes --]
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
[-- Attachment #1.2: Type: text/html, Size: 1616 bytes --]
[-- Attachment #2: Type: text/plain, Size: 204 bytes --]
_______________________________________________
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Applying a user-defined function to cols in table
2008-09-13 1:49 Applying a user-defined function to cols in table charles snyder
@ 2008-09-13 4:19 ` Nick Dokos
0 siblings, 0 replies; 2+ messages in thread
From: Nick Dokos @ 2008-09-13 4:19 UTC (permalink / raw)
To: charles snyder; +Cc: emacs-orgmode
charles snyder <clsnyder@gmail.com> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-09-13 4:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-13 1:49 Applying a user-defined function to cols in table charles snyder
2008-09-13 4:19 ` Nick Dokos
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.