Guile and C++

2010-05-14 Thread Noah Lavine
Dear Guile-users,

I am wondering what the best way is to connect Guile with C++ code. I
notice that several large programs use Guile in this way (TeXmacs and
LilyPond), so it seems that it is possible to do it, and it works well
enough that you can write a large, functioning program with it.
However, I don't see any mention of it in the Guile documentation.
Does Guile come with the ability to use C++ code, or should I plan on
writing C wrappers for any functions I want to use? (I'm planning on
using Guile 2.0, if that makes a difference.)

Thank you
Noah Lavine



Re: Guile and C++

2010-05-14 Thread objc

Dear Noah,

there are no inherent problems with mixing Guile, C, C++, guile (MS 
windows, LINUX,GNUStep,X11)
Depends on how you order your includes, which OS you use, version conflicts 
etc.
Using scoping rules to the fullest you can pretty much mix it up as you 
like.


obj.

--
From: "Noah Lavine" 
Sent: Thursday, May 13, 2010 8:53 PM
To: 
Subject: Guile and C++


Dear Guile-users,

I am wondering what the best way is to connect Guile with C++ code. I
notice that several large programs use Guile in this way (TeXmacs and
LilyPond), so it seems that it is possible to do it, and it works well
enough that you can write a large, functioning program with it.
However, I don't see any mention of it in the Guile documentation.
Does Guile come with the ability to use C++ code, or should I plan on
writing C wrappers for any functions I want to use? (I'm planning on
using Guile 2.0, if that makes a difference.)

Thank you
Noah Lavine






Re: Guile and C++

2010-05-14 Thread Noah Lavine
Thanks a lot.

How would this work if I wanted to not run Guile embedded in a C++
program, but instead load the C++ code at runtime from a regular Guile
interpreter? (This could use either the libffi binding or the regular
Guile ones.)

Thank you
Noah

On Fri, May 14, 2010 at 3:54 PM, objc  wrote:
> Dear Noah,
>
> there are no inherent problems with mixing Guile, C, C++, guile (MS
> windows, LINUX,GNUStep,X11)
> Depends on how you order your includes, which OS you use, version conflicts
> etc.
> Using scoping rules to the fullest you can pretty much mix it up as you
> like.
>
> obj.
>
> --
> From: "Noah Lavine" 
> Sent: Thursday, May 13, 2010 8:53 PM
> To: 
> Subject: Guile and C++
>
>> Dear Guile-users,
>>
>> I am wondering what the best way is to connect Guile with C++ code. I
>> notice that several large programs use Guile in this way (TeXmacs and
>> LilyPond), so it seems that it is possible to do it, and it works well
>> enough that you can write a large, functioning program with it.
>> However, I don't see any mention of it in the Guile documentation.
>> Does Guile come with the ability to use C++ code, or should I plan on
>> writing C wrappers for any functions I want to use? (I'm planning on
>> using Guile 2.0, if that makes a difference.)
>>
>> Thank you
>> Noah Lavine
>>
>>
>



Re: Guile and C++

2010-05-14 Thread Hans Aberg

On 14 May 2010, at 22:05, Noah Lavine wrote:


How would this work if I wanted to not run Guile embedded in a C++
program, but instead load the C++ code at runtime from a regular Guile
interpreter? (This could use either the libffi binding or the regular
Guile ones.)


Since Guile is written in C, formally according to the C++ standard,  
you can only load Guile from C++ code, and not the opposite. So main()  
must be C++.


GCC though has integrated C and C++ fully, it seems. So you can call C+ 
+ from C code, but the latter do not implement C++ exception stacks,  
and may not call C++ initialization function properly (I haven't  
checked). It means that throwing and catching exceptions within C++  
functions called from C seems to work fine, but if one tries to pass  
it through a C function, the program will throw a terminate exception.


  Hans





Re: Strange behavior with delayed objects

2010-05-14 Thread user8472

OK, I have found a solution. The point is that in section 4.2.2 of R5RS it is
explicitly stated that mutually recursive defines must not refer to those
variables. The solution is thus to wrap the defines in (lambda () ...)s.


(define (solve f y0 dt)
  (define (y) (integral (delay (dy)) y0 dt))
  (define (dy) (stream-map f (y)))
  (y))

(debug-set! stack 200)
(stream-ref (solve (lambda (x) x) 1 0.001) 1000)


will produce the correct answer. The downside is that the function calls
will be wrapped recursively which necessitates increasing the stack size.
Plus, it's much slower this way. But it works.
-- 
View this message in context: 
http://old.nabble.com/Strange-behavior-with-delayed-objects-tp28443452p28564620.html
Sent from the Gnu - Guile - User mailing list archive at Nabble.com.