Allegro CL Certification Program Lisp Programming Series Level I - - PowerPoint PPT Presentation

allegro cl certification program
SMART_READER_LITE
LIVE PREVIEW

Allegro CL Certification Program Lisp Programming Series Level I - - PowerPoint PPT Presentation

Allegro CL Certification Program Lisp Programming Series Level I Session 1 Homework 1/15/2004 1 Hello World Create a source file, write a function that prints Hello World Save the file Compile the file Load the .fasl


slide-1
SLIDE 1

1 1/15/2004

Allegro CL Certification Program

Lisp Programming Series Level I Session 1 Homework

slide-2
SLIDE 2

2 1/15/2004

Hello World

  • Create a source file, write a function that prints

“Hello World”

  • Save the file
  • Compile the file
  • Load the .fasl file
  • Run the function
slide-3
SLIDE 3

3 1/15/2004

Arithmetic

  • Write a function named polynomial
  • It must take 4 arguments: a, b, c and x
  • It must return the value of

ax2 + bx + c

slide-4
SLIDE 4

4 1/15/2004

My-compile-and-load

Write a function that compiles and loads a file of Common Lisp source code.

  • Takes as argument a file
  • Returns the symbol t
slide-5
SLIDE 5

5 1/15/2004

functions first, second, …, tenth

  • first, second, third, …, tenth name functions

each of which

– takes a list as argument – returns the corresponding element of its list argument

  • define a function which

– takes as argument a list – returns a list of the second and fourth elements of its argument

slide-6
SLIDE 6

6 1/15/2004

function nth

  • nth names a Common Lisp function which

– takes as arguments a non-negative integer and a list – returns the element of its list argument which is in the (zero-based) position specified by the first argument

  • as before define a function which

– takes as argument a list – uses nth to return a list of the second and fourth elements of its argument

slide-7
SLIDE 7

7 1/15/2004

function nth cont’d

  • define a function similar to that above which

– takes as arguments 2 non-negative integer aand a list – returns a list of the elements of the list argument at the indices specified by the other 2 arguments

  • modify the function defined above to also

display the number of elements in the list arguments (use the length function)

slide-8
SLIDE 8

8 1/15/2004

function rest

  • Just as first returns the first element of a list,

the rest function returns that part of the list from which the first element has been removed

  • define a function which takes as argument a

list and returns a list of the result of calling first on the list argument and the result of calling rest on the list argument.

slide-9
SLIDE 9

9 1/15/2004

function member

  • The member function

– takes as arguments any lisp object and a list. – searches the list for a list element which is eql to the first argument – returns that part of the list of which the matching

  • bject is the first element
  • define a function which calls member and

returns that part of the list which follows the matching object

slide-10
SLIDE 10

10 1/15/2004

  • ptional arguments to functions
  • Define a function which

– takes 2 required arguments and 2 optional arguments. – Prints each of its arguments

  • Call the function with 2 non-integer

arguments at least once

  • Call the function with 3 arguments, not all of

them integers, at least once

  • Call the function with 4 arguments at least
  • nce
slide-11
SLIDE 11

11 1/15/2004

keyword arguments to functions

  • Define a function doit which

– takes 2 required arguments alpha and beta and 2 keyword arguments gamma and delta. – Prints each of its arguments

  • make each of the following calls to the

function

– (doit 2 3) – (doit 2 3 :gamma 5) – (doit 2 3 :delta 7 :gamma 5)

slide-12
SLIDE 12

12 1/15/2004

rest argument to functions

  • Define a function doit2 which

– takes 2 required arguments alpha and beta and an &rest argument all-the-others – Prints each of its arguments

  • make each of the following calls to the

function

– (doit2 2 3) – (doit2 2 3 5) – (doit2 2 3 ‘july 4 1776) – (doit2 3 4 5 6 7)