I have always been very interested in functional programming, but I have never had any related practices. I finally got to work in my spare time. Unlike many scheme interpreters, MIT-scheme only accepts and executes standard input code, so it cannot be added to the header of a script like many CGI #! Run CGI in/bin/python. A conversion is required.
Method 1
The conversion script is as follows:
#!/bin/shfor program in $@do tail -n+2 $program | mit-scheme --quietdone
Save the code as SCM. SH and add executable permissions to the script. Put the code in the specified directory. For example, under/usr/bin.
Add a sentence to the header of the Scheme code file you wrote.
#!/usr/bin/scm.sh
Tell Linux that you want to use SCM. sh to parse the script, and then SCM. sh removes the first line of the current scheme script, transmits it to MIT-scheme through a pipeline, and then the MIT-scheme execution is complete.
My test. SCM script is as follows:
#!/srv/www/cgi-bin/scm.sh(display "content-type: text/plain") (newline) (newline)(display "hello lisp")(define getenv get-environment-variable)(map (lambda (env-var) (display env-var) (display " = ") (display (or (getenv env-var) "")) (newline)) '("AUTH_TYPE" "CONTENT_LENGTH" "CONTENT_TYPE" "DOCUMENT_ROOT" "GATEWAY_INTERFACE" "HTTP_ACCEPT" "HTTP_REFERER" ; [sic] "HTTP_USER_AGENT" "PATH_INFO" "PATH_TRANSLATED" "QUERY_STRING" "REMOTE_ADDR" "REMOTE_HOST" "REMOTE_IDENT" "REMOTE_USER" "REQUEST_METHOD" "SCRIPT_NAME" "SERVER_NAME" "SERVER_PORT" "SERVER_PROTOCOL" "SERVER_SOFTWARE"))
The execution result is as follows:
Method 2 add two lines of code before the scheme script
#!/bin/shexec tail -n+3 $0|mit-scheme --quiet;exit