Running a 'Hello World' app in Agda emacs - emacs

I installed an Agda compiler, binarys can be from here: http://ocvs.cfv.jp/Agda/how-to-install-windows.html
... and I'm trying to make it compile a simple hello world app (I found the Agda 'Hello World' code online)
But I've never used Emacs before, and I don't know where to begin, or which commands to use to compile and run. I'm new to Agda, which seems to have limited options for compilers, and is lacking any step by step tutorial. Below is a screenshot of the Emacs compiler with the code I found:
open import System.IO using ( _>>_ ; putStr ; commit )
module System.IO.Examples.HelloWorld where
main = putStr "Hello, World\n" >> commit
I'm looking for step by step instructions to run a simple 'Hello World' program
A working example with another compiler would also be an acceptable answer
Thanks!

This looks like you attempted something like the general M-x compile rather than any specific Agda functionality.
The Agda:run mode indicator in the Emacs mode line suggests that you have a running Agda process in another buffer, but you're not looking at it. The Agda mode probably has something like agda-eval-buffer which should pass your current program to that process, and bring up the results in the lower half of the pane. (Try switching to a buffer called something like *inferior-agda* manually if you somehow cannot reach that buffer by other means.)
The site you link to says it's Agda 1 and you should probably actually look for Agda 2 on a different site.
Below the line is my original answer, which may still provide some useful insight.
The error message indicates that you need to install make.
I'm guessing there may be additional missing dependencies after you fix this one. Ideally the documentation should explicitly specify exactly what you need to install.
make is just a wrapper to run whatever cormands are found in the local Makefile. If there is no such file, you will probably want to change the compilation command to something else. (Typically Emacs asks you for a command to run, but supplies a plausible default.)

