Next Titel Inhalt Vorwort 1 2 3 4 5 6 7 8 9 10 11 12 Appendix @ CAAD Teachers

KAPITEL 1
Einleitung, theoretische und praktische Bedeutung
Lisp I - einfache Funktionen


1.1 Introduction

In a few years, every architect in Switzerland will have a computer aided design system in the office. Knowing a CAD package and having experience in using it will be one of the basic requirements of every graduating architectural student. The success of CAD in recent years has also propagated some of its serious shortcomings, in that no CAD program It is therefore not the intent of this course to train you in a particular CAD program or design view but to prepare you for the difficult task of designing and changing CAD programs for your personal use or to needs as specified by other architects.

The emphasis of this course will be on principles. All exercises have the purpose of illustrating one particular aspect of design computing.

1.2 Computer Operations - Getting Started

All the machines in the lab are connected with each other and services like printers and plotters via a network. You can work on any machine that is available. You need a login name and a password in order to use any machine. When you are finished working, you should logout of your account and turn off the monitor. See Appendix A for details of this procedure.

In order to effectively use a computer system, some basic concepts need to be understood. A computer system is made up of a number of physical components, collectively known as hardware. Hardware is controlled and directed by a set of instructions known as software or computer programs. Software programs can be obtained from various sources and can be installed on various machines or hardware.

An operating system is a collection of software programs designed to work on specific hardware configuration. When you log into your account, you interact with the operating system. At present, in the Space and CAD labs, we have Sun Sparc Stations and Silicon Graphics Indys running operating systems called UNIX and IRIX respectively. In order to make working with computers easier, a set of programs may be installed on top of the operating systems, known as window managers, e.g., OpenWindows on our Sun machines and IndigoMagic on the SGIs. As a result, each command or process you start is displayed in a rectangular region on the screen, called a window. Windows can be closed temporarily in which case they will collapse into an icon, or windows can be quit if a process is finished and no longer needed. Commands can be entered by typing them in at the keyboard or by a series of movement and clicking actions with a mouse. Some useful commands and actions are explained in Appendix A.

In some cases, you can enter a command and its result will be some information displayed on the screen, e.g., if you type date, the current date and time are displayed. Other commands start a process in which you can generate additional information that can be stored and retrieved later. For example, an editor program lets you create text files which can be stored and manipulated. Thus there are computer programs and data you generate with such programs, both are referred to as files and may be stored separately with different file names. To work on a data file, you need to start the program which created that file, and then load in that data file for further processing.

Program and data files are stored in directories and subdirectories organized in a hierarchical fashion. You can move up and down a file system using operating system commands like cd, and delete, rename, or copy files using other commands like rm, mv, cp (see Appendix A for further details).

1.3 LISP

LISP is a computer programming language and it is considered by many to be easy to learn and fun to use. A programming language is defined by a set of valid expressions or statements. Each valid expression may be made up of a number of valid operators and symbols that can occur only in defined patterns. A series of valid statements may be combined into a computer program that, when executed, performs a specific task.

A valid LISP statement is expressed as a list enclosed in parentheses. A statement in LISP can be executed directly by an interpreter program and results displayed on the screen. Thus two steps are involved in this process: writing LISP expressions and passing them to the LISP interpreter for evaluation.

Setting Up

In this course, the LISP interpreter available with the AutoCAD program will be used. Whenever you start AutoCAD, this interpreter is running in the background. When you type a valid LISP expression, it is passed to the LISP interpreter for evaluation. Since AutoCAD is designed to be an interactive graphics application, it provides a number of specialized graphics functions in LISP which are not part of the standard LISP language. The enhanced version of the language available in AutoCAD is known as AutoLisp.

Start AutoCAD by typing acad in any shell window. Select a new drawing option and enter any name for the drawing file name. Once AutoCAD is properly loaded, you will see a graphic window with a screen menu and some pull-down menus at the top. At the bottom, you see a prompt command: in a small window. Here is where you can enter LISP statements for evaluation. If you hit F1 key, a bigger window comes to the foreground on your screen. This is the same command: prompt window which was only partially visible earlier. With this larger window available, proceed with the following sections.

