SICP with DrRacket - racket

Does anyone have experience with http://www.neilvandyke.org/racket-sicp in class? Is it mature enough?

There is another version of the library on the new package server. I think it's based on Neil's version, but it does have more recent updates. You can find it by running:
raco pkg install sicp
Or in DrRacket by going to File -> Install Package... and typing in sicp into the box and hitting install.

I am currently doing the last few questions of Chapter 2 and till date I have used Racket + Emacs(with racket-mode, because I could get it running quickly) for all the code. The only exception was the section "A picture language" -- for which I used the SICP package in order to save time.
If you have not started, I'd recommend you pick Dr. Racket for now. The introductory section of the book will anyhow get you up and running with Scheme, and if you do encounter any issues in the later chapters, then you'll have enough knowledge to fill the gap and create your own workarounds.

Related

Guidelines on structuring large racket project

Is there any general guidelines (equivalent to How to Write Go Code ) on how to structure large racket project ?
Your question is about structuring large Racket projects, however your example link How to Write Go Code seems mainly to be about how to create a package. These aren't necessarily the same thing (although you might divide a large Racket program into different source directories, which could be "collections" or "packages"). Anyway, to address both parts:
How to structure a large Racket project: Asumu's answer provides a good link: How to Program Racket. In particular see section 3, "Units of Code", which discusses modules. Also, one technique you will see in the source code of Racket itself, is that a module may exist solely to require functions from others and provide them -- to "re-provide". In other words you can use modules like this to chunk up other modules and selectively expose them as a "layer" in your structure. Furthermore, Racket has a class system if that fits your problem domain, and generics if you have some sort of "interface" or "protocol" strategy. And more. Really, there a many, many techniques available in Racket to structure a large project.
How to make Racket packages: This is an interesting time to ask. Historically Racket has used something called Planet as a package manager. More recently, it has a new package system. Although not yet officially out of beta, many people are already using it for real work. The current documentation for that, although in a different style than the Go doc, is Package Management in Racket Beta).
You asked for general guidelines, which is a bit open-ended. If you have any specific choices you're weighing for how to structure a large project, perhaps you could ask about those one by one to get crisper answers?
There is a Racket style guide called How to Program Racket that will ship in the documentation of a future version of Racket. You can read it at the link I posted or in the bundled docs if you build the git version of Racket.

Install and use LISP on Mac

I've read many topics regarding this issue, but couldn't get it to an end. I want to be able to code in LISP on Mac, using Emacs and XLispStat.
So far, I've installed Emacs with HomeBrew but I got stuck when installing XLispStat. Can someone detail the steps for doing this? I'll appreciate!
P.S.: This is the required installation for Lisp. If there is something easier to achieve on Mac, I'll try that as well!
I posted a similar answer on this question. Short version: your options for an OS X Lisp environment are LispBox, LispWorks personal (crippleware warning) or Emacs+SLIME via quicklisp/ELPA.
Since your comments imply that you're casting a pretty wide net for workable Common Lisp tools, I'll also mention that CLISP seems to be supported via various OS X ports/package managers and has a fairly comfortable REPL (you can, of course get the same in SBCL with Linedit).
EDIT: As Rainer and Vsevolod mention below, Clozure and MCLIDE also exist. I've used neither myself, so I can't give you any details (though Clozure has been recommended to me on multiple occasions).
Oh, and is there a possibility to write the code is some normal text editor and compile it somehow in the terminal?
Not in the way that I think you mean, but yes, you can write a .lisp file with Sublime or whatever, then sbcl your-file-here.lisp. Note that sbcl your-file-here.lisp starts a running Lisp instance with a REPL, and incurs all the overhead that implies. If you're dead set against Emacs, what you could do is run a REPL separately from your project directory, then just (load "file-you-changed.lisp") or (ql:quickload :your-project-name) every so often.
xlispstat can be compiled on Mac OS 10.8 and works perfectly fine. It needs a couple of little edits for the nitpicking compiler but works perfectly with XQuartz. The people who are telling you to use other systems don't know how well integrated xlispstat is for people doing numerical work.

Struggling with common lisp libraries

