all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* babel, header arguments.
@ 2014-11-18 18:44 jenia.ivlev
  2014-11-20  9:36 ` Sebastien Vauban
  0 siblings, 1 reply; 8+ messages in thread
From: jenia.ivlev @ 2014-11-18 18:44 UTC (permalink / raw)
  To: emacs-orgmode

Hello. I want to go through the book little schemer and take notes
interlaced with the code from the book. For this I want to use babel.

So lets say there's this function:

    #+name: my-plus
    #+begin_src scheme
        (define my-plus
          (lambda (x y) (+ x y)))
    #+end_src

And i want to call it from another source block, like so:

    #+tblname: addition
    | sum    |
    |--------|
    | #ERROR |
    #+TBLFM: @2$1='(org-sbe "my-plus" (33 22))

As you can see, I get an error. How do I write these "header-arguments"
(i think they are called) to achieve calling one src-block from another.

Also, second scenario, can I somehow call my-plus from a source-block as
so:

     #+begin_src scheme
         (my-plus 3 4)
     #+end_src


Thanks very much for your help and kind concern.

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

* Re: babel, header arguments.
  2014-11-18 18:44 babel, header arguments jenia.ivlev
@ 2014-11-20  9:36 ` Sebastien Vauban
  2014-11-21 19:35   ` jenia.ivlev
  0 siblings, 1 reply; 8+ messages in thread
From: Sebastien Vauban @ 2014-11-20  9:36 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

jenia.ivlev wrote:
> So lets say there's this function:
>
>     #+name: my-plus
>     #+begin_src scheme
>         (define my-plus
>           (lambda (x y) (+ x y)))
>     #+end_src
>
> And i want to call it from another source block, like so:
>
>     #+tblname: addition
>     | sum    |
>     |--------|
>     | #ERROR |
>     #+TBLFM: @2$1='(org-sbe "my-plus" (33 22))
>
> As you can see, I get an error. How do I write these "header-arguments"
> (i think they are called) to achieve calling one src-block from another.

This should do it (untested):

(org-sbe "my-plus" (x 33) (y 22))

> Also, second scenario, can I somehow call my-plus from a source-block as
> so:
>
>      #+begin_src scheme
>          (my-plus 3 4)
>      #+end_src

I think you must also call `org-sbe'.

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: babel, header arguments.
  2014-11-20  9:36 ` Sebastien Vauban
@ 2014-11-21 19:35   ` jenia.ivlev
  2014-11-21 19:49     ` Thomas S. Dye
  0 siblings, 1 reply; 8+ messages in thread
From: jenia.ivlev @ 2014-11-21 19:35 UTC (permalink / raw)
  To: emacs-orgmode

Sebastien Vauban <sva-news@mygooglest.com>
writes:

> jenia.ivlev wrote:
>> So lets say there's this function:
>>
>>     #+name: my-plus
>>     #+begin_src scheme
>>         (define my-plus
>>           (lambda (x y) (+ x y)))
>>     #+end_src
>>
>> And i want to call it from another source block, like so:
>>
>>     #+tblname: addition
>>     | sum    |
>>     |--------|
>>     | #ERROR |
>>     #+TBLFM: @2$1='(org-sbe "my-plus" (33 22))
>>
>> As you can see, I get an error. How do I write these "header-arguments"
>> (i think they are called) to achieve calling one src-block from another.
>
> This should do it (untested):
>
> (org-sbe "my-plus" (x 33) (y 22))
>
>> Also, second scenario, can I somehow call my-plus from a source-block as
>> so:
>>
>>      #+begin_src scheme
>>          (my-plus 3 4)
>>      #+end_src
>
> I think you must also call `org-sbe'.
>
> Best regards,
>   Seb

Thanks a lot Seb. It worked perfectly for the table.
For the "second scenario" I don't understand how to import the results
of my-plus function. The only thing I can think of is something like 
this (it doesnt work by the way):

    #+begin_src scheme
        (+ z 1)
    #+end_src
    #+ z='(org-sbe "my-plus" (x 33) (y 22))

Also, what if I want to import the actual function defintion into another src
block:

    #+begin_src scheme
        (+ (my-plus 3 4) 1)
    #+end_src
    something here that import the previous function definitions

Is that possible?




    

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

* Re: babel, header arguments.
  2014-11-21 19:35   ` jenia.ivlev
@ 2014-11-21 19:49     ` Thomas S. Dye
  2014-11-21 20:09       ` jenia.ivlev
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas S. Dye @ 2014-11-21 19:49 UTC (permalink / raw)
  To: jenia.ivlev; +Cc: emacs-orgmode

Aloha,

jenia.ivlev@gmail.com (jenia.ivlev) writes:

> Also, what if I want to import the actual function defintion into another src
> block:
>
>     #+begin_src scheme
>         (+ (my-plus 3 4) 1)
>     #+end_src
>     something here that import the previous function definitions
>
> Is that possible?

Yes, see section 14.10 Noweb reference syntax in the manual.

You'll have something that looks like this:

#+header: :noweb yes
#+begin_src scheme
  <<previous-function-definition>>
  (+ (previous-function 3 4) 1)
#+end_src

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: babel, header arguments.
  2014-11-21 19:49     ` Thomas S. Dye
