How to get started with OCaml on VSC? - visual-studio-code

I started learning OCaml several days ago. I installed everything and tested a small program on Atom which worked ok.
But I don't really understand how to work on VSC. I created a file 'test.ml',but how can I run it ?
Thanks in advance

Assuming VSC is Visual Studio Code (and you're on a Unix-like system):
If you want editing support such as auto-completions, you need to install OCaml Platform extension for VS Code by following installation steps outlined here. Note that the instructions indicate that you need to also have ocaml-lsp-server installed.
If you need to run test.ml as a program, you should do in the VS Code terminal:
$ ocamlc -o test test.ml # compile 'test.ml' into an executable 'test'
$ ./test # to run the program
Note that VS Code doesn't have a ready button to run an OCaml file as an executable (not yet at least).
Newcomers to OCaml are recommended to explore language either with ocaml or utop REPL.
How to get utop: Assuming you have opam installed, you should opam install utop. Aforementioned opam is a package manager for OCaml, that can also help you manage OCaml versions and is indispensable if you want to get serious about OCaml development.
Then you'll be able to launch utop in terminal, and inside utop, you can execute test.ml with
#use "test.ml"
assuming that utop was launched from the folder containing test.ml.
You should be able to do the same with ocaml REPL that is installed along with OCaml compiler, but it's much less convenient.

Related

VS Code not running C

I can't for the life of me get VSC to run C programs. The code in question runs correctly on Replit.
Extension installed
GCC installed
(GCC file path was added to the windows environment)
I tried uninstalling and re-installing. And...
It says I need a C extension.
Does anyone have any idea why this might be happening?
You still have to configure vscode well, as said in the doc.
If C\C++ extension is installed it will be asked to configure it for debugging or building, just follow the documentation.
But it is still not running, execute your program in the terminal with the gcc command: gcc filename+extension -o filenameExe

Elpy to allow pyenv to work on a project basis

I've used Emacs for all my coding projects so far. Soon I will start some python projects for the first time and would love to stick to Emacs for these as well.
I was looking into elpy which seems to provide already alot of desired functionality. The part I was not able to figure out completely is the following. I like to define virtual environments and python version to be used on a project basis. Let's say I start a project A, then I would use pyenv-virtualenv or pyenv-virtualenvwrapper to set it up
pyenv virtualenv 3.4.2 my-virtual-env-3.4.2
by doing this I've linked the python version 3.4.2 to that specific virtualenv / project. I have two questions regarding this in combination with elpy.
Question: This is a rather basic one. All the above can be achieved via the terminal. What is the advantage to emacs to support this? The workflow for me would be: Create project with associated virtualenv and python version. Activate virtualenv and start coding in emacs. If I need to install a package I will run pip in the terminal to ensure virtualenv is captured properly. There must be a reason why it's beneficial to support this in emacs. With my lack of knowledge I just don't see it :)
As pointed out there is for sure a good reason why we want emacs / elpy to support this. My second question would then be
**Question: How can I achieve this in emacs? Lokks like this blog has a solution. I was wondeirng if someone already tried this setup if it is a neat solution with makes sense conceptually. **
Well I strongly guess the goal is to use more features than just syntax highlighting: flycheck/flake8/linting, refactoring, elpy's test runner to use the right python version, install a pip package directly from emacs, stuff like this. You can carry on doing this in the terminal, but once you want an emacs feature, you'll need to set it up.
IĀ found two modes to do that (see wikemacs python page and doubled-checked on melpa): pyenv-mode (in melpa) and pyenv-mode-auto (change the version when there is a .python-version file).

How to install Coq

I have been installing Coq using the download links from the https://coq.inria.fr/ for both Windows and Mac. However, when I try coqc or coqtop on terminal or command prompt I get error messages saying that the command is not found. Although with that being said, I can still run Coq almost perfectly fine on the Coq IDE but when I compile buffer, in particularly the exercises from Software Foundations, i get the following message.
Running: coqc -I '/Users/zhangsheng/Desktop/G/repos/Coqy/cis500' '/Users/zhangsheng/Desktop/G/repos/Coqy/cis500/Basics.v' 2>&1
From what I understand, 2>&1 seems to be some form of misdirection and I feel that is the reason why coqc and coqtop don't seem to work on my terminal/command prompt.
Could someone kindly suggest the 'best' way to install Coq on either Mac or Windows or both such that I don't get the problems I mentioned above?
Although I am not a Windows or OSX user, I imagine that you're having this problem because the Coq installer does not update the system's PATH variable. This variable is a list of directories used by the terminal to look up the programs corresponding to commands you type. If you don't want to install Coq via a different method, you should probably find where the coqc and coqtop binaries are installed, and add these directories to your PATH. Here are a few references on how to do this: OSX, Windows.

Vim plugin does not recognize existing Perl support

I've been using the CoqIDE plugin for Vim on Linux machines for editing Coq files. Now I'm trying to install it on Windows 8. But when I try to source the plugin, I get
Your vim doesn't support Perl. Install it before using CoqIDE mode.
which is strange, because with :version I clearly see +perl/dyn included. Is this different from the +perl that I need?
I heard somewhere that you need to have Perl installed before Vim to get a Perl-enabled Vim, so I tried that as well. I uninstalled Vim, installed Strawberry Perl 5.18.2.2 (64bit), and reinstalled Vim. Still the same problem.
If the solution involves manually compiling binaries, I would really appreciate detailed instructions as I don't have any experience with it.
+perl/dyn just specifies that Vim has been compiled with dynamic Perl support; it doesn't yet check that the Perl library can be loaded successfully. To do that, try executing a Perl command, e.g.:
:perl VIM::Msg("Hello")
This probably yields on your system:
E370: Could not load library perl510.dll
Sorry, this command is disabled: the Perl library could not be loaded.
Next, you'd then have to investigate whether a proper Perl version has been installed and the DLL is accessible (though the PATH).
Download DWIMPerl for windows. I'm running win7 64 and gvim 7.4.2. Using strawberryperl and activeperl resulted in :echo has('perl') to yield 0. By switching to DWIMPerl (and ensuring my PATH env variables are proper) :echo has('perl') now yields 1 using the standard gvim distribution. This is important for vim extensions like dbext which require proper support for perl interfaces.

Emacs + GDB + SCons + Step through Debugging

When compiling a project via a makefile using the Emacs compile command, when gdb is run on the resultant binary the application can be stepped through. However, when building using a large project with SCons, attempting to step through does not work in that Emacs doesn't seem to know which files to load or how they're related to the binary.
What does one have to do to do step through in Emacs? If Emacs can't support SCons natively then how can this be done manually; make must be using some mechanism to alert Emacs to a file's presence.
Are you sure your make and scons compile options are the same? It sounds like your scons build is lacking debug symbols (in gcc, use the -g option).
I don't use Scons. I can't help but ask if you have done the Scons IDEIntegration as given in the Working within Emacs and XEmacs section. It says Scons builds in a different directory that Emacs does not look at by default, so you have to move the files to make Emacs look at them. But that is for navigating through build error messages. I hope it works for gdb too.