Programming

Lisp


Lisp is an expression-oriented language. Unlike most other languages, no distinction is made between “expressions” and “statements;” all code and data are written as expressions. When an expression is evaluated, it produces a value (in Common Lisp, possibly multiple values), which then can be embedded into other expressions. Each value can be any data type.

Download software: Lispbox IDE

Cost: Free

Instructions to setup software: http://common-lisp.net/project/lispbox/

Hardware requirements: PC, Mac

Operating systems supported: Win, Mac, Linux

Difficulty level: 4 out of 5


TRY IT!

1. After downloading the IDE from lispbox extract the contents into a file on your computer.

2. Copy and paste this Lisp code into your favorite text editor. Windows notepad works fine.


(defun convert ()
(format t "Enter Fahrenheit ")
  (LET (fahrenheit)
    (SETQ fahrenheit (read fahrenheit))    	
          (LET (celsius) 
               (SETQ celsius (round(*(- fahrenheit 32.0)(/ 5.0 9.0))) )	  
               (format t "Celsius is ~a" celsius)	
               (if (<= celsius 0) (format t " Pack Long Underwear ~C" #\linefeed))
               (if(>= fahrenheit 100) (format t " Remember to Hydrate ~C"  #\linefeed))
          )
  )
  (format t "~C"  #\linefeed)
  (format t "Would you like to do another calculation? 1=yes 2=no ")
  (LET (repeat)
     (SETQ repeat (read repeat))
          (if (= repeat 1) (convert))
  )
) 

3. Save the File as “lisp_example.lisp” in the root of the folder you created in step 1.

4. Start Lispbox by running lispbox.bat (Windows) / lispbox.sh (Linux) / Emacs (OS X).

5. When you start up the Common LISP environment, you should see a prompt, which means that LISP is waiting for you to enter a LISP expression. To load the file you created in step 3 type the following expression including the parenthesis, (load “lisp_demo.lisp”)

6. Once your program is loaded you can execute it with the following command, (convert)
7. Try several different temperatures by looping through the program with 1 for yes.


TRY THIS

1. Change the temperatures used in the decisions – change the lower temperature from 60 to 30 degrees, for example. Make sure you change it in two places! Save the file and refresh the browser (or restart the web page), and enter new numbers – did the answers change at the new temperature?

2. Create a new temperature range from 30 to 60 degrees and have it display – “Bring hat and gloves!”

3. Change the wording of the phrases.


LEARN MORE

Common Lisp — Getting started with Lisp.


RESOURCES, TIPS, TRICKS AND HINTS

Notepad++ is a great free text editor designed specifically for programmers. Check it out here.

Write a comment about “Lisp”

Nickname:

Type your comment:

  • 1. Safety. Do the following:
      a. Show your counselor your current, up-to-date Cyber Chip.
      b. Discuss first aid and prevention for the types of injuries or illnesses that could occur during programming activities, including repetitive stress injuries and eyestrain.

    2. History. Do the following:
      a. Give a brief history of programming, including at least three milestones related to the advancement or development of programming.
      b. Describe the evolution of programming methods and how they have improved over time.

    3. General knowledge. Do the following:
      a. Create a list of 10 popular programming languages in use today and describe which industry or industries they are primarily used in and why.
      b. Describe three different programmed devices you rely on every day.

    4. Intellectual property. Do the following:
      a. Explain how software patents and copyrights protect a programmer.
      b. Describe the difference between licensing and owning software.
      c. Describe the differences between freeware, open source, and commercial software, and why it is important to respect the terms of use of each.

    5. Projects. Do the following:
      a. With your counselor’s approval, choose a sample program. Then, as a minimum, modify the code or add a function or subprogram to it. Debug and demonstrate the modified program to your counselor.
      b. With your counselor’s approval, choose a second programming language and development environment, different from those used for requirement 5a and in a different industry from 5a. Then write, debug, and demonstrate a functioning program to your counselor, using that language and environment.
      c. With your counselor’s approval, choose a third programming language and development environment, different from those used for requirements 5a and 5b and in a different industry from 5a or 5b. Then write, debug, and demonstrate a functioning program to your counselor, using that language and environment.
      d. Explain how the programs you wrote for requirements 5a, 5b, and 5c process inputs, how they make decisions based on those inputs, and how they provide outputs based on the decision making.

    6. Careers. Find out about three career opportunities in programming. Pick one and find out the education, training, and experience required. Discuss this with your counselor and explain why this career might be of interest to you.

  • Earning the Cyber Chip can help you learn how to stay safe while you are online and using social networks or the latest electronic gadgets.

    Topics include cell phone use, texting, blogging, gaming, cyberbullying, and identity theft. Find out more about the Cyber Chip at www.scouting.org/cyberchip.