From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gary Oberbrunner Subject: Re: Org-mode as a metalanguage: calling SQL "functions" Date: Mon, 1 Apr 2013 22:54:14 -0400 Message-ID: References: <87vc85raoh.fsf@ericabrahamsen.net> <87y5d1itxx.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e01183b7a48661704d957dab9 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:42654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMrMc-0004Do-MZ for emacs-orgmode@gnu.org; Mon, 01 Apr 2013 22:54:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMrMW-0003Dr-77 for emacs-orgmode@gnu.org; Mon, 01 Apr 2013 22:54:22 -0400 Received: from mail-oa0-f47.google.com ([209.85.219.47]:50528) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMrMV-0003Cp-Vv for emacs-orgmode@gnu.org; Mon, 01 Apr 2013 22:54:16 -0400 Received: by mail-oa0-f47.google.com with SMTP id o17so2527597oag.20 for ; Mon, 01 Apr 2013 19:54:14 -0700 (PDT) In-Reply-To: <87y5d1itxx.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: Eric Abrahamsen , Orgmode Mailing List --089e01183b7a48661704d957dab9 Content-Type: text/plain; charset=ISO-8859-1 Aha -- you have to use the :var syntax on the begin_src line, not the params-in-parens syntax on the name line. Your version works: #+name: example-block #+begin_src sh :var input="" echo "input is $input" #+end_src but this doesn't: #+name: example-block(input="") #+begin_src sh echo "input is $input" #+end_src The doc seems to say it should work the same, in http://orgmode.org/manual/var.html (see "Alternate Argument Syntax"). On Mon, Apr 1, 2013 at 9:45 PM, Eric Schulte wrote: > Eric Abrahamsen writes: > > > Gary Oberbrunner writes: > > > >> It seems like you can define "procedures" in org-mode and call them > >> from elsewhere, with args. > >> But I'm not sure how well-defined that process is; the documentation > >> is not completely perfect yet I think. Here's one thing I'm trying > >> that seems not to work. > >> > >> I define a "procedure" as a named ref called recorddate with two args, > >> ver and order. The idea is I could later call that with different > >> values of those args. > >> > >> #+NAME: recorddate(order="desc") > >> #+BEGIN_SRC sql :exports none :colnames no :results scalar > >> select Event.CreatedAt from Event join MachineInfo as MI on > >> Event.MachineInfoId=MI.Id > >> where Event.CreatedAt is not NULL order by CreatedAt $order limit 1; > >> #+END_SRC sql > >> > >> (BTW, I really like how $ vars are substituted into SQL. Nice.) But > >> when I try to call it like this: > >> > >> * earliest record is call_recorddate(ver="'.'", order="asc") > >> or like this: > >> #+CALL: recorddate(ver="'.'", order="asc") > >> > >> and I try to export as LaTeX (or anything), I get > >> org-babel-ref-resolve: Reference 'recorddate' not found in this buffer > >> > >> Is this supposed to work? > > > > Yes, your example should work. From the "Evaluating code blocks" > section of the Org-mode manual. > > ,---- > | It is also possible to evaluate named code blocks from anywhere in an > | Org mode buffer or an Org mode table. Live code blocks located in the > | current Org mode buffer or in the "Library of Babel" (see *note Library > | of Babel::) can be executed. Named code blocks can be executed with a > | separate '#+CALL:' line or inline within a block of text. > `---- > > There is no need to load code blocks in the same buffer into the library > of babel. > > This example works for me evaluating code blocks in the same buffer > using call lines. > > > > When I export this to e.g., html I get the following. > > > ** ** > Call Example > > echo "input is $input" > > Here's a simple call using a named argument. > > input is foo > > It also works with a positional argument. > > input is bar > > Date: 2013-04-01T19:39-0600 > > Author: > > Org version 7.9.3f with Emacsversion 24 > Validate XHTML 1.0 > > > The call lines are replaced with their results as part of the export > process. > > If the above doesn't work for you, then I imagine something is wrong > with your install. > > -- > Eric Schulte > http://cs.unm.edu/~eschulte > > -- Gary --089e01183b7a48661704d957dab9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Aha -- you have to use the :var syntax on the begin_src li= ne, not the params-in-parens syntax on the name line. =A0Your version works= :

#+name: example-block
#+begin_src sh :v= ar input=3D""
=A0 echo "input is $input"
#+end_src

but this doesn't:

#+name: example-block(input=3D"")
#+begin_= src sh
=A0 echo "input is $input"
#+end_src
The doc seems to say it should work the same, in=A0http://orgmode.org/manual/var.html= =A0(see "Alternate Argument Syntax").



On Mon, Apr 1, 2013 at 9:45 PM, Eric Schulte <sc= hulte.eric@gmail.com> wrote:
Eric Abrahamsen <eric@ericabrahamsen.net> writes= :

> Gary Oberbrunner <garyo@ob= erbrunner.com> writes:
>
>> It seems like you can define "procedures" in org-mode an= d call them
>> from elsewhere, with args.
>> But I'm not sure how well-defined that process is; the documen= tation
>> is not completely perfect yet I think. Here's one thing I'= m trying
>> that seems not to work.
>>
>> I define a "procedure" as a named ref called recorddate = with two args,
>> ver and order. The idea is I could later call that with different<= br> >> values of those args.
>>
>> #+NAME: recorddate(order=3D"desc")
>> #+BEGIN_SRC sql :exports none :colnames no :results scalar
>> select Event.CreatedAt from Event join MachineInfo as MI on
>> Event.MachineInfoId=3DMI.Id
>> where Event.CreatedAt is not NULL order by CreatedAt $order limit = 1;
>> #+END_SRC sql
>>
>> (BTW, I really like how $ vars are substituted into SQL. Nice.) Bu= t
>> when I try to call it like this:
>>
>> * earliest record is call_recorddate(ver=3D"'.'"= , order=3D"asc")
>> or like this:
>> #+CALL: recorddate(ver=3D"'.'", order=3D"as= c")
>>
>> and I try to export as LaTeX (or anything), I get
>> org-babel-ref-resolve: Reference 'recorddate' not found in= this buffer
>>
>> Is this supposed to work?
>

Yes, your example should work. =A0From the "Evaluating code bloc= ks"
section of the Org-mode manual.

,----
| =A0 =A0It is also possible to evaluate named code blocks from anywhere in= an
| Org mode buffer or an Org mode table. =A0Live code blocks located in the<= br> | current Org mode buffer or in the "Library of Babel" (see *note= Library
| of Babel::) can be executed. =A0Named code blocks can be executed with a<= br> | separate '#+CALL:' line or inline within a block of text.
`----

There is no need to load code blocks in the same buffer into the library of babel.

This example works for me evaluating code blocks in the same buffer
using call lines.



When I export this to e.g., html I get the following.


Call Example

echo "input is $input"

Here's a simple call using a named argument.

input is foo

It also works with a positional argument.

input is bar

Date: 2013-04-01T19:39-0600

Author:

Org version 7.9.3f = with Emacs= version 24

V= alidate XHTML 1.0


The call lines are replaced with their results as part of the export
process.

If the above doesn't work for you, then I imagine something is wrong with your install.

--
Eric Schulte
http://cs.unm.edu= /~eschulte




--
Gary
--089e01183b7a48661704d957dab9--