How to setup a webserver in common lisp? - linux

Several months ago, I was inspired by the magnificent book ANSI Common Lisp written by Paul Graham, and the statement that Lisp could be used as a secret weapon in your web development, published by the same author on his blog. Wow, that is amazing. That is something that I have been looking for long time. The author really developed a successful web applcation and sold it to Yahoo.
With those encouraging images, I determined to spend some time (1 year or 2 year, who knows) on learning Common Lisp. Maybe someday I will development my web application and turn into a great Lisp expert. In fact, this is the second time for me to get to study Lisp. The first time was a couple of years ago when I was fascinated by the famous book SICP but found later Scheme was so unbelievably immature for real life application.
After reading some chapters of ANSI Common Lisp, I was pretty sure that is a great book full of detailed exploration of Common Lisp. Then I began to set up a web server in Common Lisp. After all, this should be the best way if you want to learn something. Demonstrations are always better than definations.
As suggested by the book Practical Common Lisp (by the way, this is also a great book), I chose to install AllegroServe on some Common Lisp implementation. Then, from somewhere else, I learned that Hunchentoot seems to be better than AllegroServe. (I don't remember where and whom this word is from. So don't argue with me.)
Ironically, you know what, I never could installed the two packages on any Common Lisp implementation. More annoyingly, I even don't know why. The machine always spit up a lot of jargon and lead me into a chaos. I've tried searching the internet and have not found anything.
Could anybody who has successfully installed these packages in Linux tell me how you did it? Have you run into any trouble? How did you figured out what is wrong and fixed it? The more detailed, the more helpful.

Have you tried these instructions?
I already had a working SBCL installation so I've only followed the second half of the instructions. It sets up a very minimal web app, so it lets you see just how to structure your own web app.
These instructions might not be quite what you're looking for - they're for setting up a web server (on Ubuntu) with remote interaction with emacs/SLIME, but I guess "remote interaction" could just as well mean localhost.

Basically, these installation steps are from this article A Simple Lisp Webapp for beginners, recommended by Frank Shearar (thanks again). But I didn't follow the exact steps because (1) I'd like to install Common Lisp with a local user; (2) I am not familiar with a few things the author mentioned. You can check out the original article or you can just follow me here. I am afraid my instructions are much easier to follow. :)
Three packages need to be downloaded before installation. sbcl binary and source packages can be downloaded here, and smanek package can be downloaded here.
sbcl-1.0.38-x86-linux-binary.tar.bz2
sbcl-1.0.38-source.tar.bz2
smanek-trivial-lisp-webapp-3681c1
Note: The version number may have changed when you see this essay. So don't bother to get the exact packages. However, this is right packages working for me.
Here is what I do (replace YOURPATH with your real path and I assume you are using BASH):
1. Install the binary sbcl package
tar jxf sbcl-1.0.38-x86-linux-binary.tar.bz2
cd sbcl-1.0.38-x86-linux
INSTALL_ROOT=YOURPATH sh install.sh
cd ..
Well, the binary sbcl package has been installed now. When the install program complains with something like "no manual found", it is OK since the manual stuff is not included in the binary package. Let it be.
2. Set the PATH and SBCL_HOME
export PATH=YOURPATH/bin/:$PATH
export SBCL_HOME=YOURPATH/lib/sbcl/
3. Install the source sbcl package
tar jxf sbcl-1.0.38-source.tar.bz2
cd sbcl-1.0.38
sh make.sh
export SBCL_HOME=''
INSTALL_ROOT=YOUROTHTERPATH sh install.sh
cd ..
NOTE: You may need to specify another directory for installation, or it will be installed into the same directory the binary sbcl resides in.
4. Set the PATH and SBCL_HOME
export PATH=YOUROTHERPATH/bin/:$PATH
export SBCL_HOME=YOUROTHERPATH/lib/sbcl/
5. Install the smanek package
unzip smanek-trivial-lisp-webapp-36816c1.zip
cd smanek-trival-lisp-webapp-36816c1
cd scripts
./startserver.sh
When it says "Webserver started on port 8080", you can visit "http://localhost:8080" in your web browser. It is there, right?
6. A few notes
After putting the three packages in one directory, you can run the above scripts one by one or in a batch. Remember to replace the PATHs with your real paths.
I suspect Shaneal Manek has hacked the asdf and hunchentoot packages a lot, as I didn't find anything in the $HOME/.sbclrc and $HOME/.sbcl. Thank you, Shaneal Manek, you've helped a lot of people a lot.
I still feel hateful toward those who always says a lot but does a little. Even people are angry, it is still evident that it is what they say matters, not how they say it. Nevertheless, I was wrong to say something bad in a bad mood.

5 years later.
it very easy with quicklisp. I assume you have installed SBCL or other CL implementation.
Go to your REPL and evalute
(ql:quickload :aserve)
start AllegroServe
(net.aserve:start :port 8000)
publish some HTML files
(net.aserve:publish-file :path "/" :file "~/hello.html")
Go to http://localhost:8000/
Happy hacking!.
read more about Introduction to AllegroServe Tutorial

Paul Graham has, for starters :-)
I too have found Common Lisp a lot of work to get past step one. The environment is terrible when you're just getting started, there's not a clear One True Path to get to the point where you can bang in some code and see some results (like there is with Python, for example). Like you, I wasted a lot of time jumping from one implementation to another. So my advice is:
I suggest you just pick one and ignore all other advice until you get it going.
If you're not in the mood, just get Apache and write some PHP :-)

Related

log installed files when compiling

im currently building LFS and looking for a package management solution
specifically a program that keeps track of what files got installed when you compiled
something from source also has a method for removing those files in case make uninstall isnt present
i have looked into programs like install-log and checkinstall but couldnt get both to compile
any help is appreciated, thanks!
Personally, I have always used the User Based Management (aka "Package Users"), as described in section 8.2. Package Management. It doesn't get much love, even from the LFS community, despite it (still) being in the book and being the only method "unique to LFS".
It's not great for the first timer as it will really force you to dig deep at times to solve issues and make important decisions. I suggest you complete your first LFS system build, then consider Package Users your next time around.
But once you get used to it, it works great.
Another, simpler, method is the Timestamp Based technique (described in the same link).
For example, when it comes time to copy a package's files to your system, you can do something like this:
touch timestamp_start
make install
# do other stuff as instructed
touch timestamp_stop
find / -newer timestamp_start -not -newer timestamp_stop > list_of_files_affected
And I do use this approach when installing the Nvidia proprietary drivers, because successfully installing them with a non-root account is a real pain.

How to manage multiple haskell installations on macOS?

I have on my computer (macOS High Sierra) multiple installations of the standard (Glasgow) Haskell compiler. The oldest one (as far as I can remember) is a minimal installation, while I obtained the most recent version form the "Platform" installer, something like five or six months ago. I'm trying to get rid of the whole ecosystem (ghc, stack, cabal, and friends), mostly because I don't know what tools I will be using in the case I'll plan to get back using the language.
So my questions are:
Where does the minimal/"Platform" installer installs Haskell and all related stuff?
How can one remove the whole Haskell language and all its components mentioned above (in the case of a "Platform" install, and even in the case of a minimal installation)?
EDIT: I've just remembered of the uninstall-hs command (see also here), should I run this instead of removing files manually?
I think I have come up with a solution and I'll answer the latter question first:
All the details I was looking for (what effectively is installed after launching the minimal / "Platform" installer, and, most importantly, where these guys were placed) can be found in the documentation welcome file at /Library/Haskell/Doc/Start.html. More precisely:
On Mac OS X, the Haskell Platform is installed in two major pieces: GHC and Haskell Platform. They are installed respectively in: /Library/Frameworks/GHC.framework and /Library/Haskell. Executables are symlinked in /usr/local/bin [...].
There are also another two or three directories in the home folder, namely ~/.ghc and ~/.stack.
As said in the OP, the script uninstall-hs done its work, showing a (at least I hope so) comprehensive list of all the files that constitutes the Haskell "sdk" actually installed.
Feel free to post your answers, I hope this post will be useful to the community.

Is it OK to modify the default location for Python-3.6.0.exe to just the C drive?

I am a 65 year old "newbie" and generally use default options when downloading. Python.org wants to download to an obscure directory such as
C:\Users\Facdev\AppData\Local\Programs\Python\Python36-32".
Is there anything wrong with downloading instead to "C:"?
This should not pose a problem, as long as the directory is specified correctly in you PATH.
It is OK to modify the location where you will download and install Python. However, I would advise against doing so if you are unfamiliar with how system environment variables and PATH locations work in Windows.
Why does it matter?
Once you have the python executable (in your case Python-3.6.0.exe) on your system, your computer needs to know where it is in order to execute it! If you place the executable in a location like the main directory on the C: drive your computer does not care. Your computer also does not care if the executable is deep down in the AppData\ directory.
By changing the default behavior you run a risk when troubleshooting unexpected behavior that instructions will not be written for your situation. This is OK as long as you understand what you will need to change in order to apply the troubleshooting techniques listed on documentation, blog posts, and forums.
Because of those factors and this being a new process for you, I recommend sticking to the default. You can change the location later, once you understand what doing so means. Learning to program can be frustrating and trying to grasp managing the software environment only adds to the frustration. Tackle that issue later.
Good luck on your new adventure! I hope you learn to enjoy writing your own programs in python!