Given I am running on Linux and am no agda expert, this solution might not be worth it. But still I will give it a try.
When I installed agda and agda-stdlib on my system, it provides me with a file called agda2.el in /usr/share/agda/emacs-mode. That said I just had the following in my ~/.emacs.d/init.el file:
(load-file (let ((coding-system-for-read 'utf-8))
(shell-command-to-string "agda-mode locate")))
Since, you already have agada mode setup in Emacs the above wont be useful unless your version of agda mode is old.
We can compile the current file you have opened in Emacs using M-x agda2-compile. Doing this will open up another prompt asking you for a Backend. I used GHC as input and it compiled it. Yes, and I got some errors I don't know how to fix. So, I queried on a search engine and came up with:
module memo where
open import IO.Primitive using (IO; putStrLn)
open import Data.String using (toCostring; String)
open import Foreign.Haskell using (Unit)
main : IO Unit
main = putStrLn (toCostring "Hello, Agda!")
I need to point out that the first line module memo where should be same as the filename which for your case is memo.agda.

I now have a hello world program running on my machiene.
The following code compiles and works
open import Common.IO
main = putStrLn "Hello, world, strings working!"
is the code, stored in the file 'hello.agda', which I compile in emacs to 'hello'. I compile in emacs by selecting agda > compile, an option that is available on emacs when agda is installed correctly.
I can't give a detailed tutorial as to how to install agda on emacs as a friend did it for me, but the above code works, and compiles on emacs on linux, which is the set up which is working for me.

Related

How can I print the output of each line in an .ml file

I have an .ml file and I want to be able to run it line-by-line as if I was typing it in the top-level ocaml interpreter
The problem is, if I simply type "ocaml file.ml" in the terminal, I don't get the output from the REPL, and I can't debug and compile it, since it contains the #use directive.
I've tried using several different extensions for Visual Code, but none of them worked for me.
Is there anything I can do to simply be able to run the file and get the output from the ocaml REPL?
Thanks.
I never used VS Code (if you are referring it as 'Visual Code'), but SLIME in emacs or its Vim version of it is probably what you want.
Based on that, I tried searching for an VS Code extension that does works like SLIME: SendToREPL.
(Disclaimer: the author claims it works for Python, Node, and reply (not sure what it is though), but I am quite confident that it will work for OCaml REPL/UTop.)

"illegal terminating character after a colon: #\" in portacle, though no colons in code

I've recently set up Portacle 1.3 for learning common lisp on Win 7. However, whenever I run my code I get the error, even if there is no code.
Running individual lines works fine, however. The error only shows when I run the whole file.
I tried putting some code in an EVAL function, but I believe that only accepts one argument at a time, so I couldn't run a whole program in it.
I've found a similar error in this stackoverflow page, but their code contains colons and that's where their error lies.
I think it might be an error in the code that runs mine, seeing as I get the error even if I compile with no code, however I know nothing.
The full error:
main.lisp:1:1:
read-error:
READ error during COMPILE-FILE:
illegal terminating character after a colon: #\
Line: 1, Column: 13, File-Position: 12
Stream: #<SB-INT:FORM-TRACKING-STREAM for "file [path to file]\\main.lisp" {1005F5F0D3}>
Compilation failed.
Portacle is a standalone Emacs packaged with everything needed for Common Lisp development and which uses SBCL as the Common Lisp implementation.
I believe what you do when you say 'compile the whole file' is call slime-compile-and-load-file which is bound to the key sequence C-c C-k by default. There are a lot of moving components here:
Emacs is the text editor here. It also takes care of launching all the necessary components for Common Lisp development.
Slime is one such component. It serves as interface between Emacs and your Common Lisp implementation (SBCL in this case, but supports any Lisp in theory). Basically it sends the code you wrote in Emacs to your Lisp for evaluation.
SBCL is the Common Lisp implementation. In this case it is a compiler. This is what evaluates the code it receives and spews out the answers to the user interface in Emacs, through Slime. It also 'lives', in the sense that you interact with it by modifying the state of the loaded Lisp image, keeping track of defined functions, global dynamic variables and much more. This is why you can have the REPL, and why you need Slime to interact with it.
So to debug your problem, I would try to:
Launch SBCL from the Windows shell and run a simple .lisp file to check that everything works. You can put for example (format t "~a" (lisp-implementation-type)) in a .lisp file and run it in SBCL from the shell by calling (load "...\\file.lisp"). It should return "SBCL".
Create a completely new file using Emacs (and not weird Windows programs that could mess up the files) (C-x C-f), and try to call the compile from there (C-c C-k).
And I believe you made the right choice of IDE. Portacle is arguably the simplest tool out there if you are a total beginner in Common Lisp and do not know Emacs configuration. The keybindings are a bit daunting though.

How to generate and set up annotation for Ocaml in Emacs?

I am writing a compiler in Ocaml with Emacs. I am told that with -annot a file .annot could be generated while compiling, which could help Emacs to show the type of my code. But it is odd that no .annot is generated after running this makefile. Could anyone tell me what is wrong with that?
Also, once i have got .annot, do I need to set up anything (for instance .emacs?) so that my Emacs read it and show the type of my code?
Thank you very much!
Edit1: after make clean and make, I have got the .annot... But I still do not know how to make use of this .annot in Emacs.
Edit2: actually it is necessary to follow this link, copy the files in a local folder, then update .emacs. Then when a .ml is edited in Emacs, C-c C-t returns its type from .annot.
Regarding your emacs inquiry --I don't use emacs--, this is from the man-pages for ocamlc,
-annot Dump detailed information about the compilation (types, bindings, tail-calls, etc). The information for file src.ml is put into file src.annot. In case of a type error, dump all the information inferred by the type-checker before the error. The src.annot file can be used with the emacs commands given in emacs/caml-types.el to display types and other annotations interactively.
There are also other tools from the thread I mentioned previously.
As for the Makefile not creating the .annot files, I made a mock directory and successfully had .annot files created. I also don't see anything wrong with your Makefile. You may want to clean the directory and try again, or switch to another way to build your tool like ocamlbuild --which would require minimal setup, although, I haven't used it with menhir.
I will also note that -annot is new since OCaml 3.11.0, and prior the flag was -dtypes.

Get code from REPL

If I'm entering code into the REPL using clisp, as in the program you get when you do sudo apt-get install clisp, is there a way to take all the code you've entered so far and save it in a file? I'm a Lisp beginner so I don't know if that's a ridiculous request or not.
You can start output recording with the function DRIBBLE.
Other than that I would run CLISP from a terminal program which can save input / output.
As the minimum I would usually use Emacs, run a shell via M-x shell and start the Lisp there. That way the I/O goes into an Emacs shell buffer.
There is also SLIME, which sets up quite a bit more functionality inside Emacs to communicate with a 'slave' Common Lisp. A 'listener' (aka REPL) is part of that.
There is probably a better way, but... If you are using a decent terminal program, you should be able to select the text in the terminal and save it to file. This would include your typed input as well as output, so you would have to manually remove the output.

How do I connect a clojure source file to a running clojure repl on Emacs?

I'm currently in the process of adding functionality to an existing J2EE webapp, in a Tomcat container, and I'm writing my additions using Clojure. My setup is simple: I just add calls to static methods generated by clojure, and code all the hard work from the clojure side. The build process consists in compiling clojure code (lein uberjar) and then compiling the java code with that jar on the classpath.
In the webapp init, I have a call to a generated class that fires up a swank server with a (swank/start-repl). I'd like to be able to connect my Aquamacs' slime to that server, and work interactively from there (up to a point, I won't try nothing that requires a java-side recompilation). But I have a situation that I don't quite understand. If I do a \M-x slime-connect, I get a REPL prompt (after being notified that there's no inferior lisp process, which I think it's ok, since the inferior lisp process is running outside emacs control). I can evaluate forms perfectly, and I can even inspect things like my.own.namespace/my-var. However, if I visit a file with an already compiled clojure code, I can't seem to make slime recognize it as its source. Consider a simple clojure file:
(ns my.namespace
(:gen-class
:name my.namespace
:methods [#^{:static true} [testFunc [] void]]))
(def *secret* "shhhh")
(defn -testFunc []
(println (str "our secret is: " secret)))
Assuming that this was compiled and included in the uberjar loaded by the webapp, I can eval/inspect my.namespace/*secret*. But If I try to eval inside the code buffer, Slime thinks I'm on the user namespace (which can even make sense!). But now I'm left with a single working option - I have to evaluate - one by one, all the forms in the file! \C-c \C-l (loading the source file) won't do nothing - apparently just returns nil and outputs nothing else. Compiling everything seems to do just that - it compiles, shows errors if it finds them, but won't change my namespace. And the strangest is the \C-~ (sync package and directory), which using Common Lisp it does just what I want, but here it freezes the clojure REPL for good.
There's always the option of switching to the REPL, typing (in-ns 'my.namespace), and then all works properly. But that simply isn't practical enough when the clojure files are growing in number (as the namespace of the code buffer won't change automatically!)
My question is, then, whether I'm lacking a basic command/configuration - or if there's an obvious reason for this behavior to happen as such.
I may be misunderstanding your problem, but can't you (while visiting this hypothetical buffer in emacs), hit C-c C-k to compile the buffer in your current Clojure instance (what Slime is connected to)?
Then, in the Slime buffer, switch to this namespace with a (in-ns 'my.namespace). Then you should have access to what you compiled in that namespace.
Switching namespaces automatically on compile has never been the default for swank-clojure, though it might be an optional slime feature that happened to work with Clojure. But C-c M-p to switch the repl to the current buffer's namespace has always worked for me, and I've never heard of anyone having trouble with it.
Are you running on the latest stable versions of clojure-mode and slime-repl? Do you have swank-clojure.el installed? (You shouldn't need it.) It sounds like this could be due to mismatched versions of the elisp libs. If that's not the problem it could be an Aquamacs bug; swank-clojure is designed to work with GNU Emacs. It could also be a bug in slime if you are running from trunk rather than the latest elpa release.
I've just found out that removing the culprit for this issue: slime-redirect-inferior-output, from slime-repl.el, was being called from a hook I had setup. It turns out that it doesn't play well without an inferior-lisp-process (read, a swank server started from within emacs).
So a quick workaround hack is just to remove the error form from that function, like this. Now the hook proceeds, and the namespaces are automatically calculated. As intended. Thank you for the suggestions, nevertheless - they led me to this solution!