How to load more than on language using #lang in Racket
up vote
1
down vote
favorite
I'm trying to find a way to write a program by using more than one language models in Racket. For example, I wrote a c program in Racket like:
#lang c
#include <stdio.h>
int main() {
int a = 1;
printf("%dn", a);
return 0;
}
Then is it possible to put python code after above c code in Racket program so that the Racket program will looks like:
#lang c
#include <stdio.h>
int main() {
int a = 1;
printf("%dn", a);
return 0;
}
//Someting close the c language model
#lang python
def main():
b = 2
print "%d", %b
if __name__ == "__main__":
main()
I have installed c and python language package in Racket and can write these languages in Racket singly.
python c racket
add a comment |
up vote
1
down vote
favorite
I'm trying to find a way to write a program by using more than one language models in Racket. For example, I wrote a c program in Racket like:
#lang c
#include <stdio.h>
int main() {
int a = 1;
printf("%dn", a);
return 0;
}
Then is it possible to put python code after above c code in Racket program so that the Racket program will looks like:
#lang c
#include <stdio.h>
int main() {
int a = 1;
printf("%dn", a);
return 0;
}
//Someting close the c language model
#lang python
def main():
b = 2
print "%d", %b
if __name__ == "__main__":
main()
I have installed c and python language package in Racket and can write these languages in Racket singly.
python c racket
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to find a way to write a program by using more than one language models in Racket. For example, I wrote a c program in Racket like:
#lang c
#include <stdio.h>
int main() {
int a = 1;
printf("%dn", a);
return 0;
}
Then is it possible to put python code after above c code in Racket program so that the Racket program will looks like:
#lang c
#include <stdio.h>
int main() {
int a = 1;
printf("%dn", a);
return 0;
}
//Someting close the c language model
#lang python
def main():
b = 2
print "%d", %b
if __name__ == "__main__":
main()
I have installed c and python language package in Racket and can write these languages in Racket singly.
python c racket
I'm trying to find a way to write a program by using more than one language models in Racket. For example, I wrote a c program in Racket like:
#lang c
#include <stdio.h>
int main() {
int a = 1;
printf("%dn", a);
return 0;
}
Then is it possible to put python code after above c code in Racket program so that the Racket program will looks like:
#lang c
#include <stdio.h>
int main() {
int a = 1;
printf("%dn", a);
return 0;
}
//Someting close the c language model
#lang python
def main():
b = 2
print "%d", %b
if __name__ == "__main__":
main()
I have installed c and python language package in Racket and can write these languages in Racket singly.
python c racket
python c racket
asked Nov 10 at 20:30
wwwwpkpkpk
82
82
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
The language feature doesn't support writing multiple languages in the same file out of the box. However Alex Knauth has written an extension that allows you do what you want.
Check out the documentation here: http://docs.racket-lang.org/multi-file-lang/index.html
Thanks! I tried this extension and it does work. But how to let two program shares variables easily? Is storing variables into text file the only way to do that?
– wwwwpkpkpk
Nov 10 at 21:33
That depends on the languages. Some language provide a mechanism to export variables that can be used in other modules/files. Here the implementation of "#lang C" sadly doesn't (it basically writes a .c-file and invokes the standard C-compiler). Writing/reading to/from files is one way to go. Another is to look at pipes.
– soegaard
Nov 10 at 21:57
For "#lang racket", the language can import python programs like: "(require python) (py-impoort "pyfile1" as python-model)". Is there any similar way to import C program using "require"?
– wwwwpkpkpk
Nov 10 at 22:41
No. The Python language was implemented in such a way that it plays nicely with the Racket module system. The C one (due to the way it is implemented) does not.
– soegaard
Nov 11 at 10:01
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
The language feature doesn't support writing multiple languages in the same file out of the box. However Alex Knauth has written an extension that allows you do what you want.
Check out the documentation here: http://docs.racket-lang.org/multi-file-lang/index.html
Thanks! I tried this extension and it does work. But how to let two program shares variables easily? Is storing variables into text file the only way to do that?
– wwwwpkpkpk
Nov 10 at 21:33
That depends on the languages. Some language provide a mechanism to export variables that can be used in other modules/files. Here the implementation of "#lang C" sadly doesn't (it basically writes a .c-file and invokes the standard C-compiler). Writing/reading to/from files is one way to go. Another is to look at pipes.
– soegaard
Nov 10 at 21:57
For "#lang racket", the language can import python programs like: "(require python) (py-impoort "pyfile1" as python-model)". Is there any similar way to import C program using "require"?
– wwwwpkpkpk
Nov 10 at 22:41
No. The Python language was implemented in such a way that it plays nicely with the Racket module system. The C one (due to the way it is implemented) does not.
– soegaard
Nov 11 at 10:01
add a comment |
up vote
2
down vote
The language feature doesn't support writing multiple languages in the same file out of the box. However Alex Knauth has written an extension that allows you do what you want.
Check out the documentation here: http://docs.racket-lang.org/multi-file-lang/index.html
Thanks! I tried this extension and it does work. But how to let two program shares variables easily? Is storing variables into text file the only way to do that?
– wwwwpkpkpk
Nov 10 at 21:33
That depends on the languages. Some language provide a mechanism to export variables that can be used in other modules/files. Here the implementation of "#lang C" sadly doesn't (it basically writes a .c-file and invokes the standard C-compiler). Writing/reading to/from files is one way to go. Another is to look at pipes.
– soegaard
Nov 10 at 21:57
For "#lang racket", the language can import python programs like: "(require python) (py-impoort "pyfile1" as python-model)". Is there any similar way to import C program using "require"?
– wwwwpkpkpk
Nov 10 at 22:41
No. The Python language was implemented in such a way that it plays nicely with the Racket module system. The C one (due to the way it is implemented) does not.
– soegaard
Nov 11 at 10:01
add a comment |
up vote
2
down vote
up vote
2
down vote
The language feature doesn't support writing multiple languages in the same file out of the box. However Alex Knauth has written an extension that allows you do what you want.
Check out the documentation here: http://docs.racket-lang.org/multi-file-lang/index.html
The language feature doesn't support writing multiple languages in the same file out of the box. However Alex Knauth has written an extension that allows you do what you want.
Check out the documentation here: http://docs.racket-lang.org/multi-file-lang/index.html
answered Nov 10 at 21:02
soegaard
23.7k43774
23.7k43774
Thanks! I tried this extension and it does work. But how to let two program shares variables easily? Is storing variables into text file the only way to do that?
– wwwwpkpkpk
Nov 10 at 21:33
That depends on the languages. Some language provide a mechanism to export variables that can be used in other modules/files. Here the implementation of "#lang C" sadly doesn't (it basically writes a .c-file and invokes the standard C-compiler). Writing/reading to/from files is one way to go. Another is to look at pipes.
– soegaard
Nov 10 at 21:57
For "#lang racket", the language can import python programs like: "(require python) (py-impoort "pyfile1" as python-model)". Is there any similar way to import C program using "require"?
– wwwwpkpkpk
Nov 10 at 22:41
No. The Python language was implemented in such a way that it plays nicely with the Racket module system. The C one (due to the way it is implemented) does not.
– soegaard
Nov 11 at 10:01
add a comment |
Thanks! I tried this extension and it does work. But how to let two program shares variables easily? Is storing variables into text file the only way to do that?
– wwwwpkpkpk
Nov 10 at 21:33
That depends on the languages. Some language provide a mechanism to export variables that can be used in other modules/files. Here the implementation of "#lang C" sadly doesn't (it basically writes a .c-file and invokes the standard C-compiler). Writing/reading to/from files is one way to go. Another is to look at pipes.
– soegaard
Nov 10 at 21:57
For "#lang racket", the language can import python programs like: "(require python) (py-impoort "pyfile1" as python-model)". Is there any similar way to import C program using "require"?
– wwwwpkpkpk
Nov 10 at 22:41
No. The Python language was implemented in such a way that it plays nicely with the Racket module system. The C one (due to the way it is implemented) does not.
– soegaard
Nov 11 at 10:01
Thanks! I tried this extension and it does work. But how to let two program shares variables easily? Is storing variables into text file the only way to do that?
– wwwwpkpkpk
Nov 10 at 21:33
Thanks! I tried this extension and it does work. But how to let two program shares variables easily? Is storing variables into text file the only way to do that?
– wwwwpkpkpk
Nov 10 at 21:33
That depends on the languages. Some language provide a mechanism to export variables that can be used in other modules/files. Here the implementation of "#lang C" sadly doesn't (it basically writes a .c-file and invokes the standard C-compiler). Writing/reading to/from files is one way to go. Another is to look at pipes.
– soegaard
Nov 10 at 21:57
That depends on the languages. Some language provide a mechanism to export variables that can be used in other modules/files. Here the implementation of "#lang C" sadly doesn't (it basically writes a .c-file and invokes the standard C-compiler). Writing/reading to/from files is one way to go. Another is to look at pipes.
– soegaard
Nov 10 at 21:57
For "#lang racket", the language can import python programs like: "(require python) (py-impoort "pyfile1" as python-model)". Is there any similar way to import C program using "require"?
– wwwwpkpkpk
Nov 10 at 22:41
For "#lang racket", the language can import python programs like: "(require python) (py-impoort "pyfile1" as python-model)". Is there any similar way to import C program using "require"?
– wwwwpkpkpk
Nov 10 at 22:41
No. The Python language was implemented in such a way that it plays nicely with the Racket module system. The C one (due to the way it is implemented) does not.
– soegaard
Nov 11 at 10:01
No. The Python language was implemented in such a way that it plays nicely with the Racket module system. The C one (due to the way it is implemented) does not.
– soegaard
Nov 11 at 10:01
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243133%2fhow-to-load-more-than-on-language-using-lang-in-racket%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown