How do I run a scheme script from notepad++/cmd/powershell? - scheme

In python, I add python and the path of the file, and my script will run.
In haskell, I invoke the GHC compiler on my file to make an executable, or I load GHCi and load the path of the file to use functions, and my script is running.
In Scheme, neither type of approach works for me. Everywhere I search, I only hear about emacs and SLIME. I am not interested in either. I just want to write scripts in notepad++ or any other simple text editor, and either run them through a scheme interpreter, or compile it into an exe, for the purpose of testing code from the MIT SICP book.
I installed MIT/GNU Scheme for learning purposes. I am not interested in Racket because of how different it is from Scheme now (I don't want to confuse myself further, I just want to learn the basics.)
One thing that is contributing to my confusion is the following. When I open mit-scheme through the start menu shortcut, it opens the edwin editor (its tutorial (C-h t command) is apparently "corrupted" so I can't use that instead of notepad++ nor would I want to at this point (just too frustrated with it)). The file location for the edwin editor is in the bin folder. The bin folder though, only has 2 files: mit-scheme.exe and dibutils.dll. If I double-click on mit-scheme.exe it just gives me an error, but apparently using the shortcut opens the edwin editor (that is supposed to be located in the same folder as mit-scheme.exe (it isn't)).
Why is all of this so convoluted? Isn't there a simple way to get my scheme scripts running? I just want to run things like:
(define hello-world
(lambda ()
(begin
(write ‘Hello-World)
(newline)
(hello-world))))
Searching for solutions online was futile for me, I've already wasted many hours- so hopefully I can finally get an answer here.
Thank you.
EDIT: I am on windows 7 and *nix operating systems isn't an option.

