1

I'm trying to learn how to use the noweb syntax and advance my knowledge on the possibilities of org babel. For that, I'm trying to get the following an example to work that 1. uses noweb syntax and 2. calls the tangled function later on in the code.

Here is the code:

# This is the function that needs to be tangled
#+NAME: fast-multiplication
#+BEGIN_SRC scheme :noweb yes :var a=1 :var b=1
(define (fast-multiplication a b)
<<double>>
<<halve>>
(cond ((= b 0) 0)
      ((even? b) (fast-multiplication (double a) (halve b)))
      (else (+ a (fast-multiplication a (- b 1))))))
#+END_SRC

Now, we'll need procedures for doubling and halving. We can write them down here:

#+NAME: double
#+BEGIN_SRC scheme
(define (double a)
  (+ a a))
#+END_SRC 

#+NAME: halve
#+BEGIN_SRC scheme
(define (halve a)
  (/ a 2))
#+END_SRC 

# I couldn't find examples in the documentation to check my syntax.
# I think this line here is wrong..
#+call: fast-multiplication(a=5,b=7)

#+RESULTS:
: "An error occurred."

So I get an error, which I think comes from the way I'm calling the function? Everything works fine if I try it directly on the REPL.

Daniel
  • 3,563
  • 16
  • 41
  • Does it work without using the call statement? – Sparx Mar 08 '17 at 08:00
  • It works on the Scheme REPL directly. Is that what you meant? – Daniel Mar 08 '17 at 08:01
  • I meant calling the block fast-multiplication directly with `C-c C-c` . I don't know Scheme but can you define a function within another function like that? – Sparx Mar 08 '17 at 08:55
  • It seems like there is a problem with `ob-scheme` on the function `org-babel-scheme-execute-with-geiser`. I tried with different scheme implementations and none of them worked. – Daniel Mar 08 '17 at 10:35
  • And that is the case even when using noweb? Pasting in the half and double code blocks? May be time for a bug report then. – Sparx Mar 08 '17 at 10:52
  • That is the case with and without noweb. =/ I'll report the bug when I have time to create a minimal example. Thanks for your comments – Daniel Mar 08 '17 at 11:43

0 Answers0