Installing GLPK (GNU Linear Programming Kit) on Windows

This could be an annoying question. But I was hoping someone could provide me with step by step instructions on how to get GLPK up and running on a Windows machine. I have Windows 7 64-bit.
I have tried looking at some instructions on various websites but keep running into problems. I am not very versed in creating directories, working with binaries (e.g. what is a binary), etc.... Even running commands is a little foreign to me.
To get an idea of what kind of detail I need in the instructions, here are some I have tried (and failed) to use:
http://winglpk.sourceforge.net/
http://en.wikibooks.org/wiki/GLPK/Windows
As you can see, I need something fairly detailed. I have read an example of a GLPK program in action, and I believe that once I get the program up and running I should be able to write the code to use it.
Can anyone help me? I would be so grateful.
EDIT: As a parallel question, I would also be interested in suggestions for other programs that will do the similar things as GLPK, but are more straightforward to install and use.
here an easy step-by-step explanation of "how to make glpk work":
To download GLPK , first go to the GLPK windows download page and then follow the instructions here from 1:
Go to control panel to determine whether you have 32-bit or 64-bit Windows (assume 64-bit from now on).
Download the latest version of GLPK, 4.65 at the time of writing, from the following address Sourceforge.
Extract the Zip folder by: right clicking on the folder and then>> 7-Zip >> Extract Here as shown. Move the glpk-4.65 folder from your downloads folder to your C: drive.
Assuming you’re using 64-bit Windows, click on the C:\glpk-4.65 folder in Windows explorer, click on the w64 folder, and select and copy the file path, which should be C:\glpk-4.65\w64.
Search and open your Control Panel, select System and Security>>System>>Advanced system settings>>Environment Variables. Then click on ‘path’ in the top window, click the ‘Edit’ button, then ‘New’.
Paste the file path you copied above and save.
DONE.
Here are a few suggestions to get you moving forward:
If you are having difficulty with running Windows command-line, then maybe GLPK (installing by yourself) is not the best bet.
See if you can find someone more experienced in Windows help you with the installation? (Once installed the LP modules are fairly easy to use, no more complex than any of the others)
Do you have access to any commercial solvers? (MATLAB and CPLEX can be great)
If you are going to be working with Windows for some time to come, it is a good idea to invest some time to learn how to download and install software
This SO question has links to lots of other LP/IP solvers such as Gurobi and COIN-OR.
If you don't mind learning a bit of R programming language, I'd recommend downloading R and RStudio, both of which are straightforward. Next, what you want is the lpSolveAPI package. The examples are decent and you can get going in a day or two. (You'll have to learn the basics of R)
If none of these help you progress, post some details of where you are getting stuck in the GLPK download (post the errors you are getting) and someone will try and assist you.
Hope that helps
In my opinion, it would be way easier for you to install e.g. ubuntu, especially if you are interested in other GNU programs. You can use every open-source program on windows, but it will not be easy if you don't understand what is a "search path for binaries"...
Installing softwares and libraries on windows is not easy, which is why windows program usually come with a setup.exe installer that does everything for you (but GNU programs don't).
On the other hand, ubuntu has a beginner-friendly documentation, and once you have installed it on your computer (it won't take you more than 2 hours at most, and 10G of disk space), installing GLPK or any GNU program is pretty straigtforward (just type sudo apt-get install glpk on the command-line).
There is no drawback in having the two systems on the same computer (except for the small amount of disk space used), and getting to know another operating system will certainly teach you more than following any step-by-step guide anyway.
That would be my "general advice". Now if you just want help on how to install glpk on windows, please post more details about what "doesn't work" for you (where did you "failed" to use those instruction? what happened?) because I don't think you can find something more detailed than the second link you posted.
have you set the PATH correctly once you have unziped the files?
To check it, run the cmd.exe and put "echo %path%", if in the list does not appears your glpk folder then you are unnable to execute it right since windows does not find the glpk executables.
more info:
http://en.wikibooks.org/wiki/GLPK/Windows_executables
https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them

How to get started developing on *nix

Is there a good 'how-to' or 'getting started' guide for getting started using g++ and gdb?
Some background. Decent programmer, but so far I have done everything on Windows in Visual Studio.
I have a little experience using terminal to compile files (not much beyond a .h and 1 or 2 .cpp). But nothing beyond that.
Anyone know of a good primer on on how to get started coding on Linux?
Read some good books, notably Advanced Linux Programming and Advanced Unix Programming. Read also the advanced bash scripting guide and other documentation from Linux Documentation Project
Obviously, install some Linux distribution on your laptop (not in some VM, but on real disk partitions). If you have a debian like distribution, run aptitude build-dep gcc-4.6 gedit on it to get a lot of interesting developers packages.
Learn some command line skills. Learn to use the man command; after installing manpages and manpages-dev packages, type man man (use the space bar to "scroll text", the q key to quit). Read also the intro(2) man page. When you forgot how to use a command like cp try cp --help.
Use a version control system like git, even for one person tiny projects.
Backup your files.
Read several relevant Wikipedia pages on Linux, kernels, syscalls, free software, X11, Posix, Unix
Try hard to use the command line. For instance, try to do everything on the command line for a week or more. Avoid using your desktop, and possibly your mouse. Learn to use emacs.
Read about builder programs like GNU make
Retrieve several free software from their source code (e.g. from sourceforge or freecode or github) and practice building and compiling them. Study their source code
Basic tips to start (if a command is not found, you need to install the package providing it) in command line (in a terminal).
run emacs ; there is a tutorial menu; practice it for half an hour.
edit a helloworld.c program (with a main calling some hello function)
compile it with gcc -g -Wall helloworld.c -o helloworld; improve your code till no warnings are given. Always pass -Wall to gcc or g++ to get almost all warnings.
run it with ./helloworld
debug it with gdb ./helloworld, then
use the help command
use the b main command to add a breakpoint in main and likewise for your hello function.
run it under gdb using r
use bt to get a backtrace
use p to print some variable
use c to continue the execution of the debugged program.
write a tiny Makefile to be able to build your helloworld program using make
learn how to call make (with M-x compile) and gdb (with M-x gdb) from inside Emacs
Learn more about valgrind (to detect most memory leaks). Perhaps consider using Boehm's GC in some of your applications.
You've got a lot of things to learn. I won't give you details, but as someone who's done unix and c/c++ development for a couple decades now I'll try to give you some topics to start with.
My main advice is to start experimenting. Write the most trivial program you can in C or C++ (something that prints "Hello there, world!" is traditional) and figure out how to compile and run it from the command line. Then, once you've got a compiled version, start it up under the debugger and play around with breakpoints, printing expressions, etc, etc. Once you've got this simplest program up and running and you sort of understand what the debugger is telling you, add a class, function, struct, or whatever else feels like a good small step and go through the cycle again. You'll proceed much faster this way than if you start with a very large program.
Still at a very high level, here are a handful of topics you'll need to figure out at least a bit about. Note that the "learn by starting small" approach works well for any of the topics below.
Running g++: it has pretty good online documentation for the command line syntax, and although you're bound to find it intimidating at first, try to look for the simplest starting point.
Find a text editor to use. Vim and emacs are traditional (and very very powerful) but both have a relatively steep learning curve. If you have someone around to help you, that's so much the better. There are other alternatives, but as an emacs user myself, I'm afraid I'm not that familiar with them.
Get familiar with gdb. It's an incredibly powerful tool for understanding your program. Again, it has extensive online documentation that will repay close reading.
Some familiarity with standard unix commands will be useful: ls, cd, and moving basics of the navigating unix directories; grep for quickly searching source files.
You'll have to get used to the command line approach versus the ide approach. The former is the traditional unix developer model, where you put together the operations you want from a collection of other tools, rather than having the ide hide most of this knowledge from you.
If your project is multi-file, and especially if it's a full-semester project, you might also consider learning something about the following topics.
Make is a tool for describing how to compile and link a multi-file project so that you don't have to remember how to do it by hand each time. Make, unfortunately, has a well-deserved reputation for being tricky to use, but this is mostly true in very large projects spanning multiple directories, and there are probably good simple examples online.
I would strongly consider making use of a source code control system such as git or hg, even for a few relatively small project. It's so much safer to have an archived version of what you've done so that you can back up quickly. Both git and hg are overkill for a small one-shot project, but they are worth learning on their own. Conventional wisdom as I understand it today is that they're very similar in philosophy and core functionality, but that hg is definitely a bit more consistent at the command line level, and therefore easier to start with.
I suspect this is rather intimidating, especially if you've got effectively no exposure to a unix command environment before. I re-emphasize my first piece of advice above: learn by starting simple and experimenting. This minimizes the amount of new stuff you're having to wrap your head around at any given point in time.

Resources