1

I'm working a little with SCMUTILS package that implements MIT SCHEME. I'm running it from Emacs and I'm having trouble when using a function, can you help me?

My code is:

(define ((((delta eta) f) q) t)
  (let ((fmas (f (+ q (* 0.001 eta))))
         (efe (f q)))
       (/ (- (fmas t) (efe t)) 0.001)))


(define ((G q) t)
       (dot-product (q t) (q t)))


(((((delta  test-path) G)  test-path) 5))

Where test-path is:

(define (test-path t)
 (up (+ (* 4 t) 7)
     (+ (* 3 t) 5)
     (+ (* 2 t) 1)))

And I'm getting this error:

Loading "mecanica"...
;Application of a number not allowed 2501.2500000000273 (())

what could be the problem?

At first I thought that scheme couldn't divide a structure like test-path by a number, so I put the dot product to make it a function that returns a number; but that didn't work.

I've tried printing expression in the delta-eta function and the error comes in while doing this part:

(/ (- (fmas t) (efe t)) 0.001)))

And if I take out the quotient part, there is no error.

Surely I am missing something. Hope you can help. Thanks!

Flux
  • 9,805
  • 5
  • 46
  • 92
aramirezreyes
  • 1,345
  • 7
  • 16
  • I can't get this running on it's own in my Scheme implementation. What's the definition of `up`, `efe`, `dot-product` and `fmas`? The error is simple. At some point you are doing `(some-var ...)` where `some-var` isn't resolved to a procedure but rather a number. – Sylwester Apr 01 '15 at 21:02
  • `test-path` is a function, but when you call `delta`, it gets assigned to the `eta` and `q` parameters, and then you add and multiply them. – angus Apr 01 '15 at 22:37
  • I thought [scmutils](https://www.google.com/?q=scmutils) is a package that must be run inside MIT Scheme (not emacs) on Unix, as part of SICMechanichs book. – Will Ness Apr 01 '15 at 23:08
  • 1
    @Sylwester Sorry, the answer below shows the code clearer. Dot-product and up are procedures included with the SCMUtils package. It is a packaage designed to work with when using the book 'Structure and interpretation of Classical Mechanics' – aramirezreyes Apr 04 '15 at 19:33
  • @WillNess scmutils *can* be run from emacs. See my comments [in this question](https://stackoverflow.com/questions/25956349/error-running-scmutils-by-m-x-mechanics-in-emacs). – xdavidliu Dec 23 '19 at 04:33

1 Answers1

0

Assume this

(define ((((delta eta) f) q) t)
  (let ((fmas (f (+ q (* 0.001 eta))))
         (efe (f q)))
       (/ (- (fmas t) (efe t)) 0.001)))

is equivalent to this

(define (delta eta)
  (lambda (f)
    (lambda (q)
      (lambda (t)
        (let ((fmas (f (+ q (* 0.001 eta))))
              (efe (f q)))
          (/ (- (fmas t) (efe t)) 0.001))))))

Then (((((delta test-path) G) test-path) 5)) is multiplying 0.001 and test-path at (* 0.001 eta). And also inside of the G, it expects q as a procedure however, fmas is retrieving a procedure from G passing a number to G. Thus this would try to apply calculated number passing t.

Takashi Kato
  • 646
  • 3
  • 5