mit-scheme has the --load switch. thus
mit-scheme --load path/to/script.scm scrip2.scm -- args ...
I think you also can use Racket to run standard r6rs like this:
plt-r6rs script.scm
For r5rs there is plt-r5rs. Racket can also make executables that run faster with raco exe script.scm.
EDIT
BTW: plt-r6rs is for running programs using the standard R6RS scehem report. plt-r5rs is for running programs using the standadr R5RS scheme report. I have no idea what you mean by "different it is from Scheme". Racket has it's own language, which is the default, which is it's own incompatible dialect of Scheme, but it is not a reason for not using the software. It's like not using gcc because it supports a non standard C++ language and ignoring that you can get ot to behave standard with switches.
There is only one R7RS-small implementation, the reference implementation chibi scheme. Every imlpementation is waiting for the full R7RS report I guess so it's R6RS which is the current standard.
The lists in R5RS and R6RS are mutable (but in R6RS you need to import (rnrs mutable-pairs), but thats a part of the standard. Try not import racket libraries from the standard schemes unless you have no other choice. Check the SRFIs first.
There are not so many Scheme versions and scheme implementations. For every popular programming language that has been for at least 10 years there are more than 3 implementations and several incompatible versions of the standard. If you think there are few implementations of the languages you mentioned you are quite wrong. Python has many implementations and incompatible standard versions. Haskell also has many implementations and versions of their standard. Scheme is from the 70s so it's been around for 40 years so it's only natural that there are more versions of Scheme than Haskell and Python.

This is how I was able to run scheme code from notepad++,
I put to notepad++ run configuration:
"C:\Program Files (x86)\MIT-GNU Scheme\bin\mit-scheme.exe" --heap 512 --library "C:\Program Files (x86)\MIT-GNU Scheme\lib" --load "$(FULL_CURRENT_PATH)"
and then I was able to run. However, I had to save file first, otherwise it is not running. Also notice that (+ 2 2) is not printing as a result, But If I call procedures it is working fine.
sample

Related

Interpreting SCHEME for SICP

I have read through a bunch of Structures and Interpretations of Computer Programs and it has really captured me. I love they way it explains programming concepts. But the problem is that I don't know how to get MIT Scheme working. I don't know much about how to quickly interpret/compile in languages that require a compiler/interpreter. (doing it in JavaScript is incredibly easy) I have tried DrRacket but would love to use sublime text then quickly run it.
I have downloaded the official MIT-SCHEME bundle but I have no idea on how to get it actually working after 3 hours.
Thank you for reading!
It sounds like you may be familiar with the sicp package for Racket that allows you to write programs in a #lang sicp language. If you're interested in running them from the command line a la Javascript, that's certainly possible; if you run
racket
on a file that starts with #lang sicp (and you have the sicp package installed), it should run fine at the command line. It should be easy to bind this to a sublime command.
HTH

Running simplescheme in DrRacket

I want to run code for 'simplescheme' (http://bryanchadwick.com/simplescheme/) on DrRacket to test it before putting it on the device's android. I could not find "#lang simplescheme" in the list of languages provided in DrRacket's menu.
I have 'simplescheme's android app (https://play.google.com/store/apps/details?id=chadwick.apps.simplescheme) installed on the device, but how can I test the code first on a desktop? I could not find 'simplescheme' interpreter for Linux or Windows on the net.
How can I solve this problem? Thanks for your comments/answers.
According the Simple Scheme web-site: http://bryanchadwick.com/simplescheme/index.html
Simple Scheme is a language inspired by Scheme and Racket.
This means that the only implementation of Simple Scheme is the Android one.
There are however two options to run your programs on the desktop.
The first one is to install an Android Emulator and run Simple Scheme in the emulator. This will allow you to run the real Simple Scheme.
The other options is to use #lang racket and restrict your self to use the constructs that are supported by Simple Scheme: http://bryanchadwick.com/simplescheme/index.html#functionlist
On the plus side this allows you to use DrRacket, but you risk using a construct missing from Simple Scheme.
NB! This answer is off topic as it's about Simply Scheme and not SimpleScheme. I'll leave it here as the names are rather similar
Racketeer and SO-er Danny Yoo has made a Racket module language to support Simply Scheme in the racket language suite. In Racket with the bottom left dropdown set to "Determine language from source" and replace the definitions window, including the #lang line to the following:
#lang planet dyoo/simply-scheme:2
(se (butlast (bf "this"))
"world")
And press RUN. It will download and install the language and then you'll see the answer (hi "world"). The first time around you might see an error, but my experience is that it will go away on a consecutive run.
The definitions will have all the simply scheme features described in the the documentation. Happy hacking!

How to run mzscheme on DrRacket?

I have to make sure that my code is compatible with mzscheme but I don't know how to use it on my school's ssh servers. Is there anyway to test if my code is compatible with mzscheme on DrRacket?
Rackets default language was renamed from #!scheme to #!racket when the whole thing changed name from PLT to Racket. #!mzscheme is an old version of this which is made as a legacy language.
You switch language by making the language name the very first line in your source files. also instead of #!language you can write it more verbose as #lang language. It is exactly the same.
The legacy language uses the #!racket language pairs, which are immutable. Thus you cannot use set-car! and set-cdr! with the legacy library. If this is a problem use #!r5rs instead.
The bin directory installed with DrRacket (i.e., /Applications/Racket v6.3/bin on Mac OS X) has mzscheme as a working binary; you can just use it.
Also on DrRacket GUI, you can specify to use MzScheme with #lang mzscheme at the first line.

OS X Scheme Language (dialect for lisp)

I've only learned Python, and have recently begun to learn a new language called Scheme. I have a few basic questions regarding Scheme. 1) If I want to open a scm file on sublime text 2, can I just select "Lisp" for my language settings? 2 To run python on terminal, all I had to do was python file.py, what command do i do to open a scm. file on my os x.
1) Yes. You could also install a more Scheme oriented version.
2) Yes. Depends on the implementation. For racket you can start with plt-r6rs-script file.scm, plt-r5rs-script file.scm or you can compile raco exe file.scm and then just run file which then is a executable. Racket also had an IDE called DrRacket suitable for programming, debugging and running in the IDE and it supports standard Scheme versions such as R5RS, R6RS as well as it's own languages racket, typed racket and lazy racket. Don't confuse the language racket with the whole imlementation with the very same name that also runs Scheme very well.
For ikarus you do ikarus --r6rs-script file.scm
If you're looking to pick up a Scheme dialect, you may want to do it via Racket. At that point, if you're comfortable with the terminal, you can go through their Systems Programming With Racket tutorial, which will clarify how you'd go about editing and running scheme files from a command line.

compile/run Common LIsp from the Mac Terminal

Is there a way to do this? I've been using Slime to learn Lisp, and I would like to start building larger projects which means (I think) that I would have to start writing some .lisp files.
I think your best bets for Mac Common LISP are the LispWorks Personal Edition or SBCL.
Assuming you've got SBCL installed, you can create a .lisp file using a text editor (emacs would be the traditional choice):
(defun test ()
"Hi!")
Then you can run a lisp interpreter in a shell:
bash% sbcl
This is SBCL 1.0.29, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (load "test.lisp")
T
* (test)
"Hi!"
*
The shell could either be a mac terminal window or an inferior lisp interpreter running in emacs.
Slime is designed to support writing Lisp files, including definition finding, online documentation, name completion, compilation, and more. Perhaps you should take a look at the manual, chapter 3 (using slime-mode).
I think it is a bit hard to tell what you are really asking for.
You can compile and load a whole Lisp file in Slime by using C-c C-k in the buffer, and then use it from within the Slime REPL, so you don't even have to run LOAD in the REPL.
Then, there are solutions for shebang lines known from unices that will work in the OS X shell, if you want to run your Lisp programs as scripts from the command line, but those differ from implementation to implementation.
A possibility for building executables, which then can be run from the command line, is loading the relevant code into your Lisp image, then saving that image with the loaded code. Those images may be made executable, executing a given function on startup (think main). This possibility also differs for implementations, so without mentioning your implementation of choice, you will have to look it up in its documentation.
Now, since you are asking about "building larger projects" specifically, my advice would be to get acquainted with a system definition facility. A lisp system basically is a kind of "project", a few files with code, package definitions, and a system definition. I will give you a little example for ASDF, which is (as far as I can tell) the most popular one in the open source world.
(defsystem my-system
:name "my-system"
:version "0.0.1"
:author "hedgehogrider"
:license "BSD"
:description "bla bla bla"
:serial t
:components ((:file "packages")
(:file "code")))
Now, you would put this in an asd file, say my-system.asd, put your package definitions in packages.lisp, your functionality in code.lisp, and then, given you set up ASDF properly, you would be able to compile and load your system in the Slime REPL by pressing ,l my-system. Alternatively, you could enter (asdf:oos 'load-op 'my-system) (or, for more recent versions of ASDF: (asdf:load-system 'my-system)) at the REPL.
In order to make this work, you will have to install ASDF for your Lisp implementation, if it is not shipped with it, and the directory containing your asdf-files will have to be put in asdf:*central-registry*. One easy solution is to symlink your asdf-files to one central directory, but there are other possibilities. Check the ASDF documentation or other tutorials to learn more about ASDF.
Yes, you will want to write your own Lisp files instead of relying on images.
I recommend CLISP for OSX for an out-of-the-box experience. It has a nice REPL experience.
Professional development done with F/OSS today generally uses SBCL or CCL.

Resources