emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Large numbers of named variables in Babel
@ 2014-08-06 14:27 Brett Witty
  2014-08-06 15:15 ` John Kitchin
  0 siblings, 1 reply; 2+ messages in thread
From: Brett Witty @ 2014-08-06 14:27 UTC (permalink / raw)
  To: Org mailing list

[-- Attachment #1: Type: text/plain, Size: 615 bytes --]

Hi,

I'm trying to write my RPG adventures in org-mode and would like to bring
character sheets into that fold. Is there a way in Babel to have a vast
number of named variables that I can feed into source blocks? Are macros
the way to achieve this?

As an example, I'd like something like a big (hidden) table:
#+NAME: stats
| STR | 13 |
| DEX | 12 |
| CON | 11 |

and then later I can use that like:
#+NAME: AC
#+begin_src python :var dex=table[DEX] :var armour=table[ARMOUR]
return dex + armour
#+end_src

I know I can make explicit cell references, but it'd be neat to just use
keys for values.

Cheers,

BrettW

[-- Attachment #2: Type: text/html, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Large numbers of named variables in Babel
  2014-08-06 14:27 Large numbers of named variables in Babel Brett Witty
@ 2014-08-06 15:15 ` John Kitchin
  0 siblings, 0 replies; 2+ messages in thread
From: John Kitchin @ 2014-08-06 15:15 UTC (permalink / raw)
  To: Brett Witty; +Cc: Org mailing list

Brett Witty <brettwitty@brettwitty.net> writes:

This is close to what you want I think.

#+TBLNAME: stats
| STR | 13 |
| DEX | 12 |
| CON | 11 |


#+BEGIN_SRC python :results value :var data=stats
d = dict(data)
return d['DEX'] + d['CON']
#+END_SRC

#+RESULTS:
: 23


> Hi,
>
> I'm trying to write my RPG adventures in org-mode and would like to
> bring character sheets into that fold. Is there a way in Babel to have
> a vast number of named variables that I can feed into source blocks?
> Are macros the way to achieve this?
>
> As an example, I'd like something like a big (hidden) table:
> #+NAME: stats
> | STR | 13 |
> | DEX | 12 |
> | CON | 11 |
>
> and then later I can use that like:
> #+NAME: AC
> #+begin_src python :var dex=table[DEX] :var armour=table[ARMOUR]
> return dex + armour
> #+end_src
>
> I know I can make explicit cell references, but it'd be neat to just
> use keys for values.
>
> Cheers,
>
> BrettW
>

-- 
-----------------------------------
John Kitchin
Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-08-06 15:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-06 14:27 Large numbers of named variables in Babel Brett Witty
2014-08-06 15:15 ` John Kitchin

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