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.










share|improve this question


























    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.










    share|improve this question
























      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.










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 20:30









      wwwwpkpkpk

      82




      82
























          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






          share|improve this answer





















          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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

























          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






          share|improve this answer





















          • 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















          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






          share|improve this answer





















          • 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













          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






          share|improve this answer












          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          List item for chat from Array inside array React Native

          Thiostrepton

          Caerphilly