How to Open a Web Server from Running an Executable? - racket

I've been toying with the idea of using my browser as a GUI instead of using the GUI package provided by Racket.
The code is as follows:
#lang racket
(require web-server/servlet web-server/servlet-env)
(define (start req) (response/xexpr "Goodbye, World!"))
(serve/servlet start #:port 8080 #:servlet-path "/")
When I run this in the IDE, it works just fine. But when I try running this from an executable, it just runs and doesn't open a browser window. How do I get this program working in executable form?

I figured out the problem. There was a problem with the machine I was running it on. My program runs on all other systems just fine.

Related

"Hot" Debug and Swap in Common LISP

One of the features that are unique to Common Lisp that is frequently mentioned is that of the "hot" debug. That is, it is the ability to debug, edit and recompile the production code without stopping or taking the latter off line.
While I see this mentioned all the time, I have yet to see a tutorial on how to do it.
How does one do it in, say, Emacs? Are there some simple examples? Is the feature truly as magical as it seems?
The typical way to do this is to enable SWANK in the application that you want to debug. That way you can use M-x slime-connect from Emacs to connect to the running server. From there, you can do anything you can do with a normal SLIME session. You can even set up the way file names re resolved so that when you use M-. to jump to the source of a function, it will be opened on the remote machine using Tramp.
I think the reason you haven't seen a tutorial on it is because it's a natural thing to do, and there really isn't much of a difference between doing local debugging and working on a remote system.
There is a video of a lecture I did once where I demonstrated some of this, so there definitely are videos out there. However, I think linking to external videos is frowned upon on Stackoverflow.
Some notes I took for myself. I largely agree we should have a tutorial out there. In the CL Cookbook ?
(edit: there's now a more complete example here)
Reading http://readevalprint.tumblr.com/post/101841449553/its-alive-the-path-from-library-to-web-app
Another option is hot swapping all the changes. For this purpose my hunchentoot server also starts a swank server like this:
(defun start-app (&optional (port 8080))
(handler-case (swank:create-server :dont-close t)
(error ()))
…
Swank is, of course, the server-side component of SLIME. It runs on a port that is not accessible remotely and can only be connected to locally or via SSH tunnel. I use the latter to connect SLIME on my PC to Swank running on my server, which allows me to apply various fixes without restarting, either from the REPL or by using C-c C-c to recompile some function.
Connect to a remote Slime server:
Install a Common Lisp implementation on the server. (E.g. sbcl, clisp, etc...)
Install quicklisp on the server.
Load SWANK with (ql:quickload :swank)
Start the server with (swank:create-server). The default port is 4005. [On your local machine] Create a SSH tunnel with ssh -L4005:127.0.0.1:4005 [remote machine]
Connect to the running remote swank server with M-x slime-connect.
The host should be 127.0.0.1 and the port 4005.
(reading an old SO doc page, impossible to link to now).

How To Run Lein Ring Server Command From Eclipse?

I'm trying to figure out how to run lein ring server for a Clojure Ring and Compojure application in Eclipse Mars with Counterclockwise on Windows.
I've added the correct dependencies to my project.clj file. Running this command from a command line works without any trouble.
However, if I type it into the repl inside eclipse I get the error : "CompilerException java.lang.RuntimeException: Unable to resolve symbol: lein in this context"
Is there a way to run lein ring server from within Eclipse?
I'm very new to Clojure development and hoping I'm just missing something simple here.
You can run lein commands like this http://doc.ccw-ide.org/documentation.html#lein-generic-launcher .
Trying to run lein commands in repl is wrong as leiningen is build tool, and works like any other console program.
If you want to start ring server from repl you can, to do that you need to switch to namespace where you start ring server and start it, by evaluating server start code in repl. It's described at ring wiki https://github.com/ring-clojure/ring/wiki/Getting-Started , in the pretty much like this
(run-jetty handler {:port 3000})
Also I suggest to take a look at https://github.com/plexus/chestnut (app template) so your start server from repl will look like this
(run-web-server)
assuming you have method like this
(defn run-web-server [& [port]]
(let [port (Integer. (or port (env :port) 10555))]
(println (format "Starting web server on port %d." port))
(run-jetty http-handler {:port port :join? false})))

connect multiple different terminals to the same slime instance

I am still a novice when it comes to working with emacs and slime.
I was wondering if there is a way to start a lisp (say SBCL) on a local port and then connect multiple different slime sessions to it?
For example, if I am using tmux/screen and want to have different emacs sessions between each window, would I be able to connect all the slime instances to the same lisp so that all the emacs sessions were sharing a repl allowing me to compile in any of the emacs sessions and the one running repl will have those changes?
I am using LispWorks 6.1 32 bit Professional Edition. I prefer to use (Spac)emacs for my editing in multiple tmux sessions, one session for each project that I work on.
These are the steps I follow:
Start LispWorks Listener REPL.
Load swank without going through the emacs route:
(load "/path/to/swank-loader.lisp")
(swank-loader:init)
(setf swank:*use-dedicated-output-stream* nil)
(swank:create-server :port 4005 :dont-close t)
Then in my iTerm tab with tmux session for some project 1, I do M-x slime-
connect and connect to host and port as in step 2.
Repeat step 3 for another tmux session with another lisp project code.
With this setup I can load code from multiple projects I am working on in the same lisp image. So far I have not found any major problems while doing so.
This depends on the lisp system you're using, on the features it supports, i.e. whether your SBCL has multi-threading enabled (cf. (member :sb-thread *features*) and on the setting of SWANK:*COMMUNICATION-STYLE*, cf. the Slime docs.

What is the correct way to use emacs/cider while developing a compojure/ring-based application?

What is the correct workflow/pathway of usage of emacs/cider while developing
a compojure/ring-based clojure application?
I feel that I can "attach" to my running compojure/ring-process,
change its code, read/change its data, but I can't understand how do I do it right?
What is the correct way?
What I do?
lein new compojure my-project
cd my-project
lein ring server-headless
The development server runs now. If I change files in the projects they will be automatically reloaded. That is good. But what I'd like to have is that I attach
direct to the process and change its functions for example.
I understand that it is possible, but I can't understand how.
I don't know about correct but I'll throw in my 2 cents.
I start my ring project using immutant which starts a REPL at a specified port. I start cider with M-x cider and connect to the previously specified port. From there I can modify things from the REPL.
I've also seen other people start jetty from inside the REPL though I've never tried this.
There are two main ways of doing what you want. None of them are specific to ring servers, or even to webservers, they'll apply to any Clojure Project.
Both of the methods below should give you a fully functional REPL, with complete control to redefine the functions in your running server, and full CIDER functionality (like being able to debug web-requests to the server).
As usually with CIDER, you can reload changed files with C-c C-k, which will redefine any functions you've changed. There are plenty of other keys for more fine-tuned evaluations as well.
M-x cider-jack-in (or C-c M-j)
As documented on the manual this starts a process with your project and connects a REPL to it. This won't call any functions for you (CIDER doesn't do that), but you can easily start your webserver by calling the corresponding function in the REPL. If the function in question is the -main function, you can do M-x cider-run to call it (bind that to a key if you'd like).
M-x cider-connect
Also as documented on the manual, you can start your webserver from the terminal like you normally would, and then call M-x cider-connect to open a REPL in it. (This is what I used to do a while back).
A bit late to the party. But as I have just to deal with the same issue and found this unanswered question. The answer could be found at:
lein ring server with nrepl doesn't honour cider-nrepl
Basically, use the plugin version 0.9.2 of lein-ring and add to the :ring configuration on project.clj :nrepl {:start? true} and it works

Emacs with Slime and Swank for non-leiningen projects

I found this website which explains how to use emacs with leiningen, swank, and slime. Is there a way to use slime + swank in non-leiningen projects i.e. how can I connect to slime/swank repl to run a ad-hoc Clojure script while I write it as demonstrated here?
You need to have swank-clojure.jar in CLASSPATH and your script should have following code:
(require 'swank.swank)
(swank.swank/start-repl 4005)
to start swank process on port 4005 (or some other)...
P.S. You can look onto Incanter's swank script, that pass this code in environment variable, and later it evaluated as part of boostrap script