@ 2014-11-21 20:09       ` jenia.ivlev
  2014-11-21 20:32         ` jenia.ivlev
  2014-11-21 20:36         ` Thomas S. Dye
  0 siblings, 2 replies; 8+ messages in thread
From: jenia.ivlev @ 2014-11-21 20:09 UTC (permalink / raw)
  To: emacs-orgmode

tsd@tsdye.com (Thomas S. Dye) writes:

> Aloha,
>
> jenia.ivlev@gmail.com (jenia.ivlev) writes:
>
>> Also, what if I want to import the actual function defintion into
>> another src block:
>>
>>     #+begin_src scheme
>>         (+ (my-plus 3 4) 1)
>>     #+end_src
>>     something here that import the previous function definitions
>>
>> Is that possible?
>
> Yes, see section 14.10 Noweb reference syntax in the manual.
>
> You'll have something that looks like this:
>
> #+header: :noweb yes
> #+begin_src scheme
>   <<previous-function-definition>>
>   (+ (previous-function 3 4) 1)
> #+end_src
>
> hth,
> Tom

What do you mean? <<previous-function-definition>> should be replaced
with the actual function definition? But I use babel-mode so that I can
interlace code in a natural language document. I want these src blocks
to be separate.

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

* Re: babel, header arguments.
  2014-11-21 20:09       ` jenia.ivlev
@ 2014-11-21 20:32         ` jenia.ivlev
  2014-11-21 20:36         ` Thomas S. Dye
  1 sibling, 0 replies; 8+ messages in thread
From: jenia.ivlev @ 2014-11-21 20:32 UTC (permalink / raw)
  To: emacs-orgmode

jenia.ivlev@gmail.com (jenia.ivlev) writes:

> tsd@tsdye.com (Thomas S. Dye) writes:
>
>> Aloha,
>>
>> jenia.ivlev@gmail.com (jenia.ivlev) writes:
>>
>>> Also, what if I want to import the actual function defintion into
>>> another src block:
>>>
>>>     #+begin_src scheme
>>>         (+ (my-plus 3 4) 1)
>>>     #+end_src
>>>     something here that import the previous function definitions
>>>
>>> Is that possible?
>>
>> Yes, see section 14.10 Noweb reference syntax in the manual.
>>
>> You'll have something that looks like this:
>>
>> #+header: :noweb yes
>> #+begin_src scheme
>>   <<previous-function-definition>>
>>   (+ (previous-function 3 4) 1)
>> #+end_src
>>
>> hth,
>> Tom
>
> What do you mean? <<previous-function-definition>> should be replaced
> with the actual function definition? But I use babel-mode so that I can
> interlace code in a natural language document. I want these src blocks
> to be separate.
>
>
>


Tom, thanks so so much.
If someone is interested: 

    #+name: my-plus
    #+begin_src scheme :noweb-ref my-plus
    (define my-plus
      (lambda (x y) (+ x y)))
    (my-plus 3 3)
    #+end_src
    
    #+RESULTS: my-plus
    : 6
    
    
    #+name: my-plus2
    #+header: :noweb yes 
    #+begin_src scheme
    <<my-plus>>
    (define my-plus2
      (lambda () (+ (my-plus 3 4) 1)))
    (my-plus2)
    #+end_src

    #+RESULTS: my-plus2
    : 8

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

* Re: babel, header arguments.
  2014-11-21 20:09       ` jenia.ivlev
  2014-11-21 20:32         ` jenia.ivlev
@ 2014-11-21 20:36         ` Thomas S. Dye
  2014-11-21 20:55           ` jenia.ivlev
  1 sibling, 1 reply; 8+ messages in thread
From: Thomas S. Dye @ 2014-11-21 20:36 UTC (permalink / raw)
  To: jenia.ivlev; +Cc: emacs-orgmode

jenia.ivlev@gmail.com (jenia.ivlev) writes:

> tsd@tsdye.com (Thomas S. Dye) writes:
>
>> Aloha,
>>
>> jenia.ivlev@gmail.com (jenia.ivlev) writes:
>>
>>> Also, what if I want to import the actual function defintion into
>>> another src block:
>>>
>>>     #+begin_src scheme
>>>         (+ (my-plus 3 4) 1)
>>>     #+end_src
>>>     something here that import the previous function definitions
>>>
>>> Is that possible?
>>
>> Yes, see section 14.10 Noweb reference syntax in the manual.
>>
>> You'll have something that looks like this:
>>
>> #+header: :noweb yes
>> #+begin_src scheme
>>   <<previous-function-definition>>
>>   (+ (previous-function 3 4) 1)
>> #+end_src
>>
>> hth,
>> Tom
>
> What do you mean? <<previous-function-definition>> should be replaced
> with the actual function definition? But I use babel-mode so that I can
> interlace code in a natural language document. I want these src blocks
> to be separate.
>
>

