how to reload OCaml modules in utop - ocaml

Is it possible reload modules in OCaml's utop?
My development workflow goes something like this when playing around with OCaml code:
First, open up a file example.ml in Vim and hack on it. Switch to another terminal and run utop. From within utop, load the code with the directive #use "example.ml";;.
Go back to Vim and make some changes in the code. After changing the code, I want to play around with the new changes. Go back to utop and rerun the directive #use "example.ml".
It would be nice if there were a #reload directive that would reload all previously loaded modules, but there doesn't appear to be. Is there some way to easily reload all previously loaded modules?
Ideally this would work similarly to GHCi's :reload command.

At the time this question was asked, I believe dune had not yet established itself as the build system for OCaml. Using dune, you can simply launch a utop instance with locally defined libraries loaded (as explained here) by doing :
$ dune utop <dir> -- <args>
Where <dir> is a directory under which dune will search (recursively)
for all libraries that will be loaded

Related

F# package for Sublime Text Build System absent

I am starting out with F# and trying to get it to work with Sublime Text 3 with a package, https://github.com/fsharp/sublime-fsharp-package. After installing the package using Package Control, I see F# appear as an available language to use in Sublime Text's bottom bar, and syntax highlighting appears to work more or less, from what I can tell, but the build system for F# fails to appear as it should.
So, trying to fix things, I run "build.sh install" and get an error, "Cannot open assembly '.paket/paket.bootstrapper.exe': No such file or directory." I am sort of stuck. Many thanks for any help.
From the comments you've made, you appear to be a little unfamiliar with the Unix underpinnings of OS X. I'll explain those first, then I'll suggest something for you to try that may fix your problem.
Technically, files or directories whose name starts with . are not "reserved for the system" as you put it; they're hidden. Now, it's true that Finder won't allow you to create files or directories whose name starts with ., because Apple didn't want to have to field all the tech-support calls from people who didn't know about the hidden-files feature: "I named my file ... more important stuff for work and now it's gone! Help!!!" But if you're in the Terminal app, then you can easily create files or directories with . as their first letter: mkdir .foo should work. You won't see it when you do ls, but ls -a (a for "all") will show you all files, including hidden files. And you can also do cd .foo and create files inside the hidden .foo directory -- and while the .foo folder won't show up in Finder, it will be perfectly accessible in the Terminal, and to any F# programs you might write.
So when you say that you cloned https://github.com/fsprojects/Paket but it failed to include the .github and .paket directories, I think you just don't know how to see them. You can't see them in the Finder (well, you can if you jump through a couple of hoops but I don't think it's worth the effort), but you can see them with ls -a. Just open your terminal, run cd /Users/Username/Paket, and then run ls -a and I think you'll see that the .paket and .github directories were indeed created by your git clone command.
So what you should probably try is this:
Go to https://github.com/fsprojects/Paket/releases/latest
Download the paket.bootstrapper.exe and paket.exe files. Put them in /Users/Username/Downloads (or wherever the default OS X Downloads directory is if it's different -- just as long as it's somewhere where you can find them easily).
Open the Terminal app.
Go to the directory where you've unpacked the Sublime Text 3 package. I.e., in the Terminal app, run cd /Users/Username/Library/Application\ Support/Sublime\ Text\ 3/Packages/sublime-fsharp-package-master.
Run ls -a and see if there's a .paket directory.
If it does not exist, run mkdir .paket.
Now do cd .paket so you're in the hidden .paket directory under sublime-fsharp-package-master.
Now do ls and see if there's a paket.bootstrapper.exe file.
If it doesn't exist, then copy in the .exe files you downloaded earlier:
cp /Users/Username/Downloads/paket.bootstrapper.exe .
cp /Users/Username/Downloads/paket.exe .
Important: Now do cd .. to go back up to the /Users/Username/Library/Application\ Support/Sublime\ Text\ 3/Packages/sublime-fsharp-package-master/ directory.
Now instead of running /Users/Username/Library/Application\ Support/Sublime\ Text\ 3/Packages/sublime-fsharp-package-master/build.sh install, try running it as ./build.sh install. (And also try ./build.sh Install, since I'm pretty sure the capital I is necessary).
(BTW, If you're not familiar with the syntax that I used in steps 9, 10 and 11, where I used a single . or two dots .. in commands, those are a long-standing Unix idiom: . means "the current directory", and .. means "the parent directory".)
I just looked at the build.sh script that you've been running, and it seems to assume that you've done a cd into the package's base directory (the sublime-fsharp-package-master directory) before running the script. So that could explain why it was failing: you were running it from a different directory, rather than doing a cd first. Hence why I marked step 10 as important: I think that was the root cause of the problem.

Using ocamlmktop with ocamlbuild

I have a project that builds successfully using ocamlbuild. However, I would also like an easy way to interact with the project's individual functions from different modules via the toplevel but my attempts at using ocamlmktop haven't worked out as I'd like. I've found that unless I manually put the .cmi files in the active directory, I get an "Unbound module" error. The command I'm currently using to build is:
ocamlfind ocamlmktop -I _build -o my_ocaml -linkpkg -package str module1.cmo module2.cmo
Is there a better, less hacky way to get the toplevel to work in this project structure without moving cmi files out of the _build directory?
Edit: I've figured out that I can get it to load the types and modules if I run the toplevel as
./my_ocaml -I _build
But this still seems hacky. Is there a way to bake the search path or cmi files in perhaps?
Edit 2: I think the solution to my problem may actually be not to compile a custom toplevel at all given this restriction about interface files. I have instead added load directives to my .ocamlinit to use the modules. If anybody has better ideas to solve this, I'd greatly appreciate it.
You can build a toplevel by listing the module names you want in a my_ocaml.mltop file:
Module1
Module2
subdir/Module3
Then building the target my_ocaml.top will call ocamlmktop in the expected way, and you can run the resulting my_ocaml.top toplevel.
This does not change the way that you need to add _build to the include path for the type-checker to be able to find the .cmi files. You can do this when you invoke the toplevel by passing the command-line arguments -I _build, or from the toplevel with #dir "_build";; -- the last command can also be put in your .ocamlinit if you prefer.

OCaml - cannot install Core

My question is similar to this post:
OCaml: Can't run utop after installing it
I try to open the core library, and end up with the same problem:
$ open Core.Std
Couldn't get a file descriptor referring to the console
I have tried the following command with correct quote mark:
eval `opam config env`
But nothing happens and the problem persists despite I have installed core. I also tried to follow installation instructions on this webpage (https://github.com/realworldocaml/book/wiki/Installation-Instructions), but it does not mention this strange problem.
I am using Ubuntu 24 in virtual machine by Hyper-V on windows 8. Another question I want to ask is many webpages like (http://kwangyulseo.com/2014/03/04/installing-ocamlopamutopcore-library-on-ubuntu-saucy/) suggested to compile certain lines of command in ".ocamlinit file". But I do not know where to find this file and how to modify it in linux. I have been an windows user for most of the time in my life.
Sorry if the question's level is too low.
Oh, man. open Core.Std is not a bash command. You need to open OCaml toplevel (i.e. to execute utop or ocaml) and execute this command there. Probably it is not written explicitly in manual. If you see
#use "topfind";;
#thread;;
#camlp4o;;
#require "core.top";;
#require "core.syntax";;
It means that you should enter (or add to .ocamlinit) this by hand. I mean that you should enter # too. So, if you will use ocaml you will see two #. It's normal.
About OCaml init file. As you see they refer to it as ~/.ocamlinit. Character ~ means home directory in POSIX systems. So you will probably need some GUI text editor (gedit or kwrite, for example), create new file, put content there ans save it you home directory. N.B. POSIX systems have no concept of file extension, i.e. leading dot is part of file name.

Tkinter module compilation error - 2.5.2 needed

I have a decently long program that I have been trying to compile. I have tried py2exe and cx_Freeze, both seem to come up with this problem.
I used the following setup.py file to compile my program:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [
Executable('version_3_2.py', base=base)
]
setup(name='version_3_2',
version='0.32',
description='desc',
executables=executables
)
From running this using
python setup.py build
The executable is created.
From running the executable, i was given a traceback stating that
TclError: Can't find a usable init.tcl in the following directories:
C:/Python27/build/lib/tcl8.5
and a bunch of other directories
From adding all of the tkinter and tcl files and folers into a couple of those directories i get the next traceback from executing:
C:/Python27/build/lib/tcl8.5/init.tcl: version conflict for package "Tcl":
have 8.5.15, need exactly 8.5.2
version conflict for package "Tcl": have 8.5.15, need exactly 8.5.2
while executing
"package require -exact Tcl 8.5.2"
(file "C:/Python27/build/lib/tcl8.5/init.tcl" line 20)
invoked from within
"source C:/Python27/build/lib/tcl8.5/init.tcl"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list source $tclfile]"
I'm not entirely sure what to do. Several solutions like How to correct TCL_LIBRARY and TK_LIBRARY with py2exe and Py2exe with Tkinter have not worked.
Any Ideas?
You need to match exactly the libtcl8.5.dll (or whatever the name is on your system) and the init.tcl (and related files) because they are both part of the same Tcl installation. If you change one out, you must change the other as well. How exactly you've mangled your installation I'm not quite sure, but mangled it surely is. Also be aware that in Tcl 8.5 (and before), it's strongly advised to match the Tk version precisely to it as well; we relax this requirement in 8.6 but you're not using that…
(Note that this is different from the way that normal dependencies work in Tcl; typically a program will depend on a minimum API version, not an exact one.)
Since you've got a binary build of 8.5.15 in use, you might as well use the script files for that version too. I suggest getting the Tcl source distribution for 8.5.15 from SourceForge and grabbing the files out of the library directory in there. You probably only need the .tcl files directly in there (especially init.tcl of course!) and not in any of the subdirectories, as the subdirectories are for official add on packages and those aren't so tightly bound to Tcl versions.

How to install pony-mode for Django in emacs

I'm new to emacs and i would like to install pony-mode for django. I've been struggling with the installation instructions but I have not found a way to make it work. Do i need to byte-compile all the .el files? How do I do that? Are there any dependencies that need to be installed? I've managed to get the following error: pony-mode.el:83:1:Error: Cannot open load file: files-x. Can someone provide a full set of instructions?
I'm using emacs GNU Emacs 23.1.1 on ubuntu 10.04
I noticed that pony-mode is also available via package.el
I have package manager configured like so:
(require 'package)
(dolist (source '(("marmalade" . "http://marmalade-repo.org/packages/")
("elpa" . "http://tromey.com/elpa/")))
(add-to-list 'package-archives source t))
(package-initialize)
And then you should be able to run the package-install command and type pony-mode when prompted in the minibuffer.
It works just fine for me
git clone http://github.com/davidmiller/pony-mode ~/Development/pony-mode
M-x byte-compile-file (compile only pony-mode.el)
And then add to .emacs:
(add-to-list 'load-path "~/Development/pony-mode")
(require 'pony-mode)
Of course you would have to change the paths for yours... Be careful with the path in the load path function, no final / and no spaces
The error "Cannot open load file: files-x" is unrelated to byte-compilation.
There is a file included in GNU Emacs 'files-x.el' which is required by pony-mode in order to set dir-local variables for per-project settings.
This error most likely means that the variable `load-path' is set such that it cannot find files-x.el.
(/usr/local/share/emacs/23.1/lisp/files-x.el would be a good first place to look in your case.
C-h v load-path will allow you to inspect this variable.)
The installation instructions provided by #Fernando should work if your installation is standard