Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheme and C working together

Tags:

c

scheme

Is there a way to have C run scheme programs? I know both languages and was hoping to use the logic of scheme with the speed of C. A basic example C makes the lists that scheme needs to use then scheme returns something. So far I have been using DrRacket for scheme. Can anyone point me in the right direction?

edit:

Looking at Caleb's answer I saw Racket CGC. How do you find this I have the racket source from its website, I am on Ubuntu. And where can i get the libracket.a and libmzgc.a libraries. I can't find them anywhere. Everywhere I look it just points back to the article saying you need them.

like image 452
mrm9084 Avatar asked Dec 16 '22 00:12

mrm9084


1 Answers

The simplest way of mixing Scheme and C is to write the main program in Scheme and only write what absolutely needs to be in C in C.

The C source is compiled as a library, and then it is imported in Racket using the FFI. The FFI is surprisingly easy to use, and even if you decide to write your program the other way around, is definitely something you should examine first.

Introduction to the FFI

Docs on the FFI

Btw - libracket.a and libmzgc.a should be installed along with the rest of the Racket files. I am not on Ubuntu, so I don't know the exact path. However you can use the unix command find to locate it.

If I remember correctly, the command is:

find / -name libracket.a
like image 117
soegaard Avatar answered Jan 02 '23 10:01

soegaard