emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <nicholas.dokos@hp.com>
To: charles snyder <clsnyder@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Applying a user-defined function to cols in table
Date: Sat, 13 Sep 2008 00:19:04 -0400	[thread overview]
Message-ID: <15469.1221279544@gamaville.dokosmarshall.org> (raw)
In-Reply-To: Message from "charles snyder" <clsnyder@gmail.com> of "Fri, 12 Sep 2008 20:49:23 CDT." <fa09ca6d0809121849v4ca88751u2dcb370cc968fded@mail.gmail.com>

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

      reply	other threads:[~2008-09-13  4:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-13  1:49 Applying a user-defined function to cols in table charles snyder
2008-09-13  4:19 ` Nick Dokos [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15469.1221279544@gamaville.dokosmarshall.org \
    --to=nicholas.dokos@hp.com \
    --cc=clsnyder@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).