[racket] ffi/com

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Aug 9 11:32:27 EDT 2012

At Thu, 09 Aug 2012 16:23:08 +0200, "murat demirtas" wrote:
> Hello,
> during playing arround with the ffi/com package I try to do something like that:
> (require ffi/com)
> (define cci "com-create-instance")
> (define ProgID " MzCOM.MzObj")
> (define mz (string-append cci ProgID))
> (eval mz)
> but I get only the string. 

Yes, in a read-eval-print loop,

 (eval "x") 



because `eval' expects an S-expression not a string. 

You could use

 (eval (read (open-input-string "x")))

to parse a string to an S-expression and evaluate it.

In contrast to the `eval' function, the Eval() method of MzCOM expects
a string. Really, Eval() should be called ReadStringAndEval().

> Or something like this:
> (define (cci VAR PROGID)
> 	(define VAR com-create-instance PROGID)
> )
> I get :define: bad syntax (multiple expressions after identifier) in: (define 
> VAR com-create-instance PROGID)
> So I thing I understand something wrong here. Or is this what I am trying to do 
> possible?

The immediate error is that you're missing parentheses; you want
  (com-create-instance PROGID)

instead of

  com-create-instance PROGID

But you also seem to be able to pass a variable name into `cci' and
have the `define' within `cci' bind it outside of `cci', and that won't

Stepping back, I think you're confused about `eval' --- and that's
fair, because a lot of people are confused about `eval' at first. For
most people, the solution I recommend is to completely ignore `eval'
and do things a better way.

Unfortunately, since you're trying to use MzCOM, you really have to use
`eval' in the form of Eval()...

Have you seen this part of the documentation already?


I also wrote the following blog post about `eval' in an attempt to
clarify some of the issues, but my impression is that few found it
helpful. Just in case it works for you:


Posted on the users mailing list.