I am using a software who has a built-in scheme interpreter. User could communicate and/or manipulate the software by typing command in the interpreter. The interpreter also could load scheme code file or bin file that contain scheme code. I wrote some scheme functions like this:
(define test (lambda(() (display "This is a test!")))
I will use the function "test" in the software interpreter later.
I don't want to anyone to change my code, so how can I compile this function into a bin file and load it to the interperter later?
Thanks a lot!!!
Joe
Interpreters don't run compiled code.
You can compile all your scheme program with scheme compilers but not have an hybrid interpreted/compiled code
http://www.call-cc.org/
Yours
Related
I've been trying to load another file into my Scheme scrip but when I do this,
(load "fn1.lisp")
the error came out as
The port #[input-port 13 for file: "/Users/yiwenzhu/Library/Mobile Documents/com~apple~CloudDocs/work/study/computer/SICP/src_lisp/fn1.lisp"] signalled an error:
The primitive channel-read, while executing the read system call, received the error: Bad address.
How to solve this? Thanks.
load is the only compatible way until R5RS, but after that the standard introduced libraries. Where the files need to be installed is implementation dependent, but the source structure on how to define and use isn't.
Also know that SICP is pre-R5RS so there isn't one modern Scheme implementation that would run the books examples without some compatibility layer. Eg. I have an answer about how to do SICP with DrRacket.
Since we don't know how the file you are trying to include look like or which Scheme implementation you are using I'm afraid I cannot help you further. I can update if you update your question.
How to directly run a c++ file present in read-only storage like CD-drive without making executable files using g++? There must be some arguments for that to work.
The process of a C/C++ program when you make one till you run it:
You write the program's source code.
The compiler comes in here and compiles the source code to object files.
Note: Remember that the program cannot be executed at this stage. It's only an object file. You'd know this if you have worked on bigger size programs, but if you haven't here is how it works. Remember using those header files in your programs? These header files just tell the compiler that there are some things that are not defined in your program. They are somewhere else. So your compile compiles the program to the object file leaving out things that have a prototype (which is in the header files).
This is a very important point. Here a program called 'linker' comes into play. What linker does is to take all the object files created by compiler and combines them into one. Say for example your compiler created a single object file. Now, you're using math library or anything from standard library. The compiler-linker package (often called only compiler) comes with object files for these standard library definitions. So, linker takes your object file and combines it with other object files from the package and then converts it to an executable file. This is the file that you can run. Nothing else is runnable directly.
To run source code the process is explained already, we have to use the g++. Now
What I understand from your question is that you want to know if a program can be run once it's compiled and linked properly (hence an executable has been generated). Answer to that would be yes.
Alternatively, may sound strange, there is an interpreter I know called Cling that can be of use to bypass the compilation of C++ program.
After all C++ is generally seen as a compiled language. However, any programming language can be implemented as a compiler or as an interpreter and Cling happens to be an interactive C++ interpreter based on LLVM and Clang.
Take a thorough look at this
I'm completely new to SML and I have no idea how to work with anything related to it.
I am supposed to use the SMLNJ compiler and I'm currently coding using Notepad++.
But how do I compile the program exactly? Do I copy and paste the code in the SMLNJ command line thing? Or is there an environment for SMLNJ I can actually code in and compile my code?
PLEASE HELP!
If by "compile" you mean "compile to a stand-alone executable" -- don't worry about that when first learning the language as a full answer is somewhat involved. In principle it is possible, though there seems to be practical issues (as this excellent answer details).
On the other hand, SML/NJ has a command-line based REPL (Read-Evaluate-Print-Loop) which actually is an compiler. It is an incremental compiler -- meaning that it compiles newly defined functions in the context of currently defined functions. At the very first you will be experimenting with short snippets typed directly into the REPL. Sooner rather than later you will want to write the code in something like NotePad++ . Just write the file, save it with a .sml extension, then in the REPL type
use "filename";
and it loads and compiles your definitions.
A trick that I sometimes use is the following. On the top of my files I have a comment like this:
(* val _ = (use "C:/Programs/sets.sml", OS.Process.system "cls"); *)
Here sets.sml just happens to be an SML file I have on my machine. When I get done editing the file I save it and then copy the insides of the comment (beginning with val and extending to the semicolon) to the clipboard and then paste it into an open SML REPL (using the edit menu for the command window which pops up when you hit the icon in the upper left hand corner of the command window). This loads the definitions and presents you with a cleared REPL for experimenting with your definitions.
Notepad++ seems to lack a syntax definition file for SML (although it has one for F#, which might be close enough). Personally, I do most of my SML using Textpad. This isn't open source but is reasonably priced nagware which is roughly comparable to Notepad++. From their website you can download a useful SML syntax-definition file which does a nice job of logically highlighting your code. I even created a Textpad tool (which for unknown reasons only works sporadically) for automatically saving the file, opening SML, and invoking use on the file name.
In my understanding, julia is a script language with a JIT compiler. But in java, you can find *.class files; In python, you can find *.pyc files. This means java and python need first convert its language to bytecode, then using VM to run this bytecode. However, I can not find the bytecode files for julia like *.jlc. Any ideas?
Actually there is functionality to dump the LLVM bitcode in Julia:
See jl_dump_bitcode.
Thanks to Isiah for pointing out that it is possible to use code_llvm to read the bitcode in the interpreter.
Note that in julia_trampoline this function is used, depending on a build_path option. However this does not seem like an end-user interface to me.
In contrast to other JIT-based software like NodeJS (V8), it is however technically possible to dump the LLVM bitcode.
This is covered in the manual: http://docs.julialang.org/en/release-0.5/devdocs/eval/
Leah Hanson has written an excellent article here on the 5 steps Julia performs to get from Julia code to native Assembly code:
Can anyone tell me something about this file? As I know:
Common-Lisp and Scheme are both dialects of lisp.
Common-Lisp source file *.lisp can be compiled into binary file *.fasl which can be loaded faster than the source file.
Q:Can the Scheme source code *.scm be compiled into some binary file that will be loaded faster than the source code?
Thanks in advance,
joe
Yes, if the Scheme implementation you're using has that feature.
FASL in Racket: http://docs.racket-lang.org/reference/fasl.html
FASL in Chez Scheme: http://www.scheme.com/csug8/io.html#./io:h15
Alternatively, you could compile your code to native binaries...