I've learned scheme and quickly mastered a lot of it, then did a project in it just fine. Literally took me days to finish. I'm now trying to learn common lisp to get a feel for that and now I'm just really really struggling with trying to learn asdf. It seems to be common knowledge how to use it with libraries but I'm baffled. I guess it's because most lisp programs are made and run inside the repl because that all works fine. It's when I try to compile it to an executable where I'm loosing my place.
Is there anyone who can give me any advice on it or point me to a tutorial for it? I really want to be able to make an executable to give to people without having to explain how to install sbcl and (require) it then run it. I just want to learn to do something substantial in lisp that I haven't been able to do with scheme.
I guess I could use scheme and use ffi to get c libraries to work, but I have no experience with c. I'm just a web developer learning lisp for my own personal reasons. Of course learning some c and ffi may not take as long as this haha.
Thanks
I really want to be able to make an
executable to give to people without
having to explain how to install sbcl
and (require) it then run it.
You do not need ASDF in order to produce a 'stand-alone' executable. Most implementations provide means to save an executable image, but how to do this (and if it is to be provided at all) is not mentioned in the standard.
In general, you would load your code into your running image and then "dump" that image.
In SBCL for example, you would use sb-ext:save-lisp-and-die; CCL has ccl:save-application. You will have to look in your implementation's documentation in order to find out how to do it.
I don't have SBCL here at the moment, but this minimal example should work (untested):
(defun do-it () (format t "hello world~%"))
(sb-ext:save-lisp-and-die "hello" :toplevel #'do-it :executable t)
This is a working example using CCL:
Welcome to Clozure Common Lisp Version 1.6-dev-r14287M-trunk (LinuxX8632)!
? (defun do-it () (format t "hello world~%"))
DO-IT
? (ccl:save-application "hello" :toplevel-function #'do-it :prepend-kernel t)
[danlei#susi ~/build/ccl]% ./hello
hello world
These executable images may be of rather big size, unless your implementation provides something like a tree-shaker, but I do not think that this should be a problem nowadays.
You can find a detailed example for clisp in another SO question about this topic.
ASDF Documentation
This is not exactly what you asked for, but it might help.
I never could get ASDF to work very well, either. Somebody pointed me at clbuild instead, which is a slightly different approach to a similar problem. It's worked pretty well for me so far.

Newbie question about Lisp and Packages

Here is the back story skip to the bottom if you do not care and only want to see the question.
So I have been playing around in LISP for a little while. Some basic functions, some classes ,and file IO. When I run across this article:
http://www.adampetersen.se/articles/lispweb.htm
And I am excited to try and use lisp for a web application. I go and download the packages, but for the life of me do not know how to load them into my Allegro IDE.
Hmm... ok, well the hunchentoot site says a lot of the basic packages are in LispWorks. So I download that. Still not sure how to get the source for the packages that I downloaded into these IDEs. They seem to have binaries of the packages?
Oh well maybe ill switch to my ubuntu server and apt-get all the packages and setup slime (i have not used it before because I just wanted to learn lisp. Learning emacs and lisp at the same time seemed real daunting). I apt get all the packages needed and load up slime and again same problem there aren't available.
I dig around some more and see this program called ASDF. It looks like ASDF is some kind of package builder for lisp? I don't know it seems confusing. I'm about to give up at this point.
If you are still reading this here is my question.
1. How do I load the source for these packages into my lisp environment. trying to learn lisp hasn't been too hard but the information about the environments has been sparse. Do I need to build the packages I download with ASDF.
2. Is there a simple way for someone to just get up and running in lisp without having to speed a large amount of time upfront learning all the tools?
Hmm... ok, well the hunchentoot site
says a lot of the basic packages are
in LispWorks. So I download that.
This just means that the author has written a lot of Lispworks-specific code in Hunchentoot. It does not mean that Hunchentoot only works on Lispworks.
Still not sure how to get the source for the packages that I downloaded into these IDEs.
You need to use ASDF.
They seem to have binaries of the packages?
That's unlikely.
Oh well maybe ill switch to my ubuntu server and apt-get all the packages and setup slime > (i have not used it before because I just wanted to learn lisp. Learning emacs and lisp
at the same time seemed real daunting).
Don't do it then. You don't need to use Emacs or Slime.
I apt get all the packages needed and load up slime and again same problem there aren't
available.
For quick results try clbuild: http://common-lisp.net/project/clbuild/
I dig around some more and see this program called ASDF. It looks like ASDF is some
kind of package builder for lisp? I don't know it seems confusing.
ASDF is a bit like a Makefile for Common Lisp applications.
I'm about to give up at this point.
That's about the worst thing you could so (at this or any other point). I'm glad you have decided to post your problems here instead.
How do I load the source for these packages into my lisp environment.
trying to learn lisp hasn't been too hard but the information about the
environments has been sparse. Do I need to build the packages I download with ASDF.
clbuild should give you all you need, but here are some hints if you don't want to use it:
CLISP, SBCL: ASDF is part of your Lisp. Run (require :asdf). Lispworks, Allegro: you need to download and load ASDF. Save asdf.lisp somewhere then run (load "/path/to/asdf.lisp").
For every library/application ("system" in ASDF speak) you need to download und unpack it to some place. Repeat until all dependencies are satisfied. Note down these places (directories).
For every place from step #2 add the place to the ASDF registry: (push "/path/to/dir/" asdf:*central-registry*). Don't forget the trailing slash.
Load the system using (asdf:oos 'asdf:load-op :system-name).
Is there a simple way for someone to just get up and running in lisp without having to speed a large amount of time upfront learning all the tools?
See above -- use clbuild.
The quickest way in Ubuntu is to use the packages included in that distribution. It is "ok" if you just want to try some things, but these versions are often comparatively old. I would recommend the packages sbcl and slime. If you don't know emacs yet, you can get into that quite fast through its built-in tutorial (C-h t (press Control-h, release, then press t)).
You can then start emacs, start slime (through M-x slime), open a lisp file (C-x C-f ~/lisp/first-try.lisp), and you're ready to go. As a tutorial for Lisp, I think that Practical Common Lisp is a very nice book, and it's freely available.
Now, when you have come to like Lisp, you might want more up to date packages. I would recommend to use clbuild for that (see the link for further information, including FAQ). You can then also build a new sbcl (bootstrapped by the distribution's version).
ASDF, by the way, is only a system definition facility. It doesn't know how to download packages, it only knows how to load systems into a running Lisp image. In other words, it just solves the problem of automatically loading the multiple files that some "system" (library) consists of in the right order. The newest versions allow loading a package (after it is installed, e.g. through clbuild) with a simple
(asdf:load-sys 'foo)
Older versions show ASDF's internal concept of operations:
(asdf:operate 'asdf:load-op 'foo)
The above load-sys is a shorthand for this common use case. Further information (one could say, all you need to know about it) is at the ASDF Getting Started guide. ASDF is also included in SBCL.
When you load a source file, it is automatically compiled (producing .fasl files (fast-load)) so that loading is much faster next time.
Probably one of the fastest ways to get started is to use Lisp in a Box (or a spinoff like LispBox). These are full sets of everything you need.
You could also try the Lisp Resource Kit, which is a bootable CDROM with Lisp tools and documentation, all already set up for you. Just put it into your CDROM drive and boot!
All of these answers are good, however they've become a little outdated with the new popularity of Quicklisp. Very loosely speaking, quicklisp is the package manager to asdf's make. Once Quicklisp is installed on a system, you can use (ql:quickload "name of lisp library") to load that library into your lisp environment, including downloading it and any of its dependencies if required. For example, to download, install, and load Hunchentoot and all of its dependencies, use (ql:quickload "hunchentoot"). In later lisp sessions, calling (ql:quickload "hunchentoot") again will simply load the version already downloaded and installed, making ql:quickload a simple way to load any library available locally or remotely. To install Quicklisp, I refer you to quicklisp.org.
More detailed explanation
Lisp works a little differently from other languages when it comes to libraries. The first thing to know is that the language itself provides almost no library functionality- it has load (which goes through and runs each line in a file as if you'd typed them at the REPL) and compile-file (which creates a "fast load" file, a precompiled version of the file which loads and can perform much faster). Using just what the core language provides, in order to load a library you have to go to each of its files and load it (or (load (compile-file "filename")) it, for better load speed/performance). This got tedious, so a variety of libraries were created for managing the loading of libraries, and at the moment asdf is king (so much so that many lisp implementations actually bundle it). In asdf terminology, libraries are called "systems" and .asdf files describe all of the metadata involved in loading them- the systems they depend on and what order to load files in, mostly, but they still can get quite complex. Quicklisp, then, sits on top of asdf. Basically, when asdf discovers that it cannot locate a system, Quicklisp steps in and checks to see if that system is available from one of Quicklisp's online repositories, and if so downloads it and has asdf continue on its way. ql:quickload is basically just a wrapper around the asdf machinery for loading a system that enables quicklisp to help out as needed.

What is the best Scheme implementation for working through SICP?

I have been using PLT Scheme, but it has some issues. Does anyone know of a better implementation for working through SICP?
Use Racket (formerly PLT Scheme).
The DrRacket IDE is an excellent starting point for all things Scheme including SICP.
To look up keywords in the documentation, place the cursor on the keyword and press F1. In DrRacket you can now see the images directly in the REPL (the read-eval-print-loop).
SICP Support for DrRacket, by Neil van Dyke.
Update (2016): The new SICP package is at http://pkgs.racket-lang.org/#[sicp]
Download it with the Package Manager (in DrRacket) or use raco.
Manual
Update2 (2016): Also if you want to try a new implementation of the SICP picture language, then download sicp-pict2.rkt.
Update3 (2020): The sicp-lang package includes an implementation of the sicp language and the sicp picture language.
Documentation: SICP Support for DrRacket
Source Code: sicp-lang on GitHub
Racket Package: sicp-lang package info
Note: The picture language has more features (such as colors and larger sizes) than the picture language described in the book. The source contains examples: https://github.com/sicp-lang/sicp/blob/master/sicp-pict/main.rkt
Use MIT Scheme.
It's recommended by the authors of SICP, and is used at MIT for the 6.001: Structure and Interpretation of Computer Programs course.
MIT/GNU Scheme, just make sure you load the SICP compatibility package (yes, they provide specific libraries to enhance guarantee the SICP exercises work).
This was suprisingly annoying to get done on macOS. Here's how it works as of today, assuming you have Homebrew. (Might want to run brew update once in a while).
brew cask install racket
raco setup # might be optional
raco pkg install sicp
Now you can (require sicp) or simply run
racket -l sicp --repl
Which you might want to abbreviate to scheme. In bash that'd be
alias scheme='racket -l sicp --repl'
which you can add to your ~/.bashrc
I've just started do SICP this week.
Currently, MIT Scheme is broken in in Ubuntu Linux (9.04 "jaunty"). It might be working in the future.
DrScheme is working, and is working well. You can use soegard's package listed above or Neil Van Dyke's package, which is based on soegard's package and is available from http://www.neilvandyke.org/sicp-plt/. The nice thing about this package is that when installed, you can use Language|Choose Language.... menu item to select SICP.
CHICKEN Scheme has an sicp library that provides support for SICP. You can install it by running chicken-install sicp and writing this at the beginning of your source code: (use sicp).
PLT Scheme works pretty well, or MIT Scheme as Keparo suggested. What issues are you having with it?
I'm now working through SICP using Chez Scheme. It's a pretty old dialect of Scheme, so presumably it isn't too far from what SICP was written around.
Note that the Chez Scheme project page links a Windows binary and source that can be built on Unix-like platforms. But if you're on a Mac, you'll probably want to do
brew chezscheme
man chez
Assuming you have homebrew, which you really should.
Why not MIT Scheme? Because the interactive front end is Edwin, an editor that uses EMACS conventions. (Currently, it's an actual EMACS mode, tho it used to be implemented in Scheme.) I used to know basic EMACS, but my skills atrophied from disuse, which tells me that relearning this editor is just not worth the trouble.
Why not DrRacket? If I had seen #frederick-squid 's brew instructions, I might have given it a try. Instead I tried to follow the official instructions for scheme and sicp, which are seriously out of date. Then I tried to make the IDE go into scheme mode, which seems to be intuitive but isn't.
Just too much trouble. And I'm not sure I want to get into a fancy language design IDE, especially one whose poor support of Scheme sparked the original question.