[racket] MzCOM

10 views
Skip to first unread message

hera...@gmx.de

unread,
Aug 9, 2012, 5:17:44 AM8/9/12
to us...@racket-lang.org
Hello friends,

I have questions again about MzCom.

1.: I create an Object in DrRacket from MzCom. Like this:
(require ffi/com)
(define MZCOM (com-create-instance "MzCOM.MzObj"))
(com-invoke MZCOM "eval" "print \"hello\"")

I get this output: "\"hello\""

So far so good.

When I create an Object in C++ and eval the same expression I get a
#<void>

So when I create some init files with some output in it for preloading it during my load process from my c++ app I get no output. Same occurs when I create objects or so. It might be helpful to get any informational string after creating something like:
(define MZCOM (com-create-instance "MzCOM.MzObj"))
-> "comobject;MzCOM.MzObj;MZCOM" or

(define anyvariable 12)
-> "variable;12;anyvariable "


2.: Is it possible to get all Objects/Functions/variable that I create in the actual scope?

3.: I read somewhere that I can write s-expressions for substituting xml files. Is there any tutorial?

Thanks in advance

Yours,
____________________
Racket Users list:
http://lists.racket-lang.org/users

Matthias Felleisen

unread,
Aug 9, 2012, 9:07:54 AM8/9/12
to hera...@gmx.de, us...@racket-lang.org

On Aug 9, 2012, at 5:17 AM, hera...@gmx.de wrote:

> I read somewhere that I can write s-expressions for substituting xml files. Is there any tutorial?


There are several different libraries for manipulating XML via S-expressions:

1. http://docs.racket-lang.org/xml/index.html?q=xml
Look for the subsection on X-expressions and conversion to/from XML.
This library is lightweight but covers a lot of basic needs.
Also see the web-server's use of this library.

2. http://planet.racket-lang.org/display.ss?package=sxml2.plt&owner=clements
The SXML representation is for manipulations that require some sophistication
but also look for sxml at http://planet.racket-lang.org/

3. http://planet.racket-lang.org/display.ss?package=xml.plt&owner=bzlib
Help converting bewteen xexpr and sxml, as well as helpers
for reading and writing sxml and xexpr.

And if you continue to look on Planet for XML you will find many more.

Matthew Flatt

unread,
Aug 9, 2012, 11:17:23 AM8/9/12
to hera...@gmx.de, us...@racket-lang.org
At Thu, 09 Aug 2012 11:17:44 +0200, hera...@gmx.de wrote:
> Hello friends,
>
> I have questions again about MzCom.
>
> 1.: I create an Object in DrRacket from MzCom. Like this:
> (require ffi/com)
> (define MZCOM (com-create-instance "MzCOM.MzObj"))
> (com-invoke MZCOM "eval" "print \"hello\"")
>
> I get this output: "\"hello\""

When you evaluate "print \"hello\"", then you're evaluating two expressions:

print

and

"hello"

where only the result of the last expression is returned.

Did you mean "(print \"hello\")"?

> So far so good.
>
> When I create an Object in C++ and eval the same expression I get a
> #<void>

If you used "(print \"hello\")", then you'd get a #<void> result, so I
wonder whether you used different strings in your Racket and C++ tests.

To capture printed output, use something like

(com-invoke MZCOM "eval"
(format "~s"
'(with-output-to-string
(lambda ()
(print "hello")))))


> 2.: Is it possible to get all Objects/Functions/variable that I create in the
> actual scope?

I'm not sure what you mean by "actual scope", but for a top-level
namespace, `namespace-mapped-symbols' will give you a list of defined
names, and `namespace-variable-value' will let you get the value of
each.
Reply all
Reply to author
Forward
0 new messages