When you are finished with the following sections, remember to quit AutoCAD, exit OpenWindows, and log out.

1.3.1 Atoms and Lists

An expression in LISP is made up of atom(s) or list(s). Atoms could be integer numbers like 3, 27, -88; floating-point numbers like 2.34, -0.9, 123.333; or symbols like X, name, My_Name. A list consists of a left parenthesis, followed by zero or more atoms, and a right parenthesis as in the following: (2 name -3.56) or ().

1.3.2 Arithmetic Operations

A number of operations are predefined in LISP like the following arithmetic operations. An operation is defined by a symbol (e.g. +, -) which signifies a procedure to be performed (e.g. addition, subtraction) on specified atoms.
(+ num1 num2)
This operation returns the sum of all specified numbers.
(- num1 num2)
This operation subtracts the second number from the first and returns the result.
(* num1 num2)
This operation returns the product of two numbers.
(/ num1 num2)
This function divides the first number with the second and returns the quotient.
In the above operations, symbols +, -, *, and / specify procedures, and numbers could be any numeric values on which the procedures are carried out by the LISP interpreter. If you mix integer and floating-point numbers in an arithmetic operation, the result returned will be a floating-point number! Further, note that the number of arguments to these operations need not be limited to only two numbers as shown above. Try to evaluate these operations with different number of arguments.

Examples: Enter the following expressions and check the results.

	(+ 23 34)	=>  57
	(+ 3.0 12)	=>  15.0
	(- 30.6 25)	=> 
	(- 25 10)	=> 
	(* 12 3)	=> 
	(* 12 3.0)	=>
	(/ 12 5)	=> 
	(/ 12 5.0)	=> 
Try these operations with more than two numbers as arguments.

1.3.3 Variables

