Common Lisp Compilation Program Tips

Source: Internet
Author: User

These days began to play common Lisp, encountered an interesting problem, CL is generally interpreted to run, there are implementations can compile generated bytecode (FAS file). The two CL implementations I'm using are SBCL and clisp, which I see in the book "Practical Common Lisp programming," one of the features of Clisp relative to SBCL is that Clisp compiles lisp into bytecode files (which is very similar to Java and feels kind), But also can not directly compile the machine code, which let me this obsession with the assembly and C language feeling very uncomfortable, think of the previous in the "Python core programming" see "Sh-bang", brainwave, incredibly still good to pass! Let's take a look at the following example:

(1) Lisp file: Test.lisp

1 (Format T "Hello,common Lisp world!~%")2(Defun sqr (n)3      (* n N))  4 (Format T "The square of ~a is ~a ~%" 5 (SQR 5))

(2) Compiling and other:

1 $clisp-c test.lisp23# ... Omit output ... 4 5 $vim Test.fas

(3) After opening Test.fas with the editor, add #!/usr/bin/clisp to the first line:

#!/usr/bin/clisp (| system|::|version| ' (20080430.)) #0Y_ #0Y |   charset|::|utf-8| #Y (#:|1 1 (FORMAT T "Hello,common Lisp world!~%") -1|       #18Y (The #Y (#:|1 1 (FORMAT T "Hello,common Lisp world!~%") -1-1|, the DA 6B (in) #19Y (the "Hello,common Lisp world!\n") ("the" * *, the DA-AF (9E) common-lisp|::|t| | common-lisp|::|t| |    common-lisp|::|t|)) |   common-lisp|::|*standard-output*|) (| common-lisp|::|t| | common-lisp|::|t| | common-lisp|::|t|)) #Y (#:|2 3 (defun SQR (N) ...)   -2| #20Y (xx) 2F, da DC 9C C5 19 01) (| common-lisp-user|::|sqr| |    system|::|remove-old-definitions| #Y (|       common-lisp-user|::|sqr| #17Y (from xx to XX, AD AE 33 02 39 19 02) () (| common-lisp|::|t| | common-lisp|::|nil| |       common-lisp|::|nil|) (| common-lisp-user|::|n|) | common-lisp|::|nil| 1)) (| common-lisp|::|t| | common-lisp|::|t| | common-lisp|::|t|)) #Y (#:|4 4 (FORMAT T "the SquAm of ~a is ~a ~% "...)   -3|  #22Y (The #Y (#:|4 4 (FORMAT T "The square of ~a is ~a ~%"), DA 6B, DC DC 6F. ...)       -3-1| #39Y (as at xx/xx), B1, B1, B1, B1, B1 38 02 31 9, and more. 5 9E) ("The Square of" "is" "\ n") (| common-lisp|::|t| | common-lisp|::|t| |    common-lisp|::|t|)) | common-lisp|::|*standard-output*| 5. |   common-lisp-user|::|sqr|) (| common-lisp|::|t| | common-lisp|::|t| | common-lisp|::|t|))

(4) The following execution chmod u+x Test.fas

(5) Execute./test.fas, output as follows:

1 chmod u+2 $./3 hello,common Lisp world! 4 5  -

  If you want to run the example above, make sure you have Clisp installed.

Well, what I'm talking about is not a lisp trick, it's just a feature that most shells support: In the first row, if there's something like #!/xxx/xxx, XXX is automatically called to interpret the following for this example,/usr/bin/ Clisp to explain the Test.lisp bytecode file, the equivalent of running Clisp Test.fas (but somehow, feel comfortable with this call), finally have to spit down the slot AH: "Insert Code" Support F #, Erlang but no Lisp language, Is Lisp too small?

Common Lisp Compilation Program Tips

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.