Sorry, it refers to the name of the source code block.

,-------------------------------------------------------------------------
| The “noweb” (see <http://www.cs.tufts.edu/~nr/noweb/>) Literate         
| Programming system allows named blocks of code to be referenced by using
| the familiar Noweb syntax:                                              
|                                                                         
|      <<code-block-name>>                                                
`-------------------------------------------------------------------------

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: babel, header arguments.
  2014-11-21 20:36         ` Thomas S. Dye
@ 2014-11-21 20:55           ` jenia.ivlev
  0 siblings, 0 replies; 8+ messages in thread
From: jenia.ivlev @ 2014-11-21 20:55 UTC (permalink / raw)
  To: emacs-orgmode

tsd@tsdye.com (Thomas S. Dye) writes:

> jenia.ivlev@gmail.com (jenia.ivlev) writes:
>
>> tsd@tsdye.com (Thomas S. Dye) writes:
>>
>>> Aloha,
>>>
>>> jenia.ivlev@gmail.com (jenia.ivlev) writes:
>>>
>>>> Also, what if I want to import the actual function defintion into
>>>> another src block:
>>>>
>>>>     #+begin_src scheme
>>>>         (+ (my-plus 3 4) 1)
>>>>     #+end_src
>>>>     something here that import the previous function definitions
>>>>
>>>> Is that possible?
>>>
>>> Yes, see section 14.10 Noweb reference syntax in the manual.
>>>
>>> You'll have something that looks like this:
>>>
>>> #+header: :noweb yes
>>> #+begin_src scheme
>>>   <<previous-function-definition>>
>>>   (+ (previous-function 3 4) 1)
>>> #+end_src
>>>
>>> hth,
>>> Tom
>>
>> What do you mean? <<previous-function-definition>> should be replaced
>> with the actual function definition? But I use babel-mode so that I can
>> interlace code in a natural language document. I want these src blocks
>> to be separate.
>>
>>
>
> Sorry, it refers to the name of the source code block.
>
> ,-------------------------------------------------------------------------
> | The “noweb” (see <http://www.cs.tufts.edu/~nr/noweb/>) Literate         
> | Programming system allows named blocks of code to be referenced by using
> | the familiar Noweb syntax:                                              
> |                                                                         
> |      <<code-block-name>>                                                
> `-------------------------------------------------------------------------
>
> hth,
> Tom


I have one last quick question, I have an exmaple here with no-web that
I think should work but doesnt. I wonder why:

    #+BEGIN_SRC C :noweb-ref begin
    int main() {
      printf("Line 1\n");
    
    #+END_SRC
    
    #+BEGIN_SRC C  :noweb-ref middle
    printf("Second\n");
    #+END_SRC
    
    #+BEGIN_SRC C  :noweb-ref end
    }
    main();
    #+END_SRC
    
    
    #+BEGIN_SRC C  :noweb yes
    
        <<begin>>
        <<middle>>
        <<end>>
        printf("some appropriate debug word");
    
 
    #+END_SRC
    
    And the output is:
    /tmp/babel-15080Ms4/C-src-150805OE.c: In function ‘main’:
    /tmp/babel-15080Ms4/C-src-150805OE.c:6:7: warning: incompatible implicit declaration of built-in function ‘printf’
           printf("Line 1\n");
           ^
    /tmp/babel-15080Ms4/C-src-150805OE.c: At top level:
    /tmp/babel-15080Ms4/C-src-150805OE.c:10:5: warning: data definition has no type or storage class
         main();
         ^
    /tmp/babel-15080Ms4/C-src-150805OE.c:12:8: error: expected declaration specifiers or ‘...’ before string constant
     printf("asti");
            ^
    /bin/bash: /tmp/babel-15080Ms4/C-bin-15080GZK: Permission denied

Or if I dont include the 

    printf("some appropriate debug word");

then, I get no output at all.

    `Code block produced no output.`


So my question is how do I make this work. lol.
    

Thanks in advance again

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

end of thread, other threads:[~2014-11-21 20:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-18 18:44 babel, header arguments jenia.ivlev
2014-11-20  9:36 ` Sebastien Vauban
2014-11-21 19:35   ` jenia.ivlev
2014-11-21 19:49     ` Thomas S. Dye
2014-11-21 20:09       ` jenia.ivlev
2014-11-21 20:32         ` jenia.ivlev
2014-11-21 20:36         ` Thomas S. Dye
2014-11-21 20:55           ` jenia.ivlev

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.