A symbolic atom like X, name, My_Name, may be used to store some value which may be another symbolic atom like a number, character value, or a list. A symbolic atom with some value assigned to it may be evaluated, returning the value it is assigned. Such atoms are often referred to as variables since they can be assigned different values.
(setq sym val)
This operation assigns the value of the second argument to the the first argument; this is known as an assignment operation.
Examples: Enter the following expressions exactly as shown. Note the quote (') character before the list. Its meaning will be explained in Kapitel 5; for the moment remember to put a quote before any list that is to be passed to a LISP procedure.
	(setq a_float 23.5678)	=> 23.5678
	(setq an_integer -23567)	=> 
	(setq a_list '(a b c)) 	=> 
A variable may be evaluated by simply passing it to the interpreter. In AutoLisp, you can retrieve the value of a variable by typing exclamation mark (!), followed by the variable name, without any spaces between the two. For example:
	!a_float	=> 23.5678
	!an_integer	=> 
	!a_list	=> 
The examples above should make it clear that once a variable is assigned some value, that variable can be used whenever the value it refers to is needed.

1.3.4 List Operations - car, cdr

A list may be made up of zero of more atoms, for example: (3 2.6 -8.9). If we want to access or change any of the atoms in the list, two LISP operations are provided.
(car a_list)
This operation returns the first element of an argument list.
(cdr a_list)
This operation returns a list of everything in an argument list except its first element.
Examples: Enter the following expressions exactly as shown.
	(car '(a b c))	=> A
	(cdr '(a b c))	=> (B C)
	(car '((3 b) c))	=> 
	(cdr '((3 b) c))	=> 
	(cdr '(a))	=> 
What happens if you evaluate the following expressions?

	(setq a_list '((23.9 ab)(apples oranges cherries)
		       (dogs cats cows)))	=> 
	(car (car a_list))	=> 
	(cdr (cdr a_list))	=> 
	(car (cdr a_list))	=> 
	(cdr (car a_list))	=> 
When a number of list operations involving car and cdr are needed, it is possible to combine them into compound operations by joining ar (from car) and dr (from cdr). For example, the previous four examples could be rewritten as follows:
	(caar a_list)	=> 
	(cddr a_list)	=> 
	(cadr a_list)	=> 
	(cdar a_list)	=> 

1.3.5 NIL

It is also possible to set up variables that do not have any value, this is signified by a special symbol nil. Note that assigning 0 (zero) is not the same as assigning nil to a variable since zero is still a valid value!

Example: (setq a_variable nil) will set up a symbol a_variable that does not have any value assigned to it. Since it is declared, it can be evaluated and the result of evaluation will be nil.

It is also possible to have lists which are empty, i.e. they do not contain any atoms, just left and right parentheses. These are known as null lists.

Example: (setq an_empty_list '()) will set up a null list. See what happens if you use car or cdr on such a list.

1.4 Übung 1

This exercise is meant to lead you through a series of steps in which you become familiar with the window manager, operating system commands, using the keyboard and mouse for input, and creating a drawing and a text file in your account. It has been divided into two parts. The first will give you some practice in using the operating system and preforming some basic AutoCAD commands. The second envolves transfering LISP results from AutoCADs text window into a text file. This allows you to save the results and send them, along with the .dwg file from part 1, as your first assignment to the abgabe.

Part 1: Operating system and AutoCAD basics.

1. Log in to your account.

2. Create a directory called u01 (not U01) and make it the working directory.

3. Copy a file named 01_name.dwg, from the directory: /homes5/prog/ausgabe, into your current directory and store it as 01_name.dwg where name is your name. Remember: Do not use capital letters in any directory or file names.

4. Start the AutoCAD program by typing acad in a Shell window. Select the Open option from the File pulldown menu, then the 01_name file from the list in the Open Drawing window that appears. Click the O.K. button. This will load in your data file.

5. Write your name with the command DTEXT in AutoCAD. When prompted for a Startpoint, enter 0,0. Enter 1.0 when prompted for the Height.

6. Enter the command SAVE. The Save Drawing As window will appear. Confirm that the file should be saved under its original name (i.e., updated) by clicking the O.K. button.

7. Enter END at the command prompt to stop the AutoCAD program.

8. Copy your file 01_name.dwg to the directory: /homes5/prog/abgabe.

Part 2: Lisp I - Operations with lists.

1. Open a text window by selecting the Text Editor... option from the Programs submenu of the WorkSpace menu in OpenWindows.

2. Restart AutoCAD and a new drawing file. Bring the AutoCAD text window into the foreground by hitting the F1 key.

3. Enter each of the following expressions at the AutoCAD command: prompt.

	(+ 3 4.0 8 99.99)	=> 
	(- 234 34 89 10)	=> 
	(* 10.0 2 5 6.0)	=> 
	(/ 335 12 8 9.9)	=> 
	(car (cdr '((ab cd) (ef gh ij) (kl mn))))		=> 
	(cdr (car '((ab cd) (ef gh ij) (kl mn))))		=> 
	(setq a_list '((ab cd) (ef gh ij) (kl mn)))	=> 
	(car (cdr a_list))	=> 
	(cdr (car a_list))	=> 
	!a_list	=> 
	(setq num1 25)	=> 
	(setq num2 10)	=> 
	(+ num1 num1 num2 num2)	=> 
	(* num1 num2)	=> 
	(/ num2 num1)	=> 
4. Select the entire AutoCAD text window by clicking at the top of the window with the left mouse button and then clicking at the bottom of the window with middle mouse button. This should make the entire text grey out.

5. Copy the selected text by hitting the Copy function key on the keyboard. This puts the selected text in computer memory.

6. Move the mouse over to the text editor window and hit the Paste function key on the keyboard.

7. Use the right mouse button to open the File menu of the text window, select the Store as New File... option, complete the path name indicated next to Dirctory: by adding u01. Type 01_name.txt (where name is your name) on the line next to File:. Complete the proceedure by clicking on the Store as New File button.

8. Quit AutoCAD. Copy the file 01_name.txt to directory /homes5/prog/abgabe.

9. Exit OpenWindows and log out of your account.

Next Titel Inhalt Vorwort 1 2 3 4 5 6 7 8 9 10 11 12 Appendix @ CAAD Teachers

This website has been archived and is no longer maintained.