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.
Related
I have built a C++ cross-platform application and am struggling with how to get it to work correctly on macOS.
So far, I'm able to run the application manually with the command open /Applications/myApp.app --args /path/to/myFile.ply.
I have associated all ply files with my application but when I double click on it in the finder, the file path is not in argv argument list.
How can I get the double-clicked file path in my application?
You'll need an event loop, normally done using the NSApplicationMain function. Then you need to receive an Apple Event telling what file(s) to open. It will be much easier if you are willing to use some Objective-C or Swift, rather than pure C++. In Objective-C, you'd make an object that conforms to the NSApplicationDelegate protocol and that implements a method application:openURLs: or application:openFile:.
#JWWalker has explained how to solve your problem by altering your code to cope with the macOS GUI environment. Here is a different approach which avoids messing with your C++. Pick the one that suits you needs best.
If your cross-platform application is designed to run from the shell prompt you might want to run it within the macOS Terminal app. You can do this using a small AppleScript application which accepts the file paths passed by the Finder and invokes the Terminal app to run your C++ code.
To do this open Script Editor, you will find it inside Utilities in Applications. Enter the following:
on open passedItems
set convertedPaths to ""
# convert passed macOS paths to posix paths
repeat with nextItem in passedItems
set posixPath to the POSIX path of nextItem # convert macOS alias to posix path
set convertedPaths to convertedPaths & " '" & posixPath & "'" # place in quotes to protect any spaces
end repeat
tell application "Terminal" # open (if required) and activate Terminal
activate
do script "echo " & convertedPaths # just run echo - use the path to your C++ binary instead
end tell
end open
If you can program in C++ you can probably figure that out, if not search for AppleScript and all will become clear.
Now save this as an application, for this demo it was saved in /tmp/bridge (aka /private/tmp/bridge on macOS) as "Bridge.app".
Now create some test files with a suitable extension, e..g something like:
$ cd /tmp/bridge
$ touch a.bridgeDemo 'b c.bridgeDemo'
From Terminal you can open /tmp/bridge in a Finder window using:
$ open /tmp/bridge
In the Finder select any of your test files, do a Get Info and set the file to open with Bridge and then hit Change All...
Now try it: select the test files in the Finder and open them. You should see Terminal open/activate and show you something like:
$ echo '/private/tmp/bridge/a.bridgeDemo' '/private/tmp/bridge/b c.bridgeDemo'
/private/tmp/bridge/a.bridgeDemo /private/tmp/bridge/b c.bridgeDemo
$
Now edit the AppleScript to run your compiled C++ instead of echo and save it in a suitable location. HTH
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
I am very new to Clojure and am following Clojure for the Brave and True. One of the steps is to create ~/.lein/profiles.clj . I cannot find how I am supposed to do this so any help would be much appreciated.
Thanks in advance
From your question, I take it that you are a) on a Linux system and b) do not yet know your way around Linux. Is that correct?
If so, there are a few things, you should know:
Filenames beginning with a dot are hidden. You can not see them in normal file listings. All graphical filemanagers have a switch somewhere to show hidden files. If you are typing in a terminal, you can use the -a option of the command ls to show them. Compare the output of ls ~ and ls -a ~on the command line. You can usually get a command line if you start a "terminal" or "console" from menu.
You can create directories on the command line with mkdir. In this case you would call it like this: mkdir ~/.lein on the command line.
You can then use one of the many, many text editors to create and edit the profiles.clj file. For example, on the command line call gedit ~/.lein/profiles.clj to open a graphical editor. It should be installed on most systems. If you do not have a graphical user-interface, you could try the editor nano instead of gedit
If you are on a Windows box, all these instructions make no sense. In that case, I cannot help you much as I have never run Clojure on Windows.
If you are already an experienced Linux user and I just misread your question, I beg your pardon for stating the obvious.
I use open_in to open a local file with its path:
let f = open_in "/Users/SoftTimur/file.txt" in
...
Now, I would like to open a downloadable file with its URL:
let f = open_in "http://caml.inria.fr/distrib/ocaml-4.02/ocaml-4.02-refman.txt" in
...
returns an error Fatal error: exception Sys_error("http://caml.inria.fr/distrib/ocaml-4.02/ocaml-4.02-refman.txt: No such file or directory").
Does anyone know which function I could use to open such a downloadable file? Do I have to first download it to local (how to do that by OCaml?)?
Well, there are plenty of libraries in OCaml that can deal with http protocol in particular and with network communications in general. None of them will provide a function of type string -> in_channel as the in_channel type is an abstraction owned by OCaml. The language doesn't allow us to create our own implementations of the channel type1.
The libraries, that I know and used are:
cohttp - asynchronous library for http client and servers;
ocurl - a binding to the libcurl;
ocamlnet - all things network and even much more;
Presumably there are others, please feel free to edit this answer and add them.
I personally prefer asynchronous monadic cohttp, but it is easier to start with ocamlnet, that is also an excellent library, that has lots of features. This is how to play with it in the OCaml toplevel:
# #use "topfind"
# #require "netclient";
# module Client = Nethttp_client.Convenience
# let ocamldoc = Client.http_get "http://caml.inria.fr/distrib/ocaml-4.02/ocaml-4.02-refman.txt";;
Before starting the playing, make sure that you installed it with
opam install ocamlnet
Footnotes:
at least in pure OCaml, it is possible to create it from C, but I doubt if someone will pursue in this direction, it doesn't worth.
In Ocaml this is an C fopen call, no way to do it with a http source scheme.
You will have to download the file first, use one of the usual download tools wget or curl which are used in your linux package manager as well. Sys.command is your friend to do this.
It would be not too hard writing a module that checks the file name for a "schema:" like prefix, and taking appropriate action.
Maybe look at the opam sources for inspiration?
Does anyone know which function I could use to open such a downloadable file?
Install the wget program for your Linux distro and use the Unix library when you compile and you can use:
let open_url_in = Unix.open_process_in("wget -O - " ^ url)
This runs the wget program with -O o asking it to output the downloaded file to stdout which open_process_in reads into your process as the resulting channel.
Do I have to first download it to local (how to do that by OCaml?)?
No.
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