Mit-scheme CGI programming

Source: Internet
Author: User
 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.