Home

ALisp User's Guide

image

Contents

1. 37 REFCN T tas 51 reference GOUNIET s iss se Be EES SR ER ee gek 51 REOGISTER AMOS 41 REGISTER INIT FORM ccococccnccccnnnconno ns 33 REGISTER SHUTDOWN FORM 34 regression testing oooocooccccooccccooncnonancninnnss 32 regular expression iese ee ee ee 15 relative time values ooooonnonccnnnnnccon 34 35 REMHAS Hs 20 remote evaluatton 41 REMOTE EVAL c cccestssoseesconserseesees 42 REMOVE vs ee de Ge De ss 13 remove break point ese esse ee ee ee 47 EE 11 RESP 42 43 44 reset Da 42 45 47 reset pointist rsr eke Ee ee EEN 42 RESET VAR dia aaa 10 RES EE A ed See 13 RETURN using suas e id 28 REVERSE decada 13 rewrite rule sesse sesse se ee ee ee ee ee 28 rewrite rules esse ee esse ee se Re Re ii eiia 7 ROLLOUT Ampuan ed 5 33 34 ROUND se o ees os 16 RPE AC AS dd 14 ea bv Gh Dea e 14 Ak NEE 28 RUN SERVER uno adds 41 SR 49 sampling frequency iese esse se se ee ee 49 SCOPES ni n 45 A ee ede iist 52 SECOND ee 13 SELECTO AA Re Ee Ge 27 SENDEFCIRM e ee ee eeuse eie 42 SE UE 18 SE Ve ES O heme rn emeE 10 SETAS da 19 SETDEMON und 51 SET DIPRERENCE aretes 13 SET ads 11 14 19 20 21 31 33 SETE MACIO EE 33 SETEMETHOD das 33 SES EE 8 10 SEIL TIMER a eto e 34 SEVEN TIO do 13 MN CIS EE 29 SIN aio 17 A 17 ESME MEE E 13 SEBEP lr o 34 SMAS HS oe ee oe ee S 14 socket stream 36 SOCKET POR EE 40 SOCKS ui 39 SOME EE e lol 25 Eli EE 13 sortine list vetar gedd
2. MACRO General CommonLisp iterative control structure 1 Loop can be terminated with RETURN VAL in addition to the ENDTEST DO INITS ENDTEST FORM MACRO As DO but the initializations INIT are done in sequence rather than in parallel DOLIST X L FORM MACRO Evaluate the forms FORM for each element X in list L 27 DOTIMES I N RES FORM MACRO Evaluate the forms FORM N times I varies from 0 to N 1 The optional form RES returns the result of the iteration In RES the variable I is bound to the number of iterations made LOOP FORM MACRO Evaluate the forms FORM repeatedly The loop can be terminated and the result VAL returned by calling RETURN VAL RETURN VAL LAMBDA Return value VAL form the block in which RETURN is called A block can be a PROG LET PROG LET DOLIST DOTIMES DO DO LOOP or WHILE expression RPTQ N FORM SPECIAL Evaluate FORM N times Recommened for timing in combination with the function TIME WHILE TEST FORM MACRO Evaluate the forms FORM while TEST is true or until RETURN is called 3 12 4 Non local returns Non local returns allows to bypass the regular function application order The classical functions for this are CATCH and THROW CATCH TAG FORM evaluates TAG to a catcher which must be a symbol Then FORM is evaluated and if the function THROW TAG VALUE is called with the same catcher then VALUE is returned If THROW is not called the value of
3. FORM 9 MACRO As LET but if RETURN V is called in FORM then PROG LET will exit with the value V The classical PROG and GO are NOT implemented in ALisp The most common use of PROG is as a LET with a RETURN which is supported by PROG LET PROG LET VAR INIT FORM MACRO This function is similar to PROG LET but binds the local variables sequentially like LET QUOTE X SPECIAL Return X unevaluated RESETVAR VAR VAL FORM MACRO Temporarily reset global value of VAR to VAL while evaluating FORM The value of the last evaluated form is returned After the evaluation VAR is reset to its old global value This is similar to declaring VAR being special with DEFVAR as specified by the CommonLisp standard DEFVAR should normally be used SET VAR VAL EXTEN Bind the value of the value of VAR to VAL This function is normally not used the normal function to set variable values is SETQ that does not evaluate its first argument SETQ VAR VAL SPECIAL Change the value of the unevaluated variable VAR to VAL Sec 3 15 is a generalization of SETQ to allow updating of many different kinds of data structures rather than just setting variable values PSETQ VARI VALI VARk VALk MACRO Set in parallell variable VARI to VALI VARk to VALK using SETQ SPECIAL VARIABLE P V EXTEN Return T if the variable V is declared as special with DEFVAR SYMBOL VALUE S EXTFN Ger the global value of the symbol S R
4. Similar to CONS X L but does not add X if it is already member of L tests with EQUAL Make an AND form of the forms in L Make a copy of the concatenated lists L APPEND X copies the top level elements of the list X Append two lists X and Y Search association list ALI for a pair X Y Tests with EQUAL Similar to ASSOC but tests with EQ True if X is not a list or if it is NIL Build a list of same length as L whose elements are all the same X Build a list of length N whose elements all are all the same X Return a copy of list L minus its last element CAR CAR CAR X CAR CAR CDR X CAR CAR X CAR CDR CAR X CAR CDR CDR X same as THIRD X CAR CDR X same as SECOND X CAR X CDAAR X CDADR X CDAR X CDDAR X CDDDDR X CDDDR X CDDR X CDR X CONS X Y CONSP X COPY TREE L EIGHTH L FIFTH L FIRST L FIRSTN NL FOURTH L GETF LI IN X L INTERSECTION X Y INTERSECTIONL L LAST L LDIFF L TL LENGTH X LIST X LIST X LISTP X MEMBER X L MEMO X L MERGE A B FN MKLIST X NATOM X NINTH L 12 EXTFN EXTFN EXTFN EXTFN EXTFN Return the head of the list X same as FIRST X CDR CAR CAR X CDR CAR CDR X CDR CAR X CDR CDR CAR X LAMBDA CDR CDR CDR CDR X EXTFN EXTFN EXTFN EXTFN EXTFN EXTFN CDR CDR CDR X CDR CDR X Retu
5. 1 1 gt gt 2 NIL Notice that macros should not have side effects They should be side effect free Lisp code that transforms one piece of code to another equivalent piece of code For example it is not unusual to use macros to define functions where arguments are automatically quoted For example PP FN1 Fn pretty prints function definitions and the following expression pretty prints the definition of PP itself 29 gt pp pp DEFMACRO PP amp REST FNS Pretty prints function definitions LIST PPF PP LIST QUOTE FNS gt macroexpand pp pp PPF QUOTE PP Let s look at how PP PP is rewritten The function PPF is a lambda function MACROs are made very efficient in ALisp because the first time the interpreter encounters a macro call it will modify the code and replace the original form with the macro expanded one just in time expansion Thus a macro is normally evaluated only once The definition of a macro is a regular function definition but each symbol has a special flag indicating that its definition is a macro The following functions are useful when defining macros Function BQUOTE X Type MACRO DEFMACRO NAME ARGS FORM KWOTE X KWOTED X MACRO FUNCTION FN 30 SPECIAL EXTEN EXTEN EXTFN Description BQUOTE implements ALisp s variant of the CommonLisp read macro back
6. A stream argument NIL or T represents standard input or standard output i e the console Streams normally have functions providing the following operations Open a new stream e g OPENSTREAM FILE MODE creates a new file stream Print bytes to the stream buffer For example PRINT FORM STR prints a form to a stream open for output and iterates through FORM converting encountered data structures to byte strings that are printed to the stream Read bytes from the stream buffer For example READ STR reads of form from a stream open for input and will thereby read bytes from the stream buffer Notice that PRINT and READ are compatible so that a printed form will be recreated by READ Send the contents of a stream to its destination when FLUSH STR is called Close the stream when CLOSESTREAM STR is called The following functions work on any kind of stream Function Type Description CLOSESTREAM STR EXTFN Close stream STR _DEEP PRINT_ GLOBAL Default T Normally the contents of fixed size arrays and structures are printed by PRINT etc This allows I O of such datatypes However when _DEEP PRINT_ NIL the contents of arrays and structures are not printed Good when debugging large or circular structures DRIBBLE FILE LAMBDA Log both standard input and output to FILE The logging stops and the file is closed by calling DRIBBLE NIL Standard input and 36 output is printed on the console as well Notice that only the us
7. By the function profiler the user can dynamically wrap Lisp functions with code to collect statistics on how much time is spent inside particular functions The wrapping profiler is useful to exactly measure how much time is spent in specific functions Notice that the wrapping makes the instrumented function run slower so the wrapping profiler can slow down the system significantly if the wrapped function does not use much time per call 7 4 1 The Statistical Profiler The statistical profiler is turned on by START PROFILE After this the system will start a background timer process that regularly default every millisecond update statistics on what code was executing at that time After starting the statistical profiler you simply run the program you wish to profile When the statistics is collected the percentage most called ALisp functions is printed with PROFILE You may collect more statistics to get better statistics by re running the program and then call PROFILE again Statistical profiling is turned off with STOP PROFILE STOP PROFILE also clears the table of call statistics For example gt start profile STAT FUNCTION gt defun fib x TE Ges 2 TL EE fab x 2 fabs Gs 2 FIB gt fib 30 1346269 gt profile 120 FIB 99 1 DEFUN 0 8 gt stop profile The function PROFILE returns a list where the first element is the number of samples and the rest lists t
8. Value of PROG1 is value of first argument Compond expressions are also implicitly formed by lambda and LET expressions and many control structures described in the next section Function Type Description PROGI X EXTFN Return the value of the first form in X PROG2 X EXTFN Return the value of the second form in X PROGN X EXTFN Return the value of the last form in X 3 12 2 Conditional expressions Conditional expressions are special forms that evaluate expressions conditional on the truth value of some condition The classical Lisp conditional expression is COND For example gt setq x 1 1 gt setq y 2 2 gt setq z nil NIL gt cond x t y 1 1 gt cond z print NO y print YES 5 t print NO YES An alternative to COND is IF PRED THEN ELSE For example the COND expression above can also be written gt if z print NO if y progn print YES 5 print NO ES The function PROGN has to be used to form compound expressions inside the IF Such nested IFs are not recommended as they make the code difficult to read 26 The CASE macro selects forms to evaluate conditional on the value of a test form For example gt case x 1 The test form 0 2 YES Succeeds if x 1 is either 0 or 2 1 NO Succeeds if x 1 is 1 otherwise NO Default case YES X is 1 The following conditional st
9. an EXTEN with gt pp cdddr DEFC CDDDR EXTFN1 CDDDR CDDDR APROPOS prints the documentation of LAMBDA functions and macros For example gt apropos printl PRINTL C AmosNT 1sp orginit lsp 530 53 Print list of arguments on standard output NIL The documentation of a function should be given as a string directly after the formal parameter list as for PRINTL To find where a structure is defined you can search for its construction For example gt apropos make selectbody MAKE SELECTBODY C AmosNT 1sp function lsp 46 Function Type Description DOC FN LAMBDA Return the documentation string for a function FP FUNCTION LAMBDA Print the file position of a function definition The file position of the currently focused function in the break loop is printed with the command fp GREP STRING LAMBDA Print the lines matching the string in all source files currently loaded in the database image This can be slow CALLING FN LEVELS FILE LAMBDA Print the file positions for the functions calling the function FN LEVELS specifies how many levels of functions that call FN indirectly are printed default 1 FILE prints to a file CALLS FN LEVELS FILE LAMBDA Print the file positions for the functions called from function FN LEVELS specifies how many levels of functions that are called indirectly by FN are printed default 1 FILE prints to a file USING S LAMBDA Print the f
10. substituted for the original body of FN So called aspect oriented programming CODE must be a single form The variables of FN are available in CODE If the function is an EXTEN the variable ARGS is bound in CODE to a list of the actual arguments To restore the not wrapped function definition call UNWRAP FN FN TRACE BREAK PROFILE FUNCTIONS and many other packages are based on ADVISE AROUND which allows existing code to be instrumented without changing it Regression testing facility The TEXT is first printed Then each FORM is evaluated and its result compared with the value of the evaluation of the corresponding VALUE If some evaluation of some FORM is not EQUAL to the corresponding VALUE an error notice is printed Clears MEMO FUNCTION cache Dummy defined in ALisp for compatibility with CommonLisp Decrease the current value at location P with V default DECR Enter the ALisp top loop Return to caller when function EXIT is called Return from the ALisp top loop to the program that called it In a stand alone system EXIT is equivalent to QUIT When ALisp is called from some other system EXIT will pass the control to the calling system LAMBDA The identity function MACRO Increase the current value at location P with INCR default 1 LAMBDA Make Lisp function FN into a memo function This means that the EXTEN system caches the arguments of FN when it is called so that it does not execute the function body
11. 1 2 function sqrt sqrt 1 sqrt 2 2 41421 In CommonLisp the system function FUNCALL must be used to call a function bound to a functional argument Also notice that FUNCTION should be used rather than QUOTE when passing a functional argument to be explained next 3 10 1 Closures In the example FUNCTION is used when passing a functional argument QUOTE should not be used when passing functional arguments The reason is that otherwise the system does not know that the argument is a function This matters particularly if the functional argument is a lambda expression Consider a function to compute XN YN using SUM2 gt defun sumpow x y pow sum2 x y function lt FUNCTION must be used here lambda z lambda expression anonymous function expt z pow POW is free variable in lambda SUMPOW gt sumpow 1 2 2 5 Free lambda expressions 1 as this one are very useful when passing free variables like POW into a functional argument Now let s see what happens if QUOTE was used instead of FUNCTION gt defun sumpow x y pow sum2 x y quote This is wrong lambda z expt z pow SUMPOW REDEFINED Suspicious use of QUOTE rather than FUNCTION QUOTE LAMBDA Z EXPT Z POW in SUMPOW SUMPOW lisp 1 gt sumpow 1 2 2 Error 1 Unbound variable POW When evaluating POW FAULTEVAL BROKEN In SUM2 brk gt r As you can see the system warns that
12. Amos II as a subsystem Server side On the server side the following makes an Amos II peer behave as a remote evaluation server accepting incoming forms to evaluate remotely An Amos II name server must be started on some host The name server is an Amos II peer that keeps track of what peers listen to what ports for remote evaluation see 1 To start a name server run on the desired host execute the shell command amos2 n The peer needs to be registered in the Amos II name server used by the peer under some name NAME This is done with REGISTER AMOS NAME REREGISTER For example REGISTER AMOS ME The NAME is a short nick name for the peer The name server keeps track of the nick names of the peers and makes sure that no name collisions occur REREGISTER T means that the system should reregister NAME for this peer even if another peer is registered with the same nick name The OS environment variable AMOS NAMESERVERHOST should be set to the IP host name of the computer where the name server is running Default is the same host as the peer The remote evaluation server must be listening for incoming remote evaluation requests on the port on which it has been assigned for that purpose This is done with RUN SERVER After RUN SERVER is called the peer enters a remote evaluation server loop The loop continues forever or until interrupted with CTRL C If an err
13. break loop 7 1 The break loop The break loop is a Lisp READ EVAL PRINT loop where some special debugging commands are available This happens either when i the user has explicitly specified a break point for debugging specific broken functions ii explicit break points are introduced in the code by calling HELP or ii when an error happens in debug mode For example gt defun FOO gt defun FIE gt foo 1 Error dy When eval FAULTEVA foo x fie x fie y x Undeclared free variable X in FIE Unbound variable uating X BROKEN In FIE br FIE FOO k gt bt FAULTEVA FIE br 0 ENV_ bi D H DI Ke Kl RNO_ 4 Y lt gt 1 o RSR 23X sier 1 1 0 Es FOO BO FAULTEVA LAMBDA error detected BROKEN k gt btv lt gt 3 RRFORM lt gt X ROBJ_ RRMSG_ lt gt X lt gt 1 ERRNO X lt gt Unbound variable ERRMSG 0 0 TTOM BROKEN 0 In FIE db FAULTEVA k gt y BROKEN In FIE 14 343 s gt Kr 3 Warning Run time error System error break point N N Make backtrace Mak detailed backtrace mor This function is called by system whenever Investigate variable y in FIE scope Reset Lisp In the break loop the following break commands are available help lva
14. but the enlarged array may or may not be a copy of the original one depending on its size In other words you have to rebind non adjustable arrays after you enlarge them For example gt setq a make array 3 NIL NIL NIL gt adjust array a 6 NIL NIL NIL NIL NIL NIL gt a NIL NIL NIL gt setq a make array 3 adjustable t NIL NIL NIL gt adjust array a 6 NIL NIL NIL NIL NIL NIL gt a NIL NIL NIL NIL NIL NIL gt Function Type Description 18 ADJUST ARRAY A NEWSIZE EXTEN Increase the size of the array A to NEWSIZE If the array is declared to be adjustable at allocation time it is adjusted in place otherwise an array copy may or may not be returned AREF A D MACRO Access element I of the array A Enumeration starts at 0 Unlike CommonLisp only one dimensional arrays are supported ARRAY TOTAL SIZE A EXTFN Return the number of elements in the one dimensional array A ARRAYP X EXTEN True if X is an array fixed or adjustable ARRAYTOLIST A EXTEN Convert an array A to a list CONCATVECTOR X Y LAMBDA Concatenate arrays X and Y COPY ARRAY A EXTFN Make a copy of the non adjustable array A ELT A D EXTEN Same as AREF A I LISTTOARRAY L EXTEN Convert a list to a non adjustable array LENGTH V EXTFN Returns the number of elements in vector V MAKE ARRAY SIZE INITIAL ELEMENT V ADJUSTABLE FLG MACRO Allocate
15. ede 40 OPENS TREAM see de ei 38 OR RE EE EN 18 PAG ME DER EE 11 PACKE E DES GE 11 EE 13 PATRIAS id 13 parameters iii 46 E 41 pending data oil 41 percentage spent in function 0 0 49 performance profiling iese se ee ee A8 AE REECH 16 point to point Communication esse 40 POLE SOCKET ii sees iii 41 POP tina it 13 NE 38 53 EE 38 A RR eeatt 37 A igesi 29 37 Pretty PEL dea ea eee 38 PRINS SE GR GE EG ee ee As 37 PRING so reta oa aid 37 PRINC CHARCODE ee esse esse see sees 37 PRINT ELE ote 36 37 39 DELI TINGS ss ee e i a ee 6 PRINTERAME sisie eis iste see gis lirios 51 PRINT FUNCTION PROFILES 50 51 ERAN been cote eat ee eins 39 PRINTSTAT vivirla N gegee 51 PROFM E eege ee 49 51 PROFILE FUNCTIONS esse 50 51 PROG EE aan 10 PROG ist 26 PROG2 mae SS 26 PROG LE Ltda 9 PROG LE Ph os Ge ee Ge eet 10 PROGN nia rar 26 PROGNIEY GE aaa ee 31 property MdicatO li 11 property list eee 6 7 10 11 12 property value ista a dias 10 PET 10 PUSH ES a nee ees 13 PUSH VECTOR src datan 19 bi EE N EN 11 EE Eed 21 PUTE ses a 13 PUTHASH isis 20 016 H EE 33 EE de 10 22 24 A O ee eer 43 RANDOM notaras dd 16 RANDOMINIT encirooosisacionini jaa 16 READ BAR VR EG N 36 37 39 READ BY E 37 READ CHARCODE NEE 37 READ LINE ia 37 READ TOREN iii 37 RECONS ee 13 recursive functions esse see esse ee se ee ee 24 Redirect standard output sesse esse sees 37 REDIRECT BASIC STDOUT
16. es 13 EE 53 SPACES di 38 special TOTTS sis SR GES ee GE 7 special variable is ss eess dis ees ges ese he 8 9 SPECIAL VARIABLE P esse sesse 10 SOR EE 17 Stack overflow 33 44 STACKSIZE sumida 33 standard IDEES SEG Ee ees 38 standard OUtDU nicotina ed se de ie 38 START PROFILE esse osse esse sesse ses 49 51 statistical profiler eee esse see ee 48 49 STOP PROFILE dies 49 51 Storage ebe GE EE 51 52 storage manager sesse esse ee ee ee ee 36 LA N SES de ged ee ese 51 STORAGESTAT ass k este sk se sense 51 STORAGE USED ias 51 CO iii dare 36 string delimiter A Season CEA 37 SIRIO o o 15 EE eebe 15 STRING DOWNCASE ees sesse esse 15 STRING LEFT TRIM ees sees esse esse 15 STRING LIKE SE aR 15 STRING LIK BEL Mee natalie 15 STRINGP isis 15 STRING POS daa 15 STRING RIGHT TRIM esse sesse esse 15 STRING TRIM GE 15 STRING UPCASE ies sees bless gese is sees tee 15 o kansien n ia 31 SUBDIS A A A 13 SUBPAIR ads 13 SUBSET see gese N ja 25 e EH NEE 13 SUBS ESSEN ESE DE EA er 13 SUBS TRINO EE EA Re 15 SWAPO GEE ee Ee ee 19 SXHASH ronda tara 20 SYMBOL FUNCTION sesse esse 6 8 SYMBOLEP EA EED NG eg 11 SYMBOL PLIST sirociinionind dci 11 BEIS eege reen 6 SYVMPBOL SETEUNCTION 7 8 SYMBOL V ALUE si n iniciados 10 SEH SUSAM oia ii 28 T global Lisp variable iese ee esse es eee 17 TAN adas 17 tangente et eet 17 CA EE EDE DE 40 TENTH qdo pad 13 TER PR ista das 38 text STEAM ia 39 TEXTSTREAMPO
17. guts tees wat OG EG a 17 ANDIER dde 11 APPEND EES a e 11 APPEND 2 SEEM Ghote Bu Ee 11 APPLY A Used n 23 APPLYARRA Y is oe io DE ee oe 24 APROPOS did 53 ee E 16 ALC SINE A bas 16 ate tangents id esse Ve dee Ge Re Ge es 16 56 AREP Se De eebe de 19 arguments of broken function 47 E 18 array dimension alt 18 ARRA YP usina tia 19 ARRAY TOLIST SG sae este las 19 ARRAY TOTAL SIZE sesse esse sees 19 ASIN cosida dias 16 aspect oriented programming iese 32 Ad 11 association jet 11 PRO OD pts pe DE Ed 11 ATAN EE N aon EE EE N 16 AO titel SR EE SE Oe ae 12 ATOM a serait De ei 11 ATTACH N AE NE 14 Dakgoot EE ME OO N 29 Darkrai O GR anes 45 BAC ICTR AGE EE or EE De iese 50 ro ei EE EE ER ees 44 binary tee uta 11 BOUN DP oia bares 9 BOUOTE MA ER veia 30 BREAK iss ese audi 46 47 51 break commands usar 45 break logos 5 33 44 45 47 breakpoint RE ee s 45 46 break point on external Lisp function 47 break point on function sesse eee se se 46 break point on Macro 2 0 eee eee ete se ee 47 broken function 45 47 BAT ida 20 BUD dia 11 BUILDING EES RE EG ED EE 11 BUTLAS E 11 CAAAR ed Eege 11 ER KEE 11 Kee 11 CADAR ace Gi a na 11 HERE 11 BPN Bears Seen le a te 11 call with variable arity sesse esse ee see es 22 CALUNG EDE BE ee 54 CALLS MEE cheese EN 54 CAR EE N N 11 12 EA El REG Ge ee ee ee 28 CATCHDEMON se Se ses ees ses De 44 EI E WEE 28 CATCH ERROR ie sesse s
18. important that its storage manager is efficient and scales well Thus all data structures are dynamic and can grow without performance degradation The data structures grow gracefully so that there are never any significant delays for data reorganization garbage collection or data copying Except that the OS might sometimes do this outside the control of ALisp There are no limitations on how large the data area can grow except OS address space limitations and the size of the virtual memory backing file The performance is of course dependent on the size of the available main memory and thrashing may occur when the amount of memory used by ALisp is larger than the main memory A critical component in a Lisp system is its garbage collector Lisp programs often generate large amounts of temporary data areas that need to be reclaimed by garbage collection Furthermore as ALisp was designed to be used in a DBMS kernel it is essential that the garbage collection is predictable i e it is not acceptable if the system would stop for garbage collection now and then The garbage collector must therefore be incremental and continuously reclaim freed storage Another requirement for ALisp is that it can share data structures with C in order to be tightly embedded in other systems Therefore unlike many other implementations of Lisp SmallTalk Java etc systems both C and Lisp data structures are allocated in the same memory area and there is no need for ex
19. new seed for RANDOM EXTFN Round X SQRT X EXTFN Compute the square root of the number X SIN X EXTFN Compute sinus TAN X EXTFN Compute tangent ZEROP X LAMBDA True if X 0 3 6 Logical Functions In CommonLisp NIL is regarded as false and any other value as true The global variable T bound to itself is usually used for representing true For example gt setq x t regarded as true T gt setq y nil regarded as false NIL gt setq z 1 regarded as true JR gt or x y zi T X T is the first true value gt and x y zl NIL lt Y is NIL gt or zx y 1 7 1 is the first true value gt not y T lt Y is NIL gt not ei NIL Z is 1 i e true The following functions return or operate on logical values Function Type Description lt X Y EXTFN True if the number X is less than Y lt X Y EXTEN True if the number X is less than or equal to Y X Y EXTEN Tests if two numbers are the same For example 1 1 0 gt T while EQUAL 1 1 0 gt NIL gt X Y EXTEN True if the number X is greater than Y gt X Y EXTEN True if the number X is greater than or equal to Y AND X SPECIAL Evaluate the forms X and return NIL when the first form evaluated to NIL is encountered If no form evaluates to NIL the value of the last form is returned COMPARE X Y EXTEN Compare order of two objects Return 0 if they are equal 1 if less an
20. quote X is substituted for a new expression where gt comma and at sign are recognized as special markers A comma is replaced with the value of the evaluation of the form following the comma The form following an at sign is evaluated and spliced into the list For example after evaluating setq a 1 2 3 setq b 3 4 5 then a b a b or equivalently bquote a b a b both evaluate to fa br OE Pi BI BA BY Very useful for making Lisp macros Define a new MACRO Make X a guoted form Good for making Lisp macros For example KWOTE T gt T KWOTE 1 gt 1 KWOTE A gt QUOTE A KWOTE 1 2 gt QUOTE 1 2 Return T if X is a quoted form For example KWOTED 1 gt T KWOTED QUOTE 1 gt T KWOTED 1 gt NIL Return the function definition of FN if FN is a macro otherwise return NIL MACROEXPAND FORM EXTEN If FORM is a macro return what it rewrites FORM into otherwise FORM is returned unchanged PROGNIFY FORML LAMBDA Make a single form from a list of forms FORML UNFUNCTION FORM LAMBDA Get the function definition of a functional expression 3 14 Defining structures ALisp includes a subset of the structure definition package of CommonLisp The structures are implemented in ALisp using fixed size arrays You are recommended to use structures instead of lists when defining data structures because of their m
21. sede 21 EEN NR EE 7 CERES 12 GETHASH ironia rita 19 20 GETHOSTNAME os eise Bees dees Rg 40 GETTIMEOEDAV sesse esse esse ees se es see 35 global valen RE N RE 6 global variable iss Ge Gees EG ee se GE Ge 9 A N OD 10 GREP SERE aie ea R 54 HARDRESE LT sinc eae a 43 44 hash table keys cisnes 19 HASHBUCKERTHIRSTINATL 20 HASH BUCKE Es 20 HELP Ge dee AE 46 51 higher order functions eee eee eee se ee 21 HOOKS oi Senorita DRS iat GE 33 IDENTITY reeur hiore enii 32 IF26 27 image expansiones 32 51 IMAGE EXPANSION ossee 51 IMAGESIZE cnica 32 ec 12 ii ie io ios ieee a shes 11 INT CHAR ssl 15 INTEGERP ee ees Se is 16 INTERSECTION pasais 12 INTERSECTION E aida 12 eege 25 A late ia dee 24 keyword E 11 KEY WORDP sarao aisla 11 KEYWORD TO ATOM ossee 11 KWOTE gebeten 30 KWOTED MERE SR SS 30 LAMB Da De ie e DE Gie 7 lambda ex pression 22 24 LAMBDA function ee esse see see se ee ee 6 LAMB DAP a ee Ge 8 EAS Trt GR e dete 12 DIEF acia idas 12 LENGTE sat Ee ER ie 12 15 19 O IE ee 8 9 sok E EE ES 9 lexical environment 46 Lisp function defined in Ce 7 LIS Macro toi ad 7 Mi nido 11 LIS EE 12 ed EE EO SE N 12 En H EED SE SEE DE SEE 12 LISTIOARRAY aid 19 LOAD SE N GE EE ED 38 HOC wasn ogi RE RE N 51 local variable 8 9 Toc MOM td ects ee ae ahs 33 AA A 16 Log standard input and output esseses 36 Log top lOO nice EE 36 59 LOSING iii alli 36 37 E 28 lower CAS 15 MIO des 7 30 ma
22. system is running by calling GETHOSTNAME Server side The first step on the server receiving side is to open a socket listening for establishments of incoming connections Two calls are needed on the server side A new socket object must be created which is going to accept on some port registrations of new socket connections from clients This is done with OPEN SOCKET NIL PORTNO For example gt open socket nil 1235 socket NIL 1235 1936 OPEN SOCKET returns a new socket object that will listen on TCP port PORTNO If PORTNO 0 it means that the OS assigns a free port for incoming messages If the OS assigns the port number of socket S can be obtained with the function SOCKET PORTNO S Then the server must then wait for clients to request connections by calling ACCEPT SOCKET S TIMEOUT ACCEPT SOCKET waits for the next OPEN SOCKET call to the server to establish a new connection If TIMEOUT is omitted the waiting is forever it can be interrupted with CTRL C otherwise it specifies a time out in seconds If an incoming connection request is received ACCEPT returns a new socket stream to use for communication with the client issuing the OPEN SOCKET request ACCEPT SOCKET returns NIL if no OPEN SOCKET request was received within the time out period Client side On the client side a call to OPEN SOCKET HOSTNAME PORTNO opens a socket stream to the server lis
23. the mouse pointer For example the function FP FN prints the file position of a function gt fp printl PRINTL C AmosNT 1sp orginit lsp 530 T If you place the pointer over the file name and press F1 you should be placed in a separate Emacs window at the file position where the function PRINTL is defined If F1 is undefined you have not installed init e1 properly If you have edited a function with Emacs it can be redefined in ALisp by cut and paste The key F2 will send the form starting at the pointer position in the file source window to the shell window for evaluation If you don t have the source code you can still look at the definition of PRINTL using PP gt pp printl DEFUN PRINTL amp REST L Print list of arguments on standard output PRINT L PRINTL PP prints the definitions of functions from their internal representation in the database image The appearance in the source file is normally more informative e g including comment lines and with no macros expanded Often you vaguely know the name of a function you are looking for To search for a function where you only know a part of its name use the CommonLisp function APROPOS FN For example gt apropos ddd CADDDR C AmosNT 1sp orginit lsp 47 mn CDDDDR C AmosNT 1sp orginit lsp 45 wee CDDDR EXTEN Here we see that the function CDDDR is an external function with no source code We can inspect its definition and see that it is
24. 2e 20 The following system functions operate on numbers Function X X Y 1 X 14 X 1 X 1 X X XY ACOS X ASIN X ATAN X COS X CEILING X EXP X EXPT X Y FLOOR X FRAND LOW HIGH INTEGERP X LOG X NUMBERP X PLUSP X RANDOM N RANDOMINIT N ROUND X 16 Type Description EXTFN Add the numbers X EXTFN Subtract Y from X MACRO Add one to X which can be both integer and real MACRO Increment the variable X MACRO Subtract one from X which can be both integer and real MACRO Decrement the variable X EXTFN Multiply the numbers X EXTFN Divide X with Y EXTFN Compute arc cosine of X EXTFN Compute arc sine of X EXTFN Compute arc tangent of X EXTFN Compute cosine EXTFN Compute ceiling of X EXTFN Exponent e EXTFN Compute exponent XY EXTFN Compute largest integer lt X EXTFN Generates a real random number in interval LOW HIGH EXTFN True if X is an integer EXTFN Compute natural logarithm of X EXTFN Return the largest of the numbers X EXTFN Return the smallest of the numbers X EXTEN Negate the number X Same as calling X LAMBDA True if lt X 0 EXTFN Return the remainder when dividing X with Y X and Y can be integers or floating point numbers EXTEN True if X is number LAMBDA True if gt X 0 EXTFN Generate a random integer between in interval 0 N EXTEN Generates
25. 4 1 25 35 However this calls enters a break loop Tol 2 3 7 3 Tracing functions It is possible to trace Lisp functions FN with the macro TRACE FN When such a traced function is called the system will print its arguments on entry and its result on exit The tracing is indented to clarify nested calls Macros and special functions can also be traced or broken to inspect that they expand correctly Remove function traces with UNTRACE FN To remove all currently active traces do UNTRACE Analogous to conditional break points conditional tracing is supported by replacing a function name FN in TRACE with a pair of functions FN PRECOND for example gt trace floatp gt 1 2 3 gt GD 22 gt ARGS 1 1 2 lt 3 1 3 1 gt 1 2 1 Sik gt 7 4 Profiling There are two ways to profile ALisp programs for identifying performance problems The statistical profiler is the easiest way to find performance bottlenecks It works by collecting statistics on what ALisp functions were executing at periodic sampled time points It produces a ranking of the most commonly called ALisp functions The statistical profiler has the advantage not to disturb the execution significantly at the expense of not being completely exact 48 The wrapping profiler is useful when one wants to measure how much wall time is spent inside a particular function
26. ACRO Print the real time spent evaluating FORM Returns value of FORM Often used in combination with RPTQ Sec 3 12 TRACE EN MACRO Puta trace on the functions FN Sec 7 3 The arguments and the values will then be printed when any of these functions are called Remove the tracing with UNTRACE TRACEALL FLG EXTEN Trace all function calls if FLG is true The massive tracing is turned off with TRACEALL NIL TRAPDEALLOC X EXTFN Set up a demon so that the break loop is entered when the object X 1s deallocated Good for finding out where objects are deallocated by the garbage collector UNBREAK EN MACRO Remove the break points around the specified functions Sec 7 2 UNPROFILE FUNCTIONS FN JMACRO Remove function profiles from the specified functions Sec 7 4 2 VAG X EXTEN Return the ALisp object at image location X The inverse is LOC X VIRGINEN FN LAMBDA Get the original definition of the function associated with the symbol EN even if FN is traced or broken 8 Code search and analysis As Lisp code is also data it is stored in the internal database image A number of system functions are available for searching and analyzing Lisp code in the image This can be used for finding functions printing function documentation cross referencing functions analysing correctness of functions etc 8 1 Emacs subsystem ALisp can run as a subprocess to Emacs or XEmacs The most convenient way to develop Alisp
27. ALisp v2 User s Guide Tore Risch Uppsala Database Laboratory Department of Information Technology Uppsala University Sweden Tore Risch it uu se 2006 02 22 revised 2011 12 02 ALisp is an interpreter for a subset of CommonLisp built on top of the storage manager of the Amos II database system The storage manager in scalable end extensible which allows data structures to grow very large gracefully and dynamically without performance degradation Its garbage collector is incremental and based on reference counting techniques This means that the system never needs to stop for storage reorganization and makes the behaviour of ALisp very predictable ALisp is written in ANSII C and is tightly connected with C Thus Lisp data structures can be shared and exchanged with C programs without data copying and there are primitives to call C functions from ALisp and vice versa The storage manager is extensible so that new data structures shared between C and Lisp can be introduced to the system ALisp runs under Windows and Linux It is delivered as an executable and a C library which makes it easy to embed ALisp in other systems This report documents how to use the ALisp system 1 Table of contents WUE CUCL ORG E 4 Start AE IS TEE 4 Basic gul th VES RR RA EE Ee 5 Ji Data TEE 6 2 EH ebe ee Meee EE GEE GE ES EE EE 6 3 2 DEMAS TUCASA as 7 3 2 2 Binding variables A O 8 3 2 3 Symbol manipulation iii aini ge Re DEENEN is 10 eN EA
28. AM ese esse esse se ee 39 wrapping profiler esse esse ee ee 49 50 de ii ie AE EE OE ER SEEN 52 ZEROP sisi tiated aided EE 17
29. EE nois 52 EQ EEN 17 EQU 17 ERRCOND ARO ees sees se esse esse ee 43 44 ERRCOND MSG esse se esse ese se 43 44 ERRCOND NUMBER ossee 43 44 ERROR eege 43 44 error CONO led 43 GE 42 o ciety aii as termi ele etal 42 error SLO dl aii it 42 ERROR ee 43 44 escape Charat iia 15 37 EVA Loja RE 23 24 e E EE TEE 32 EVENP GM iio Mes 17 EVER EE rt 25 SAAL EE id 32 A ENE 16 explicit break point esse see se ee ee ee 46 EXPLODE na 10 15 GA 16 EX P ME LE EE N 16 external Lisp function e sesse se se ee ee 7 ARE EE EE AE ER 7 ER RE Se ebe 24 Eeer 6 17 FAULTEVA Espina ae eN ie iS 42 44 FETH GO GE EG EG DR GE eer 12 file posi cc oi se ee de 33 54 file StrEAMS ooccccccnononnninocncnconononananonos 36 38 FILB EXISTS Piso ii rasse sees wanes tia 38 PORN EE 38 finding TUNCHONS Dim 32 finding source code see se ee ee 53 AA EE EE Toe 12 EIRS EN chee GE 12 di RE EA OE N 7 floating point numbers iese se esse es se se 16 PEOR Ee 16 ei EE EE 36 40 FORMA ed 37 FORMAT Lt 37 POUR TH sevi 12 AE wccintenmes 53 54 FRAMENO ts 44 FRAND oeste es ee gis Geo gs Ge Nee N hens 16 free variables oie Se ee Ee ES 22 FUNCAL EE 22 24 FUNCION soi SE ee 22 24 A or OE 6 function deftmton 6 function MASON Ed ee 50 TUNCUION TYPE ae eee eee 7 functional argument 21 functions excluded from sampling 49 garbage collection see ee 4 10 52 GENSYM SES GE ee 10 GET GIS ee Ge Go Ge Eie 10 GET BTREE ees eie eds kase it is ee
30. EEN ER AE EE E E RE N 11 3 3 1 Destaco list IUNEU ONS ed 13 E Be TEE 15 Dede HEET 16 3 6 Logitcal Functions nt A deeg 17 ER ee de RS 18 3 8 A s a Oe ge Ge GE n Ge ese 19 3 9 EE e 20 3 10 Functional arguments and dynamic fOrms ooonooccnoncconnnonnnononcnoncnnnnnonnnonn nono Re ee ee ee ee 21 SS el AE EE EE OR EE ONE EO Secs arene tees N 22 3 10 2 Applying functions with variable arity oooccninccnoccnoncconannnonconncnoncnnnnn nan ncon anno ncnnnos 22 3 10 37 ET e E 23 3 10 4 System functions for run time ewvaluaton siese ee see ee es ee Ge Ge ee ee RR Re ee 23 GEEN Map in eie EER EE OR acd ananassae Gan R ae 24 3 1247 C ntrol SUGGEREER EE A e 25 S21 gt Compound expressions it Ee ER EE Ge SE 26 3 122 eh tee 26 SAQS It raty statements asii 27 3 12 4 Non local TOUS is eie SKEER SN Ge dia sacada caian 28 Bre IM e os ele e 28 LA Dening ter 31 3 15 Miscellaneous UNC iia i aenn e be ee Ge ee ei nee 32 O OO iO a EE OE HOL OE EE ON 33 Time FUNGON Sy Bh Feds AS A EE is a Rockies EE 34 Al Systemi clock EE EE Ee een 34 AD ADSOlUt LM NOESEN 35 43 Relative time Valles aa 35 AA EE GE GE EG ERE 35 Ind dn OUES BESEER ie as Ge des GE GE EG DE EE 36 Sdo oi ie EE EE a 38 de AA GE RE ED GE Ge ES SE EG A 39 O GR EE N eo Re ee GR 39 5 3 1 Point to point communication sees ss ese es did aiii tad 40 5 3 2 Remote evaluation aia 41 Error bandlin ui EE N 42 Gale ABAD PINE EXCUSA saee GE EN eg oe 42 G2 A EE Ee
31. EQUAL LAMBDA Same as CDR EXTEN Return a new list whose elements are the reverse of the top level of L EXTFN Get second element in list L Same as CADR EXTFN Return a list of the elements in X which are not member of the list Y Tests with EQ LAMBDA Get the seventh element of the list L LAMBDA Get the sixth element of the list L LAMBDA Sort the elements in the list L using FN as comparison function EXTFN Substitute elements in the list structure L as specified by the association list ALI that has the format FROM TO For example SUBLIS A 1 B 2 A B A gt 1 2 1 EXTEN Substitute elements in the list L as specified by the two lists FROM and TO Each element in FROM is substituted with the corresponding element in TO For example SUBPAIR A B 1 2 A B A gt 1 2 1 LAMBDA Return true if every element in the list X also occurs in the list Y EXTFN Substitute FROM with TO in the list structure L Tests with EQUAL For example SUBST 1 A A B A gt 1 B 1 LAMBDA Get the tenth element in the list L EXTFN Get the third element of the list L Same as CADDR EXTFN Construct a list of the elements occurring in both the lists X and Y Tests with EQ LAMBDA Construct a list of the elements occurring in all the elements of the list of lists L EXTFN Remove all duplicate elements in the list L Tests with EQUAL 3 3 1 Destructive list functions Th
32. EYWORD TO ATOM X MKSYMBOL X PACK X PACKLIST L PUT SIV PUTPROP A I V REMPROP S I SYMBOL PLIST S SYMBOLP X 3 3 EXTFN EXTEN EXTEN LAMBDA LAMBDA EXTEN EXTEN EXTEN EXTEN EXTEN Lists Return T if X is a keyword i e symbol starting with Convert a keyword X into a regular symbol without the Coerce a string to a symbol The characters of X will be capitalized Pack the arguments X into a new symbol Pack the elements of the list L into a new symbol Set the value stored on the property list of the symbol S under the indicator I to V Same as SETF GET S I V Same as PUT Remove property stored for the indicator I in the property list of symbol S Get the entire property list of the symbol S Return true if X is a symbol Lists data type name LIST represent list structures as binary trees There are many system functions for manipulating lists Two classical Lisp functions are CAR to get the head of a list and CDR to get the tail For example gt setq xx A B C car xx Function ADJOIN X L ANDIFY L APPEND L APPEND X Y ASSOC X ALD ASSQ X ALI ATOM X BUILDL L X BUILDN N X BUTLAST L CAAAR X CAADR X CAAR X CADAR X CADDR X CADR X 11 a b c Type EXTFN LAMBDA MACRO EXTEN EXTEN EXTEN EXTEN LAMBDA LAMBDA EXTEN EXTEN EXTEN EXTEN EXTEN EXTEN EXTEN Description
33. F X Y behaves like SETQ X Y The user can extend the update rules for SETF by defining new SETF macros If a function call FOO is used for accessing an updatable location then the SETF update rule is specified by putting a macro definition on the property list of FOO under the indicator SETFMETHOD The SETF macro should have the format LAMBDA PLACE VAL It is executed when SETF FOO V is called and thereby PLACE is bound to the list FOO and VAL to V The SETF method should return the form to do the desired update STACKTOP SIZE SLACK EXTFN Change or obtain the size of Lisp s variable binding stack SIZE is the total stack size in stack frames while SLACK indicates the number of stack frames that has to remain when an error happens The SLACK allows the break loop to work even when stack overflow happens as it provides some remaining stack space when an error happens The slack should be at least 300 initial setting for the break loop to work The current setting is obtained as a pair by passing NIL as arguments Notice that the SIZE can never be increased beyond the initial setting assigned when the system is started up The initial stack size can be set in C by assigning the global C variable a_stacksize before the system is initialized STACKTOP allows setting a smaller stack size than the initial one to prevent the system from crashing because of C stack overflow which may happen in e g DLLs where the ca
34. FORM is returned For example gt defun foo x catch foo catch fie 1 x FOO gt defun fie y cond y 2 throw foo catch 1 t y A related subject is how to catch errors In particular UNWIND PROTECT is the general mechanism to handle any kind of non local return and error trapping This is described in Sec 6 1 Function Type Description CATCH TAG FORM SPECIAL Catch calls to THROW inside FORM matching TAG THROW TAG VAL EXTFN Return VAL as the value of a call to CATCH with the catcher TAG that has called THROW directly or indirectly 3 13 Macros Lisp macros provide a way to extend Lisp with new control structures and syntactic sugar Because programs are represented as data in Lisp it is particularly simple to make Lisp programs that transform other Lisp programs Macros provide the hook to make such code transforming programs available as first class objects A macro should be seen as a rewrite rule that takes a Lisp expression as argument and produces another equivalent Lisp expression as result For example assume we want to define a new control structure FOR to make for loops e g for i 2 10 print i prints the natural numbers from 2 to 10 FOR can be defined as a macro gt defmacro for var from to do 28 subpair var from to do VAR FROM TO and DO are substituted list var from to do with these actual values let var _from This is the code skele
35. Ge DR ee ENEE dee end Ge Eed 43 6 3 EEE 43 64 Error management e de ee de EG etme es 44 lisp DS DUS PAID ra 44 dl We break LOO py oras 45 1 Breakin tune ONS OE DES SG Eeer 46 TZ Lo Conditional break OES a is 47 A e A OE EE OE HA RE OE ORE OT 48 TAs A Y 48 7 4 1 The Staustical Profiler EE A ae 49 1 4 2 The Wrappins Profilet menot A NOS 50 7 5 System functions for debugging issie sesde VR Ge ese ee N EA Gee RAK Ge se Rds Ge AN Ged es Ede 50 Code search Mee EE E 52 Gla Emacs SUDSYySte EE 52 8 2 e E E OG 53 8 3 Code ven ao al 54 1 Introduction ALisp is a small but scalable Lisp interpreter that has been developed with the aim of being embedded in other systems It is therefore tightly interfaced with ANSII C and can share data structures and code with C ALisp supports a subset of CommonLisp and conforms to the CommonLisp standard when possible However it is not a full CommonLisp implementation but rather such constructs are not implemented that are felt not being critical and difficult to implement efficiently These restrictions make ALisp relatively small and light weight which is important when embedding it in other systems ALisp was designed to be embedded in the Amos II object relational database kernel 3 However ALisp is a general system and can be used as a stand alone system as well This manual documents the stand alone ALisp system with a few exceptions Because it is used in a database kernel it is very
36. QUOTE is used instead of FUNCTION and then the variable POW is unbound when SUMPOW is called The reason is that the system QUOTE returns its argument unchanged while FUNCTION makes a closure of its argument if it is a lambda expression A closure is a special datatype that holds a function lambda expression together with the local variables bound where it is called In our example the local variable POW is bound when SUM2 is called in SUMPOW Thus always use FUNCTION when passing functional arguments 3 10 2 Applying functions with variable arity FUNCALL does not work if we don t know until at run time the number of arguments of the function to call In particular FUNCALL cannot be used if we want to call a function with variable arity like plus What we need is a way to construct a dynamic argument list before we call the function For this the system function APPLY is used For example the function COMBINEL X Y EN applies FN on the elements of X and Y and combines the results also using FN gt defun combinel x y fn 22 funcall fn apply fn x apply fn y COMBINEL gt combinel 1 2 3 4 5 6 function 21 In this case we have to construct the arguments as a list to the inner function applications and therefore APPLY has to be used COMBINEL could also have been written less efficiently as gt defun combinel x y fn apply fn list apply fn x apply fn y COMBINEL REDEFINED COMBINEL
37. S Auen 39 TEXTSTREAMSTRING ee see esse 39 THIRD vasija Fees ede bedes sve 13 TORO Wisin 28 43 TIME Se Ee ee nna aed 52 time TURCOS a Re ees 34 A as 35 NIE Le EE 35 TIME MINUTE eiii 35 TIMEP Me eo ee ne oe ee de eks 35 timer FUNCION eiii 34 TIME SECOND issit esse tese seek Gesie ig 35 AAA Se ek 35 TIMEVAL SE Cuadrados 35 TIMEVAL TO DATE ees esse see sees 35 TIMEVAL USEC issie sees sesse esse ese sees 35 TRACE iaa 48 52 TRACEALE Oe ER Re a ee 32 transform Lisp programs sesse esse es see ee 28 TRAPDEAREBOC saudi 32 DEE A Men ee 6 17 HUL velde ois eee ese see 6 A ER eg eo 6 type tender A Sea nec 39 type taS n EE N eg 6 62 TYPENAME econo 6 33 TYPE READER tati 39 UNE Eeer 47 52 undeclared global variables 8 undefined functions 54 undefined variables ao 54 UNFUNCTION cusco 31 UNION e gtk ero ret thee 13 UNIOND eiiie 13 MUNCH SS GR E E 13 UNLESS Dat ASM RE Bee 27 UNPROFILE FUNCTIONS 50 52 UNRPAD CHARCODE ese see sees 38 UNTRA CE siret e eg Ge 48 UNWIND PROTBCT esse 28 42 44 IN WRAPPING foe carmona 33 PpEr CASE ii diia 15 USING rs tado 54 MAER EED OR oe IE 52 Variables enssins 8 variable arity ticas 22 variable arity external Lisp functions 7 variable number of arguments ssns0eees0 7 VECTOR sants e as eee 19 VERIFY ALL ins 54 VIRGIN EN es Ge e 52 WHEN its is 27 WHILE issues id ile 28 WITH OPEN FILE ee esse see sees 38 39 WITH TEXTSTRE
38. Special forms are printed as EXTFN 2 fn For example gt symbol function quote EXTFN 2 QUOTE 3 The property list Sec 3 2 3 associates property values with the symbol and other symbols called property indicators In function descriptions of this document X indicates that the expression X can be repeated whle X indicates that X is optional Described functions that are similar or equivalent to standard CommonLisp functions are marked with a under Type The Type of a function can be EXTFN defined in C SPECIAL special form LAMBDA defined in Lisp or MACRO Lisp macro Sec 3 13 A system variable can be either SPECIAL dynamically scoped or GLOBAL Sec 3 2 2 3 2 1 Defining functions This section describes the system functions to define and manipulate Lisp functions Function DEFC FN D DEFUN FN EXTENP X Type Description EF EXTFN Associate the function definition DEF with the atom FN Same as SYMBOL SETFUNCTION ARGS FORM SPECIAL Define a new Lisp function LAMBDA Return T if X is a function defined in C FLET FN DEP FORM MACRO Bind local function definitions and evaluate the forms FORM GETD X 7 EXTFN Get function definition of atom NM Same as SYMBOL FUNCTION LAMBDAP X LAMBDA Return T if X is a lambda expression MOVD Fl F2 EXTEN Make F2 have the same function or macro definition as F1 SYMBOL FUNCTION S EXTFN Get the function
39. T resets Lisp In debug mode a break loop is entered when CTRL C is typed For disable delay CTRL C during evaluation of a FORM use DOUNITERRUPTED FORM 43 6 4 Error management functions Below follows short descriptions of system functions and variables for error management Function Type Description CATCH ERROR FORM CLEANUP MACRO Trap and repair errors CLEANUP is optional CATCHDEMON LOC VAL LAMBDA See SETDEMON CATCHINTERRUPT LAMBDA This system function is called whenever the user hits CTRL C Different actions will be taken depending on the state of the system DOUNITERRUPTED FORM MACRO Delays interrupts happening during the evaluation of FORM until DOUNITERRUPTED is exited ERRCOND ARG EC LAMBDA Get the argument of an error condition ERRCOND MSG EC LAMBDA Get the error message of an error condition ERRCOND NUMBER EC LAMBDA Get the error number of an error condition ERROR MSG X EXTFN Print message MSG followed by and X and then generates an error ERROR X LAMBDA True if X is an error condition FAULTEVAL ERRNO ERRMSG X FORM ENV LAMBDA FAULTEVAL is called whenever the system detects an error If the system runs in debug mode FAULTEVAL then enters a break loop Sec 7 1 If the system is not in debug mode FAULTEVAL prints the error message and calls RESET FRAMENO EXTEN Return the frame number of the top frame of the stack HARDRESET EXTEN Does a hard reset ignori
40. TR EOLCHAR EXTFN Read the characters up to just before the next end of line character as a string If EOLCHAR is specified it is used as terminating character instead of end of line READ TOKEN STR DELIMS BRKS STRNUM NOSTRINGS EXTFN Read the next token from stream STR DELIMS are character used as delimiters between tokens default blank tab newline carriage return BRKS are break character i e they become their own tokens default O If STRNUM NIL numbers are parsed into numbers otherwise no special treatment of numeric characters If NOSTRINGS NIL the system will interpret strings enclosed with as in Lisp C Java etc otherwise no special treatment of REDIRECT BASIC STDOUT FILE EXTEN Redirect all standard output to the specified file In case the system is run inside another system e g inside a web server standard output is often disabled and this function allows logging in a file instead To run this function when the system is started use the r file option or make an ALisp image where the AFTER ROLLIN FORMS Section 3 16 redirects standard output 37 An alternative is the function DRIBBLE that prints the user interaction with the ALisp toploop to both a file and the standard input output streams SPACES N STR LAMBDA Print N spaces on the stream STR TERPRI STR EXTFN Print a line feed on the stream STR UNREAD CHARCODE C STR EXTFN Put character C back into strea
41. XTSTREAMPOS TXTSTR EXTEN TEXTSTREAMPOS TXTSTR POS EXTEN TEXTSTREAMSTRING TXTSTR EXTEN CLOSESTREAM TXTSTR EXTEN WITH TEXTSTREAM STR FORM MACRO 5 3 Sockets Description Create a new text stream with an initial buffer size The system automatically extends the initial size when necessary Get the position of the read print cursor in a text stream TXTSTR Move the cursor to the specified position This position is also updated by the regular Lisp I O routines Retrieve the text stream buffer of TXTSTR as a string Notice that this function cannot be used if the buffer contains binary data Reset the cursor to position 0 i e same as TEXTSTREAMPOS TXTSTR 0 Opens a text stream S over the string STR and evaluates the forms FORM with S open The function then closes S and returns the result of the evaluation of the last S expression For example WITH TEXTSTREAM S A B READ S READ S gt B ALisp servers can communicate via TCP sockets Essentially socket streams are abstracted as conventional I O streams where the usual ALisp I O functions work The ALisp functions PRINT and READ are thus used for sending forms between ALisp systems 39 5 3 1 Point to point communication With point to point communication two ALisp servers can communicate via sockets by establishing direct TCP IP socket connections The first thing to do is to identify the TCP host on which an ALisp
42. a one dimensional array of pointers with SIZE elements INITIAL ELEMENT specifies optional initial element values If ADJUSTABLE is true an adjustable array is created the default is a non adjustable array PUSH VECTOR A X EXTEN Adjusts the array A with one element X at the end SETA ATV EXTEN Set the element I in the array A to V Returns V Same as SETF AREF A T V SWAP A El E2 LAMBDA Swap elements El and E2 in the array A VECTOR X EXTFN Make an array with elements X 3 8 Hash Tables Hash tables data type name HASHTAB are unordered dynamic tables that associate values with ALisp objects as keys Hash tables are allocated with MAKE HASH TABLE Notice that unlike standard CommonLisp no initial size is given when hash tables are allocated Instead the system will automatically and incrementally grow or shrink hash tables as they evolve Elements of a hash table are accessed with GETHASH KEY HASHTAB Elements of hash tables are updated with SETF GETHASH KEY HASHTAB NEW VALUE Iteration over all elements in a hash table is made with MAPHASH FUNCTION LAMBDA KEY VAL HASHTAB Notice that comparisons of hash table keys in CommonLisp is by default using EQ and not EQUAL Thus e g two strings with the same contents do not match as hash table keys unless they are pointers to the same string Normally EQ comparisons are useful only when the keys a
43. ach key and value of the hash table HT PUTHASH K HT V EXTEN Set the value stored in the hash table HT under the key K to V Same as SETF GETHASH K HT V REMHASH K HT EXTEN Remove the value stored in the hash table HT under the key K SXHASH X EXTFN Compute a hash code for object X and a non negative integer If EQUAL X Y then SXHASH X SXHASH Y 3 9 Main memory B trees Main memory B trees datatype BTREE are ordered dynamic tables that associate values with Alisp objects as keys The interfaces to B trees are very similar to those of hash tables The main difference between B trees and hash table are that B trees are ordered by the keys and that there are efficient tree search algorithms for finding all keys in a given interval B trees are slower than hash tables for eguality searches B trees are allocated with 20 MAKE BTREE Elements of a B tree are accessed with GET BTREE KEY BTREE SETF is used for modifying accessed B tree element For example gt setq bt make btree BTREE 3396632 gt setf get btr hello bt world world gt get btree hello bt world gt System functions operating on main memory B trees Function Type Description GET BTREE K BT EXTEN Get value of element with key K in B tree BT Comparison uses COMPARE MAKE BTREE EXTEN Allocate a new B tree MAP BTREE BT LOWER UPPER FN EXTFN App
44. al Z initialized to 2 list x y z Return list of the local variables 1 NIL 2 Unlike most programming languages global Lisp variables can also be dynamically scoped so that they are rebound when a code block is entered and restored back to their old values when the code block is exited 1 In CommonLisp dynamically scoped variables are declared using the special system function DEFVAR Dynamically scoped variables provide a controlled way to handle global variables as they are restored as local variables are when a code block is exited Usually dynamically scoped variables have as first character For example assume we have a package to do trigonometric computations using radians degrees or new degrees 8 gt defvar angle unit 1 ANGLE UNIT gt defun mysin x sin MYSIN gt defun hl ang x x HL gt hl 0 785398 10 14 1421 gt setq angle unit 0 0174533 gt hl 45 10 14 1421 gt setq angle unit 0 015708 gt hl 50 10 14 1421 3 1415926 180 3 1415926 200 Units in radians to measure angles x angle unit mysin ang Compute length of hypotenuse using radians Let s us s instead degr Let s us s instead new degr Now suppose we want to have a special version of HL that computes the hypotenuse only for regular degrees gt defun hyplen let hl ang x HY PLEN gt hyplen 45 10 14 1421 gt
45. and returns a new list formed by the values of the applications For example gt mapcar function 1 1 2 3 2 3 4 The function MAPC is similar but does not return any value It is useful when the applied function has side effects For example gt mape function print 1 2 3 T 2 3 NIL MAPC always returns NIL In CommonLisp the basic map functions may take more than one arguments to allow parallel iteration of several lists For example gt mapcar function 1 2 3 10 20 30 11 22 33 Lambda expressions are often useful when iterating using map functions For example gt defun rev2 a b let ra rb mapc lambda x y 24 push x ra push y rb a b list ra rb REV2 gt rev2 1 2 3 a b c 3 2 1 C B A The following system map functions are available in ALisp Function Type ISOME L EN EXTFN MAPC EN L MACRO MAPCAN EN L MACRO MAPCAR EN L MACRO MAPFILTER FILT LST OP Description FN is function with two arguments X and TAIL Apply FN on each element and its tail in list L If FN returns true for some element in L then ISOME will return the corresponding tail of L For example ISOME 1 2 2 3 LAMBDA X TL EQ X CADR TL gt 2 2 3 See also SOME Apply FN on each of the elements of the lists L in parallel Apply FN on each of the elements of the lists L in parallel and NCONC together the results A
46. atabase image For example given that we have registered to above two hooks we can do the following gt rollout myimage dmp Save the database image in a file T gt quit Goodbye The shutdown hook is evaluated c torer gt amos2 myimage dmp Start Amos II with the saved image amos2 myimage dmp Welcome lt The initialization hook is evaluated Amos II Release 7 v7 Amos 1 gt 4 Time Functions Time can be represented in ALisp either as absolute time values or relative time values i e differences between time points Time values are used for storing time stamps measuring time intervals or control system behaviour 4 1 System clock The behaviour of the system can be influenced based on time either by i making the system sleep for time period or ii by running a background timer function at regular time intervals Function Type Description CLOCK EXTEN Compute the number of wall clock seconds spent so far during the run as a floating point number SLEEP SEC EXTEN The system function SLEEP makes the system sleep for SEC seconds It can be interrupted with CTRL C SEC is specified as a real number SET TIMER FN PERIOD EXTEN The function function SET TIMER starts a timer function which is a Lisp function called regularly by the system kernel PERIOD 34 specified the minimal interval between successive calls to the function FN In practice it will not be called that often depending on OS sche
47. atements are available in ALisp Function Type Description CASE TEST WHEN THEN OTHERWISE DEFAULT MACRO For example CASE 1 2 1 HEY 2 3 HALLO OTHERWISE DEFAULT gt HALLO Evaluate TEST and match the value with each of the WHEN expressions For the WHEN expression matching the value the corresponding forms THEN are evaluated and the last one is returned as the value of CASE Atomic WHEN expressions match if they are EQ to the value while lists match if the value is member of the list If no WHEN expression matches the forms DEFAULT are evaluated and returned as the value of CASE If no OTHERWISE clause is present the default result is NIL COND TEST FORM SPECIAL Classical Lisp conditional execution of forms IF P AB SPECIAL If P then evaluate A else evaluate B SELECTO TEST WHEN THEN DEFAULT SPECIAL For example SELECTO 1 2 1 HEN 3 HALLO DEFAULT gt HALLO Same as CASE TEST WHEN THEN OTHERWISE DEFAULT UNLESS TEST FORM MACRO Evaluate FORM if TEST is false WHEN TEST FORM MACRO Evaluate FORM if TEST is true 3 12 3 Iterative statements As in other programming languages Lisp provides iterative control structures normally as macros However in most cases map functions Sec 3 11 provide the same functionality in a cleaner and often more general way Function Type Description DO INITS ENDTEST FORM
48. ble Y in scope of FIE In FIE brk gt f foo Move down the stack to FOO 2 X lt gt 1 FOO 0 FIE BROKEN In FOO brk gt x The focused function is FOO FIE BROKEN In FOO brk gt org Move back to broken function 682 4 SEM 62 FIE 0 FIE BROKEN In FIE brk gt args Look at arguments of broken function Y FIE BROKEN In FIE brk gt r Reset Lisp gt When such a broken function is called the system will also enter a break loop where the above break commands are available Breaks on macros mean testing how they are expanded If you break an EXTEN the argument list is in the variable ARGS The break points on functions can be removed with UNBREAK FN For example UNBREAK FOO FIE To remove all current function breaks do UNBREAK 7 2 1 Conditional break points ALisp also permits conditional break points where the break loop is entered only when certain conditions are fulfilled A conditional break point on a function FN is specified by pairing FN with a precondition function PRECOND BREAK FN PRECOND When FN is called PRECOND is first called with the same parameters If PRECOND returns NIL no break loop is entered otherwise it is For example 47 BREAK FLOATP BREAK CREATETYPE LAMBDA TP EQ TP PERSON Then no break loop is entered by the call
49. code is to run from a shell within XEmacs Emacs should be configured using the file init el It provides extensions to Emacs for finding Lisp code and for evaluating Lisp by ALisp Place init el in the initialization folder of Emacs on Linux the file home emacs or XEmacs under Windows in userprofile Xemacs init lsp When Emacs is started give the command M x shell This will start a new Windows or Unix shell inside Emacs You can there give the usual Windows Unix commands First check that the Emacs init file was loaded correctly by typing F1 If it was loaded correctly there should be a message Error is not a file When Emacs initializes OK run Amos II in the Emacs shell by issuing the command amos2 If you are developing Lisp code enter to the ALisp top loop the command lisp 52 8 2 Finding source code The system contains many Lisp functions and it may be difficult to find their source code To alleviate this there are Lisp code search functions for locating the source codes of Lisp functions and macros loaded in the database image having certain properties Most code search functions print their results as file positions consisting of file names followed by the line number of the source for the searched function Only source code of LAMBDA functions and macros has file positions If Emacs is configured properly the Emacs key F1 defined in init el can be used for jumping to the source code of a file location at
50. cro EXPANSION esse ee ee ee 30 31 MACROEXPAND ee ee ee ee ee ee se ee ee ee ee 31 MACRO FUNCTION ee ee ee see ee 30 MACOS ida 28 MAKE ARRBAY oe EES Ee ee 18 MAKESBTREE a as 21 MAKE ARRAY esse ese ee ee ee ee ee ee 18 19 MAKE BIREE scan a 21 MAKE HASH TABLE 000064 19 20 MAKETEXTSTREAM iesoesesssssssssseees 39 Map FUNGUO E 24 MAP BTREE EE 21 MAP scart scot ses als 24 25 IMIA PE EEN 25 MAPCAR caia 24 25 MAPEIL EER ecc de ee ean 25 MAPHAS Hiatt 19 20 IEA Pod A ely ER di 25 MATCHING ss Gn ore ese SR asis 54 MAN ER OE RE Re ee RR DE RR 16 MEMBER Ee ede n ee eg 12 MEM PUNCTION ees esse esse ee esse ee 32 MEMOLY COMUPUON viii 51 MEMO EE 12 MERGE ibas 12 MAN Sud 16 MINUS a e e 16 MINOS Pad oo 16 MKDATE EE 36 MRS de 12 MES TRIN Goiania 6 15 e TEE reas 11 ME TIME liada 35 MKTIMEVA Lada 35 MOD eege ED 16 MONDE EE 8 Move down the stack 47 name SEIVET esse ese ee se Re Re ee ee ee 41 NATOM it EE 12 natural logarithm eseseeeeseeesseessees seese 16 Ee SE GR 14 NEONGE IS id 14 NEO iaa 18 TICK NAMES nia ii Gea ed 41 Nos 6 17 NIN TH aria 12 NOBIN D Suomi bbe oes sis 10 non blocking messages see ee se ee 42 non local returns sist ee Dee Seeds arias 28 NO a edo 18 NOTAN Y isis 25 EC 14 NEE i destin dae an 13 RN Lei RE 13 INU his tio Ds 13 18 NUMBERP ee fico ER es ek 16 numeric values EE ee 16 A ee n ED ie De Ig 18 Open SEAT inercia is 36 OPEN SOCKE Ta ts ne ees
51. d if greater EQ X Y EXTEN Test if X and Y have the same address EQUAL X Y EXTFN Test if objects X and Y are equivalent Notice that in difference to CommonLisp arrays are equal if all their elements are equal and equality can be defined for user defined data types too 2 EVENP X LAMBDA True if X is an even number 17 NEQ X Y EXTFN Same as NOT EQ X Y ODDP X LAMBDA True if X is an odd number OR X SPECIAL Evaluate the forms X until some form does not evaluate to NIL Return the value of that form NOT X EXTEN True if X is NIL same as NULL 3 7 Arrays Arrays data type name ARRAY in ALisp representation of one dimensional sequences The elements of an array can be of any type Arrays are printed using the notation el e2 For example gt setq a 1 2 3 HL 23 Arrays are allocated with the function MAKE ARRAY SIZE For example gt make array 3 NIL NIL NIL Notice that ALisp only supports 1 dimensional arrays vectors while CommonLisp allows arrays of any dimensionality Adjustable arrays datatype ADJARRAY are arrays that can be dynamically increased in size They are allocated with the function MAKE ARRAY SIZE ADJUSTABLE T Arrays can be enlarged with the function ADJUST ARRAY ARRAY NEWSIZE Enlargement of adjustable arrays is incremental and does not copy the original array Non adjustable arrays can be enlarged as well
52. definition associated with the symbol S Same as GETD SYMBOL SETFUNCTION S D EXTEN Set the function definition of symbol S to D Same as DEFC 3 2 2 Binding variables Symbols hold variable bindings Variables bindings can be either global or bound locally inside a Lisp function or a code block Local variables are bound when defined as formal parameters of functions or when locally introduced when a new code block is defined using LET or other variable binding expressions Both local and global variables can be re assigned using the special system function SETQ In ALisp global variables should be declared before they are used using the system macro DEFGLOBAL ALisp gives warnings when setting undeclared global variables or using them in functions There are a number of built in global variables that store various system information and system objects For example gt setq x 1 WARNING Setting undeclared global variable X because X is undeclared lisp 1 gt defglobal g _ declare G_ as global NIL lisp 1 gt setq g 1 assign number 1 to G_ lisp 1 gt o evaluate G_ isp 1 gt let g 3 New block where local variable G initalized to 3 oO Value of local variable G returned from block 3 lisp 1 gt o Global value did not change LET defines a new code block with new variables For example gt let x 1 Local X initialized to 1 Y Local Y initialized to NIL Z 2 Loc
53. duling and other activities The timer function is terminated if it causes an error signal Sec 6 The statistical profiler Sec 7 4 1 is based on a timer function 4 2 Absolute Time Values The ALisp datatype TIMEVAL represents time points A TIMEVAL object has two components sec and usec representing seconds and micro seconds respecively A TIMEVAL object is printed as TIMEVAL sec usec e g ITIMEVAL 2 3 The following Lisp functions operate on time points Function Type MKTIMEVAL SEC USEC EXTEN TIMEVALP TVAL EXTEN TIMEVAL SEC TVAL EXTFN TIMEVAL USEC TVAL EXTFN GETTIMEOFDAY EXTEN TIMEVAL TO DATE TVAL EXTEN DATE TO TIMEVAL D EXTEN Description Create a new TIMEVAL object Return T if TVAL is a TIMEVAL object otherwise NIL Return the number of seconds for a given TIMEVAL object Return the number of micro seconds for a given TIMEVAL object Return a TIMEVAL representing the wall time from a system call to C s gettimeofday Useful for constructing time stamps Translate a TIMEVAL TVAL into a date A date is a seven element array where the first element is the Year the second Month the third Date the fourth Hour the Minutes the Seconds and the seventh Micro Seconds All elements in the array are integers Translates a date D to a TIMEVAL 4 3 Relative time values Relative time values are represented by the datatype TIME It has three components hour minute and second The follo
54. e list functions introduced so far are constructing new lists out of other objects For example APPEND X Y makes a new list by copying the list X and then concatenating the copied list with the list Y The old X is removed by the garbage collector if no longer needed If X is long APPEND will generate quite a lot of garbage This is not very serious because ALisp has a very 13 efficient garbage collector that immediately discards no longer used objects However sometimes one needs to actually modify list structures by replacing pointers One may wish to do so for efficiency reasons as after all the generation of garbage has its cost Another reason is that some data structures maintained as lists are updated Therefore Lisp has a number of destructive list manipulating functions that replace pointers rather than extensively copying lists Notice that such destructive functions may cause bugs that are difficult to find Therefore destructive functions should be avoided if possible As an example of a destructive list the function RPLACA X Y replaces CAR X with Y For example gt setq a 1 2 3 4 CL 2 34 gt rplaca cddr a 8 Replace CAR CDDR X with 8 8 4 gt a The list held in A has changed 1 2 8 4 gt rplaca a a This makes a circular list Don t do this CCC That makes the printer loop use CTRL C CommonLisp makes it very easy to make destructive list operations using SETF SETF is exp
55. ees didas 43 44 CATCHINTERRUPT 0008 43 44 RN EE 12 CDADR di io 12 EDAR OE Ge ee 12 ODA SE OS GR e 12 CDDDDR EMS Ee EE OE 12 CDDDR EE ly ads Ee RES es ie 12 DORA SE o ee 12 A EE EE N Ee ee 11 12 CEI SEE EG RE tice eons 16 RETTEN 16 COM AR ANT cd als 15 CABEKBOLAL aid 32 circular list EES RE SE ON GEE DE ES SS ges ee 14 cleanup TOT siese ese Ke ienesis 42 CLEAR FUNCTION PROFILES 50 51 CLEAR MEMO FUNCTION 5 32 CLOCK A EE Ee 34 SA PA eo dees ie 36 CLOSE SOCK ED ad es ed 41 CLOSPSTRPANM 36 39 ClOSULE LE EE EE OR aS 22 24 GERHAS H sarita 20 COME pattern A O 54 Code seardh aiii 54 code veficapon 54 CommonLisp futonal 5 COMPARE aos 17 CONOS e e rd 15 CONCATVECTOR css 19 OID ah ae SA iso 26 27 conditional break PONS sees sees see ee 47 conditional tracing esse esse se ee ee 48 COMMECTION asine ees esse ee Re ee ee ee 40 CON AE EE DE 12 CONSP EE 12 CONSTANT Pave ee ee eee 9 control structures 21 28 copy with APPEND AAA 11 COPYSARRA Vta tiza 19 COPY TREE tad 12 57 COS vinilo 16 OOSTE sa sn SR ege eege DE e SEE Ne 16 cross referencing functions CALLING 54 cross referencing functions CALES 54 CTOSS FELETENICING 055 2 seassesannes sierseesadesebes des 52 ENEE 34 40 41 43 44 database Ios ltda 4 5 database image size 32 datatype inn 6 33 datatype ADJARRAY ee sesse es see ee 18 datatype ARRA Yes de Rhee 18 datatype BTRE B sn 20 datatype CLOSURE oci
56. ents of PP are not quoted For example PP PPS PPF PPF L FILE LAMBDA Pretty print the functions and variables in L into the specified file For example PPF PPS PPF pps lsp 38 PRINTL X LAMBDA Print the objects X as a list on standard output TYPE READER TPE FN EXTEN Define the lisp function FN TPE ARGS STREAM to be a type reader for objects printed as TPE X The type reader is evaluated by the ALisp reader when the pattern is encountered in an input stream TPE is the type tag ARGS is the list of argument of the read object X and STREAM is the input stream WITH OPEN FILE STR FILE DIRECTION D FORM MACRO First the stream STR is opened for reading writing or appending of FILE then the forms FORM are evaluated and finally the stream is always closed even if exceptions are raized while evaluating FORM The file is opened for reading if DIRECTION is omitted or D INPUT If D OUTPUT the file is opened for writing Finally if D APPEND it is opened for writing at the end of the file 5 2 Text streams Text streams datatype TEXTSTREAM allow the I O routines to work against dynamically expanded buffers instead of files This provides an efficient way to destructively manipulate large strings Text streams can also store bit sequences blobs The following ALisp functions are available for manipulating text streams Function Type MAKETEXTSTREAM SIZE EXTEN TE
57. er interaction with the system is redirected i e printing to standard output using the basic OS I O routines e g printf in C is not redirected by DRIBBLE To redirect all standard output use the function REDIRECT BASIC STDOUT FORMATL STR FORM LAMBDA This function is a simple replacement of some of the functionality of FORMAT in CommonLisp 1 It prints the values of the forms FORM on stream STR A marker T among FORM indicates a line feed while the string PP makes the next element pretty printed For example FORMATL T One 1 two 2 T prints the line One 1 two 2 PPS S STR LAMBDA Pretty print expression S PRIN1 S STR EXTFN Print the object S in the stream STR with escape characters and string delimiters inserted so that the object can be read with READ STR later to produce a form EQUAL to S PRINC X STR EXTFN Print the object into the stream STR without escape characters and string delimiters PRINC CHARCODE X STR EXTEN Prints character code for number X on stream STR PRINT X STR EXTFN PRINI X STR followed by a line feed READ STR EXTFN Read expression from stream STR IF STR is a string the system reads an expression from the string For example READ A B C gt A B C See also WITH TEXTSTREAM READ BYTES N STR EXTEN Read N bytes from stream STR as string READ CHARCODE STR EXTEN Read one byte from the stream STR and return it as an integer READ LINE S
58. es bind symbols to values and property lists associate data values with properties of symbols Symbols are unique and the system maintains a hash table of all symbols Symbols are not garbage collected and their locations in the dataase image never change It is therefore not advisable to make programs that generate unlimited amounts of symbols Symbols are mainly used for storing system data such as programs while other data structures e g hash tables arrays lists etc are used for storing user data Symbols are always internally represented in upper case and symbols entered in lower case are always internally capitalized by the system The special system symbol NIL represents both the empty list and the truth value false All other values are regarded as having the truth value true Each symbol has the following associated data The print name is a string representing the symbol The print name of a symbol can be accessed by the function MKSTRING For example gt mkstring banana BANANA 1 Symbols represent variables and bind them to values The global value of a symbol Sec 3 2 1 binds it to a global value Most values are local and bound on a variable binding stack maintained by the system when functions are called or code blocks entered 2 Each symbol nm has an associated function cell where the ALisp function definition for the function named nm is stored The function cell of a Lisp symbol nm is retrieved with the CommonLi
59. eturns the symbol NOBIND if no global value is assigned 3 2 3 Symbol manipulation The following system functions do other operations on symbols than handling variable bindings e g managing property lists testing different kinds of symbols or converting them to other data types A property list is represented as a list with an even number of elements where every second element are property indicators and every succeeding element represents the corresponding property value Property lists are often used for associating system information with symbols and can also be used for storing user data However notice that as atoms are not garbage collected dynamic databases should not be represented with property lists The Lisp function GET is used for accessing property lists Sec 3 2 3 Function Type Description ADDPROP S I V FLG EXTFN Add a new value V to the list stored on the property I of the symbol S If FLG NIL the new value is added to the end of the old value otherwise it is added to the beginning EXPLODE S EXTFN Unpack a symbol S into a list of single character symbols Symbols are exploded into symbols and strings into strings For example EXPLODE ABC gt A B C EXPLODE abc gt a p c GENSYM LAMBDA Generate new symbols named G 1 G 2 etc GET SI EXTFN Get the property value of symbol S having the indicator I GETPROP S I EXTFN Same as GET 10 KEYWORDP X K
60. g is supported by specifying pairs FN PRECOND as arguments to PROFILE FUNCTIONS e g PROFILE FUNCTIONS CREATETYPE LAMBDA X EQ X PERSON The function profiler does not double measure recursive functions calls When a functions call causes error throws it is not measured 7 5 System functions for debugging We conclude this chapter with a list of all ALisp system functions useful for debugging Function Type Description BACKTRACE DEPTH FRAME FILTERED EXTEN Print a backtrace of the contents of the current variable binding stack DEPTH indicates how many function frames are printed If FILTERED is true then arguments of EXTFNs are excluded from the backtrace FRAME indicates at what stack frame number the backtrace shall start Default is top of stack _BATCH_ GLOBAL If this variable is true no break loop is entered after errors are detected Instead the system make a backtrace command btv Sec 7 1 and resets the system Useful when running in batch or in 50 BREAK EN MACRO CLEAR FUNCTION PROFILES LAMBDA DEBUGGING FLAG EXTFN servers Put break points on entries to Lisp functions FN so that an interactive break loop is entered when any of the broken functions are called Sec 7 1 Clear the statistics for wrapping profiling Sec 7 4 2 If FLAG is true the system will start running in debug mode where warning messages are printed and the system checks assertions Tu
61. gt combinel 1 2 3 4 5 6 function Sch 3 10 3 Dynamic evaluation The most general way to execute dynamic expressions in Lisp is to call the system function EVAL It takes as argument any Lisp form i e expression and evaluates it For example gt setq a 1 1 gt eval list a 1 gt eval list a This fails because we are trying to evaluate the form 1 Error 15 Undefined function 1 When evaluating 1 FAULTEVAL BROKEN In BOTTOM brk gt r gt list a This gives the same result as the ALisp top loop calls eval 1 EVAL is actually very seldomly used It is useful when writing Lisp programming utilities like e g the top loop or remote evaluation Sec 5 3 2 Avoid using EVAL unless you really need to as the code executed by EVAL is not known until run time and this is very unpredictable and prohibits compilation and program analysis If possible use FUNCALL and APPLY instead In most other cases macros Sec 3 13 replace need for EVAL while at the same time producing compilable and analyzable programs 3 10 4 System functions for run time evaluation Function Type Description APPLY FN ARGL MACRO Apply the function FN on the list of arguments ARGL APPLY is used to call a function where the argument list is dynamically constructed with varying arity 23 APPLY FN ARG ARGx MACRO APPLY with gt 2 arguments ARG ARGx k g
62. he percentage spent in each function Profile takes as argument an optional cut off percentage For example gt profile 1 120 FIB 99 1 gt The sampling frequency is controlled with the global variable PROFILER FREOUENCY It is by default set to 0 001 meaning that up to 1000 samples are made per second In practice the actual number of samples can be smaller The sampling is also influenced by the value of the global variable EXCLUDE PROFILE containing a list of functions excluded from sampling The sampler registers the first call on the execution stack not in this list For advanced profiling it is 49 sometimes useful to exclude the most commonly called functions by adding more functions to EXCLUDE PROFILE_ 7 4 2 The Wrapping Profiler To collect statistics on how much real time is spent in specific ALisp functions and how many times they are called use the wrapping profiler PROFILE FUNCTIONS FN For example PROFILE FUNCTIONS SUBSET GETFUNCTION The calling statistics for the profiled functions are printed optionally into a file with PRINT FUNCTION PROFILES FILE The calling statistics are cleared with CLEAR FUNCTION PROFILES Function profiling can be removed from specific functions with UNPROFILE FUNCTIONS FN To remove all function profiles do UNPROFILE FUNCTIONS Analogously to conditional break points conditional function profilin
63. hl 50 10 14 1421 ang x angle unit 3 1415926 180 Rebind angle unit inside HL Using degrees inside HYPLEN Restored back to new degrees outside HYPLEN The following system functions handle variable bindings Function BOUNDP VAR CONSTANTP X Type Description EXTFN Return T if the variable VAR is bound Unlike CommonLisp BOUNDP works not only for special and global variables but also for local variables SUBR Returns T if X evaluates to itself Same as KWOTED DEFGLOBAL VAR VAL DOC MACRO Declare VAR to be a global variable with optional initial value DEFVAR VAR VAL DOC GLOBAL VARIABLE P VAR LET VAR INIT FORM LET VAR INIT FORM VAL and documentation string DOC Unlike dynamically scoped variables global variables are not temporarily reset locally with LET LET They are much faster to look up than dynamically scoped variables see DEFVAR SPECIAL Declare VAR to be a special variable with optional initial value VAL and documentation string DOC Special variables are dynamically scoped See also DEFGLOBAL LAMBDA Return true if VAR is declared to be a global variable MACRO Bind local variables VAR to initial values INIT in parallel and evaluate the forms FORM Instead of a pair the binding can also be just a variable binding the variable to NIL MACRO As LET but local variables are initialized in sequence PROG LET VAR INIT
64. ile positions for the functions whose definitions contain the symbol S S is usually a variable name MATCHING PAT LAMBDA Print the file positions of functions whose definitions match somewhere the code pattern PAT A pattern is an S expression where the symbol matches everything For example MATCHING map matches functions containing e g the form mapcar print 1 8 3 Code verification ALisp has a subsystem for verifying Lisp code The code verification goes through function definitions to search for code patterns that are seem errorneous It also looks for calls to undefined functions undefined variables etc The code verifier is automatically enabled incrementally when in debug mode However full code verification requires that all functions in the image are analyzed e g to verify that all called functions are also defined To verify fully all functions in the image call VERIFY ALL It goes through all code and prints a report when something incorrect is found For example gt verify all NIL All Lisp functions in image OK 3 75 s 54 gt defun foo x fie x FOO gt verify all Call to undefined function FIE in FOO FOO was not OK NIL 319 S References 1 Staffan Flodin Martin Hansson Vanja Josifovski Timour Katchaounov Tore Risch and Martin Sk ld Amos II Release 11 User s Manual http user it uu se udbl amos doc amos_users_guide html 2 Tore Risch ASto
65. istics on time spent in profiled functions Sec 7 4 2 FILE is optional Print the variable stack frame numbered FRAMENO Print storage usage since the last time PRINTSTAT was called Good for tracing storage leaks and usage Print statistics of time spent in ALisp functions after a statistical profiling execution Sec 7 4 1 Wrap the ALisp functions FN with code to collect statistics on how much real time was spend inside them Sec 7 4 2 Return the reference count of X For debugging of storage leaks Set up a system trap so that when the word at image memory location LOC becomes equal to the integer VAL the system will call the Lisp function CATCHDEMON LOC VAL which by default is defined to enter a break loop The trap is immediately turned off when the condition is detected or when a regular interrupt occurs Very useful for detecting memory corruption in C code interfaced to the system See also 2 Start statistical profiling of a Lisp program Sec 7 4 1 Stop profiling the ALisp program Sec 7 4 1 If FLAG is true the top loop prints how much data was allocated and deallocated for every evaluated Lisp form in the ALisp top loop or AmosQL statement in the AmosQL top loop Very useful for finding storage leaks Evaluate FORM and print a report on how many data objects of different types were allocated by the evaluation TAG is an optional title for the report Good for finding storage leaks TIME FORM M
66. k to AmosQL top loop from the ALisp top loop enter the keyword 0sql When in the ALisp top loop the system reads S expressions evaluates them and prints the results from the evaluation for example gt setq a a b c WARNING Setting undeclared global variable A A B C gt reverse a C B A gt defun foo x 1 a Undeclared free variable A in FOO FOO gt As you can see ALisp warns the user when it encounters forms that may contain errors If you make an error ALisp will enter a break loop where the error can be investigated The simplest thing to do is to enter r to reset the error For example gt your age Error 1 Unbound variable YOUR AGE When evaluating YOUR AGE FAUTEVAL BROKEN In BOTTOM brk gt r a See Sec 7 1 for documentation of all break loop commands The recommended way to learn about ALisp is to run a CommonLisp tutorial e g http mypage iu edu colallen Ip Notice that ALisp is a subset of CommonLisp so not all exercises there are applicable in particular CommonLisp FORMAT function is replaced with a simplified FORMATL Sec 5 and arrays Sec 3 7 are one dimensional All Lisp code and data is stored inside the database image which is a dynamic main memory area The image can be saved on disk with the ALisp function rollout filename which is equivalent to the AmosQL command save filename dmp To later connect Amos II to a previously sa
67. lained in 3 15 The following destructive system list functions are supported Function Type Description ATTACH X L EXTEN Similar to CONS X L but destructive i e the head of the list L is modified so that all pointers to L will point to the extended list after the attachment This does not work if L is not a list in which case ATTACH works like CONS DELETE X L EXTFN Remove destructively the elements in the list L that are EQ to X Value is the updated L If X is the only remaining element in L the operation is not destructive and NIL is returned DMERGE X Y FN LAMBDA Merge lists X and Y destructively with FN as comparison function For example DMERGE 1 3 5 2 4 6 lt gt 1 2 3 4 5 6 The value is the merged list the merged lists are destroyed See also MERGE NCONC L MACRO Destructively concatenate the lists L destructive APPEND and return the concatenated list NCONCI1 L X EXTFN Add X to the end of L destructively i e same as NCONC L LIST X NREVERSE L EXTEN Destructively reverse the list L The value is the reversed list L will be destroyed Very fast reverse RPLACA L X EXTFN Destructively replace the head of list L with X RPLACD L X EXTFN Destructively replace the tail of list L with X SMASH X Y LAMBDA Replace destructively the list X with the list Y 14 3 4 Strings Strings data type name STRING represent text strings of arbitrary length String
68. lling system may have allocated a to small C stack size TYPENAME X EXTEN Get the name of the datatype of object X UNWRAP EN EN LAMBDA Restore the original code for advised functions See ADVISE AROUND 3 16 Hooks Hooks are lists of Lisp functions executed at particular states of the system Currently there is an initialization hook evaluating forms just after the system has been initialized and a shutdown hook evaluating forms when the system is terminated To register a form to be executed just after the database image has been read call REGISTER INIT FORM FORM WHERE 33 The Lisp expression FORM is inserted into a list of forms stored in the global variable AFTER ROLLIN FORMS which are evaluated by the system just after a database image has been read from the disk If WHERE FIRST the form is added in front of the list otherwise it is added to the end For example gt register init form formatl t Welcome t OK To register a form to be evaluated when the system is exited use the system function REGISTER SHUTDOWN FORM FORM WHERE The Lisp expression FORM is evaluated just before the system is to be exited using QUIT The shutdown hook will not be executed if EXIT is called The global variable SHUTDOWN FORMS contains a list of the shutdown hook forms For example gt register shutdown form formatl t Goodbye t OK The hooks are saved in the d
69. ly ALisp function FN KEY VAL on each key value pair in B tree BT whose key is larger than or equal to LOWER and less than or equal to UPPER If any of LOWER or UPPER are the symbol 3 1t means that the interval is open in that end If both LOWER and UPPER are the entire B tree is scanned PUT BTREE K BT V EXTEN Set the value stored in the B tree BT under the key K to V Same as SETF GET BTREE K BT V V NIL gt marking element as deleted NOTICE that the elements are not physically removed when V NIL they are just marked as deleted To physically remove them you have to copy the B tree 3 10 Functional arguments and dynamic forms Variables bound to functions or even entire expression can be invoked or evaluated by the system Functional arguments higher order functions provide a very powerful abstraction mechanism that actually can replace many control structures in conventional programming languages The map functions in Sec 3 11 are examples of elaborate use of functional arguments The simplest case for functional arguments is when a function is passed as arguments to some other function For example assume we want to make a max function SUM2 X Y FN that calls the functional argument FN with X and Y as actual parameters and then adds together the result i e sum2 fn x fn y gt defun sum2 x y fn funcall fn x funcall fn y The system function FUNCALL calls FN 21 SUM2 gt sum2
70. m STR 5 1 File VO File streams are used for print to and reading from files Their type name is STREAM Standard output and standard input are regarded as file streams represented as nil A new file stream is opened with OPENSTREAM FILENAME MODE where MODE can be r for reading w for writing or a for appending For example gt setq s openstream foo txt w STREAM 3396656 gt print hello world 1 s HELLO WORLD 1 gt closestream s STREAM 3396656 gt setq s openstream foo txt r STREAM 3396800 gt read s HELLO WORLD 1 gt closestream s STREAM 3396800 gt The following system functions and variables handles file I O and file streams Function Type Description DELETE FILE FILE EXTFN Delete the file named FILE Returns T if successful FILE EXISTS P NM EXTEN Return T if file named NM exists FILE LENGTH NM EXTEN Return the number of bytes in the file named NM LOAD FILE EXTFN Evaluate the forms in the file named FILE OPENSTREAM FILE MODE EXTEN Open a file stream against an external file MODE is the Unix file mode i e r w or a As errors can happen during the processing of a file causing it not to be closed properly you are advised to use the macro WITH OPEN FILE instead when possible PP EN MACRO Pretty print the functions and variables FN on standard output Notice that argum
71. nation is caused UNWIND PROTECT can be used to achieve this It is possible to trap all errors raised during the evaluation of a form by using the macro CATCH ERROR FORM REPAIR It evaluates FORM and returns the result of the evaluation if successful Should an error occur during the evaluation of FORM then REPAIR is evaluated if supplied and an error condition is returned which looks like ERRCOND ERRNO errmsg X For example gt catch error a ERRCOND 1 Unbound variable Ai The function ERROR X tests if X is an error condition It can be used for testing if CATCH ERROR returned an error condition The functions ERRCOND ARG the object causing the error ERRCOND NUMBER the error number and ERRCOND MSG the error message are used for accessing error condition properties The form REPAIR is evaluated if an error is raised In REPAIR the variable ERROR CONDITION is bound to the error condition 6 2 Raising errors The function ERROR MSG X print and error message MSG and raises an error for X The error number is always 1 user error To cause an error signal without any error message call RESET As any other error these functions will go through the regular error management mechanisms User errors can be caught with UNWIND PROTECT or CATCH ERROR 6 3 User interrupts After an interrupt is generated e g CTRL C the system calls the Lisp function CATCHINTERRUPT By default CATCHITERRUP
72. ng FN Set new current frame one step up the stack Set new current frame one step down the stack arg N Function that returns N th argument in current frame b VAR Enter new break loop when VAR becomes bound The variables bound in the current frame are inspectable in the break loop because variables in a break loop are evaluated in the lexical environment of the current frame It is possible to explicitly insert a break loop around any Lisp form in a program by using the macro HELP TAG When HELP is called a break loop is entered where the user can investigate the environment with the usual break commands The local variables in the environment where HELP was called are also available The TAG is printed to identify the occurrence of the HELP call Very good for debugging complex Lisp functions 7 2 Breaking functions Explicit break points can be put on the entry to and exit from Lisp functions by the Lisp macro BREAK fn For example gt break foo fie Put break point on FOO and FIE FOO FIE lisp 1 00 L FOO BROKEN In break point of FOO In FOO brk gt Print parameters of FOO and their values 46 X 1 FOO BROKEN In FOO brk gt eval FIE BROKEN Evaluate the body of FOO The broken function is FIE N N N In FIE brk gt The focused function is also FIE Y 1 FIE BROKEN In FIE brk gt y Evaluate varia
73. ng UNWIND PROTECT Called after fatal errors such as stack overflow RESET EXTEN Signals an error The control is returned to the latest reset point The reset point is either the ALisp top loop or the latest call to UNWIND PROTECT UNWIND PROTECT FORM CL SPECIAL UNWIND PROTECT enables the user to clean up after a local or non local exit 7 Lisp Debugging This section documents the debugging and profiling facilities of ALisp To enable run time debugging of ALisp programs the system should be put in debug mode This is automatically done when entering the ALisp top loop To enable Lisp debugging also in the AmosQL top loop call DEBUGGING T To disable debugging in the ALisp top loop call DEBUGGING NIL In debug mode the system checks assertions at run time and analyses Lisp function definitions for semantic errors and thus runs slightly slower Also in debug mode the system will enter a break loop when an error occurs instead of resetting Lisp as described next The interactive break loop for debugging is difficult or even impossible if you are using the system in a batch environment or an environment where an interactive break loop cannot be entered e g under PHP For debugging in batch environments set the global variable BATCH to true SETQ _BATCH_ T When BATCH is set and the system is in debug mode errors are trapped and cause a backtrace to be printed 44 printed after which the error is thrown without entering the
74. ns the number of characters in string S Coerce an atom to a string Change all ASCII characters in string STR into lower case Change all ASCII characters in the string STR to upper case Return T if the string S1 alphabetically precedes S2 Return T if the strings S1 and S2 are the same EQUAL works too Remove initial characters in STR occurring in CH Returns T if PAT matches string STR PAT is regular expression where matches any sequence of characters zero or more matches any character SET matches any character in the specified set SET or SET matches any character not in the specified set Case insensitive STRING LIKE Return the character position of the first occurrence of the string X in STR The character positions are enumerated from 0 and up Remove trailing characters in STR occurring in CH Remove both initial and trailing characters in STR occurring in CH Returns true if X is a string Returns the substring in STR starting at character position P1 and ending in P2 The character positions are enumerated from O and up 3 5 Numbers Numbers represent numeric values Numeric values can either be integers data type name INTEGER or double precision floating point numbers data type name REAL Integers are entered to the Lisp reader as an optional sign followed by a sequence of digits e g 1234 1234 1234 Examples of legal floating point numbers De EE E SDs 2 1 12 3 1 2E3 1 e4 1
75. or occurs during the remote evaluation the default behaviour is that the error 41 message is shipped back to the caller However if the server is in debug mode Sec 7 1 server errors will be trapped there Client side On the client side to ship a FORM for evaluation on an Amos II peer with nick name PEER simply call REMOTE EVAL FORM PEER The result of the remote evaluation is shipped back to REMOTE EVAL REMOTE EVAL blocks until the result is received Errors occurring on server are shipped back to client For non blocking messages use instead SEND FORM FORM PEER The difference to REMOTE EVAL is that FORM is evaluated on PEER on its own the client does not wait for the result and is thus non blocking Errors are NOT sent back SEND FORM is faster than REMOTE EVAL in particular when the messages are large If you want to synchronize after many non blocking messages sent with SEND FORM end with a REMOTE EVAL For example the following form will return the number 1000 assuming that an Amos II peer named FOO is running progn send form setq xx 0 foo dotimes i 10000 send form 1 xx foo remote eval xx foo 6 Error handling When the system detects an error it will call the Lisp function FAULTEVAL ERRNO MSG O FORM FRAME where ERRNO is an error number 1 for not numbered errors MSG is an error message O is the failing Lisp objec
76. ore efficient and compact representation A new structure S is defined with the macro DEFSTRUCT S FIELD1 for example gt defstruct person name address PERSON DEFSTRUCT defines a new structure S with fields named FIELD1 pointing to arbitrary objects DEFSTRUCT generates a number of macros and functions to create and update instances of the structure New instances are created with MAKE S FIELD1 VALUEL for example gt setq p make person name Tore address Uppsala PERSON Tore Uppsala The fields of a structure are updated and accessed using accessor functions generated for each field S FIELD S for example gt person name p Tore Fields are updated by combining SETF with an accessor function SETF S FIELD S VAL For example gt setf person name p Kalle Kalle gt person name p Kalle An object O can be tested to be a structure of type S using the generated function S P 0 31 For example gt person p p T 3 15 Function ADVISE AROUND FN CODE LAMBDA Miscellaneous functions Type CHECKEQUAL TEXT FORM VALUB CLEAR MEMO FUNCTION FN LAMBDA DECLARE DECF P V DECR EVALLOOP EXIT IDENTITY X INCF P V INCR MEMO FUNCTION FN IMAGESIZE SIZE 32 SPECIAL MACRO MACRO EXTFN EXTFN Description Wrap the body of function FN with form CODE where each is
77. os cid cies caaseessacadaveseas 22 datatype DATE iis ait et ances 35 datatype HASHTAB se 19 datatype INTEOGER AAA 16 datatype LIS Tiida 11 datatype EE 16 datatype SOCKET sees esse ee see 36 datatype STREAM ee ese esse ee 36 38 datatype STRIN Gregoriano 15 datatype SYMBOL eee sees soe ee ee ee 6 datatype TESTSTREANM ese 36 39 datatype TIME ese Ge ci sde ed 35 datatype TIMEVAL esse esse esse es se ee ee 35 date Vales 35 DATE DAY ti GE es 36 DATE MONTH essa diri 36 DATEP a ed ence 36 DATE TO TIMEVAL ees esse esse se ee 35 DATE Y BAR dia 36 debug mode 42 43 44 45 54 DEBUGGING EEN 44 51 debugging Macros eiii da 29 DECLARE nds 32 Bode Gee tea 7 8 DEFGLOBAL innesti 8 9 DEEMACRO aia 7 30 DERSTRUET ee Ee 31 DEFUN tl a 7 DEN AR ivi 8 9 DELETE RSG Ge Ge 14 DELEIE HILE EG MS RS EG 38 destructive CONS siste ndiisartass 14 destructive list concatenation s s00 14 destructive list element removal 14 destructive list manipulation sss0se0s0e 14 destructive list merge voii sede des 14 egent 14 DMERGE sort 14 A SEE EE ETE 27 DOF A 27 DOE ER Ee as 54 ASUMEN ON sd 52 54 DOLIST unas 27 DOTIMES ee 28 double precision EE 16 DOUNITERRUPTED ee esse esse ss 43 44 DRIBBLE ais 36 DUMPSTAGK tai 46 51 dynamic argument list ee eee ence 22 dynamic expressions iese se ee ee ee 23 dynamic SCOPING i ees see ee ee ee ee Ge ee 8 EIGH CH EE 12 EET EE ter 19 Emacs
78. pensive copying of large data areas between C and Lisp This is essential for a predictable interface between C and Lisp in particular if it is going to be used for managing large database objects as in ALisp s main application Section 2 describes the system functions in ALisp The differences w r t CommonLisp are documented Section 3 gives an overview of the debugging facilities while Section 4 describes the error handling mechanisms Section 5 describes the I O system The storage manage and how to extend ALisp with new datatypes and functions implemented in list is described in separate document 2 ALisp includes a code search system to allow for searching for Lisp code having certain properties Sec 8 The code search system is connected to Emacs and XEmacs to allow for finding Lisp source code A code validation system Sec 8 searches through Lisp code to find possible errors such as unbound variable undefined functions or other questionable Lisp code 2 Starting ALisp ALisp is a subsystem of Amos II 1 Amos II is started with the OS command amos2 The same directory as where Amos II is started must have a database image file with a system Amos II database amos2 dmp When Amos II is started it runs the AmosQL top loop where it accepts and evaluates AmosQL commands from the console 4 To enter the ALisp top loop where Lisp expressions are evaluated rather than AmosQL give the AmosQL command lisp To go bac
79. pply EN on each of the elements of the lists L in parallel and build a list of the results EXTEN If OP NIL return the subset of the elements for which the filter function FILT returns true If OP is specified the result is transformed by applying OP on each element of the subset For example MAPFILTER FUNCTION NUMBERP A 1 B 2 F 1 x 1 x gt 2 3 See also SUBSET MAPL FN L MACRO Apply EN on each tail of the lists L SUBSET L FN EXTEN Return the subset of the list L for which the function FN returns true EVERY EN L MACRO Return T if EN returns non nil result when applied on every element in the lists L in parallel NOTANY FN L MACRO Apply EN on elements in the lists L in parallel Return T if FN does not return true for any element SOME FN L MACRO Apply FN on elements in the lists L in parallel Return T if FN returns non NIL value for some element 3 12 Control Structures Syntactic sugar and control structures are implemented in Lisp as macros and special functions This subsection describes system functions macros and special forms 25 3 12 1 Compound expressions The compound functions PROGN PROG1 and PROG2 are used for forming a single form out of several forms This makes sense only if some of the forms have side effects For example gt progn print AT B MAN Br Value of PROGN is value of last argument gt progl print TA B CH AY
80. rage a main memory storage manager UDBL Dept of Information Technology Uppsala University http user it uu se torer publ aStorage pdf 2009 3 T Risch V Josifovski and T Katchaounov Functional Data Integration in a Distributed Mediator System in P Gray L Kerschberg P King and A Poulovassilis eds Functional Approach to Data Management Modeling Analyzing and Integrating Heterogeneous Data Springer ISBN 3 540 00375 4 2003 http user it uu se torer publ FuncMedPaper pdf 4 Guy L Steele Jr Common LISP the language Digital Press http www cs cmu edu Groups Al html cltl clt12 html 55 Index 16 ARGS abe Sethe Gis Shee DE 47 16 BACKTRACE DEPTH esse esse 46 16 ERREOND ELS SES eno SE GE ds 43 OSG i a a OE 5 BATCH Si OIE ee ie 50 PDEEE PRINT Se tense De ees 36 _ERROR CONDITION oocccccncnncncnncnnnnn ns 43 _EXCLUDE PROFILE_ coocococnccncnccncnnnnnns 49 _PROFILER FREQUENCY_ 006 49 16 lt 17 ees Socata eben dds idad 17 17 gt 17 AR RE ahi a deine 17 1 16 Le accent ME EE EE EL Re 16 TA 16 E E 16 CET E 33 absolute time values n nnsosonsono0000s0s00 34 ACCEPT SOCKET sao 40 accessor FUNCTIONS ees ees esse ee Re ee 31 AE OSSE EG DE De 16 PDD PROP sa EE ER loci 10 ADJON oia ol 11 Adjustable arrays din 18 ADIUST ARRAN 18 19 ADVISE AROUND ie siekes ese dee 32 AFTER ROLLIN FORMS esse sesse 34 AMOS NAMESERVERHOST 41 analyze EE 52 AND ag
81. re symbols To specify a hash table comparing keys with EQUAL e g for numeric keys or strings use MAKE HASH TABLE TEST FUNCTION EQUAL 19 Example gt setq htl make hash table HASHTAB 2547944 gt setf gethash hello ht1 world world gt gethash hello ht1 NIL gt setq ht2 make hash table test function equal HASHTAB 2548104 gt setf gethash hello ht2 world world gt gethash hello ht2 world gt The following system functions operate on hash tables Function Type Description CLRHASH HT EXTEN Clear all entries from hash table HT and return the empty table GETHASH K HT EXTFN Get value of element with key K in hash table HT HASH BUCKET FIRSTVAL HT EXTFN Return the value for the first key stored in the hash table HT What is the first key is undefined and depends on the internal hash function used HASH BUCKETS HT EXTEN Compute the number of buckets in the hash table HT HASH TABLE COUNT HT EXTFN Compute the number of elements stored in the hash table HT MAKE HASH TABLE SIZE S TEST EQEN MACRO Allocate a new hash table The CommonLisp parameter SIZE is ignored as the hash tables in ALisp are dynamic and scalable The keyword parameter TEST specifies the function to be used for testing equivalence of hash keys TEST can be FUNCTION EQ default or FUNCTION EQUAL MAPHASH FN HT V EXTFN Apply FN KEY VAL V on e
82. rn off debug mode by calling with FLAG false Notice that the system by default is in debug mode when the ALisp top loop is entered but can be turned on by calling DEBUGGING NIL DUMPSTACK FRAME EXTEN Print all the contents of the variable binding stack If FRAME is HELP TAG MACRO provided it specifies the starting stack frame number otherwise the printing starts at the current top of the stack To insert explicit break points in Lisp code The TAG indentifies the HELP call For example HELP FOO IMAGE EXPANSION RATE MOVE EXTEN When the database image if full it is dynamically expanded by the LOC X EXTFN PRINT FUNCTION PROFILES FILE LAMBDA PRINTFRAME FRAMENO EXTFN PRINTSTAT EXTEN PROFILE LAMBDA PROFILE FUNCTIONS EN MACRO REFCNT X EXTEN SETDEMON LOC VAL EXTEN START PROFILE LAMBDA STOP PROFILE LAMBDA STORAGESTAT FLAG LAMBDA STORAGE USED FORM TAG SPECIAL 51 system This function controls the expansion RATE is how much the image is to be expanded default 1 25 If MOVE is true the image will always be copied to a different place in memory after image expansion If MOVE is false it may or may not be copied To test system problems related to the moving of the image the following call will make the image move a lot when data is loaded IMAGE EXPANSION 1 0001 T Return the location handle of Lisp object X as an integer The inverse is VAG X Print stat
83. rn the tail of the list X same as REST X Construct new list cell Test if X is a list cell Make a copy of all levels in list structure To copy the top level only use APPEND L LAMBDA Get the eighth element from list L LAMBDA Get fifth element in list L EXTFN LAMBDA Get first element in list L Same as CAR L Return a new list consisting of the first N elements in the list L LAMBDA Get fourth element in list L EXTFN EXTFN EXTFN LAMBDA EXTFN Get value stored under the indicator I in the property list L IN returns T if there is some substructure in L that is EQ to X Build a list of the elements occurring in both the lists X and Y Tests with EQUAL Make the intersection of the lists in list L Return the last tail of the list L E g LAST 1 2 3 3 LAMBDA Make copy of L up to but not including its tail TL EXTFN EXTFN EXTFN EXTFN EXTFN EXTFN Compute the number of elements in a list the number of characters in a string or the size of a vector Make a list with the elements X Is similar to LIST except that the last argument is used as the end of the list For example LIST 1 2 3 gt 1 Ps 3 LIST 1 2 A gt 1 2 A This function returns true if X is a list cell or NIL Tests if element X is member of list L Tests with EQUAL Returns the tail of L where X is found first For example MEMBER 1 2 1 1 2 1 2 3 gt 1 2 1 2 3 a
84. rs fp 45 Print variables bound by current frame Print summary of available debugging commands i e this list Names of local variables bound at current frame Print file position of function at current frame sub bt btv bty eval value Unbreak the function at current frame Print a backtrace of functions at current frame The depth of the backtraces is controlled by the special variable B ACKTRACE DEPTH that tells how many function frames should be printed Its default is 10 Print a detailed backtrace of the frames below the current frame Print a long backtrace including all stack contents To print the complete variable binding stack use the function DUMPSTACK FRAME that print everything pushed on the stack starting at frame number FRAME Evaluate current frame Lisp variable bound to value of evaluating current frame with eval Its value is UNEVALUATED if eval has not yet been called It cannot be reset by SETQ return x Return value x from the broken frame i e the frame where the break loop was entered He GEEN NX pr Continue evaluation from broken frame where the break loop was entered The value of variable V ALUE 1s used as return value from the break loop if eval has been called beforehand Reset to ALisp top loop Change current frame to the previous broken frame or reset if there is no previous broken frame Set current frame to first frame down the stack calli
85. s MEMBER but tests with EQ instead of EQUAL LAMBDA Merge the two lists A and B with FN as comparison function EXTEN EXTEN For example MERGE 1 3 2 4 function lt gt 1 2 3 4 X is returned if it is NIL or a list Otherwise LIST X is returned Return T if X is not an atom and not NIL Anything not being a list is an atom LAMBDA Get ninth element in list L NTH NL NTHCDR N L NULL X PAIR X Y PAIRLIS X Y POP L PUSH X VAR PUTF LIV RECONS X Y L REMOVE X L REST L REVERSE L SECOND L SET DIFFERENCE X Y SEVENTH L SIXTH L SORT L FN SUBLIS ALI L SUBPAIR FROM TO L SUBSETP X Y SUBST TO FROM L TENTH L THIRD L UNION X Y UNIONL L UNIQUE L EXTFN Get the Nth element of the list L with enumeration starting at 0 EXTFN Get the Nth tail of the list L with enumeration starting at O EXTEN True if X is NIL EXTFN Same as PAIRLIS EXTFN Form an association list by pairing the elements of the lists X and Y SPECIAL Same as SETQ L CDR L MACRO Add X to the front of the list bound to the variable VAR same as SETQ VAR CONS X VAR EXTEN Set the value of the indicator I on the property list L to V LAMBDA Similar to CONS X Y but if the result object has the same head and tail as L then L is returned Useful for avoiding to copy substructures EXTFN Remove all occurrences of X from the list L Tests with
86. s containing the characters or must precede these with the escape character Examples of strings gt setq a This is a string This is a string gt setq b String with string delimiter and the escape character String with string delimiter and the escape character gt concat a b This is a stringString with string delimiter and the escape character gt Function Type CHAR INT STR EXTEN CONCAT STR EXTEN EXPLODE STR EXTEN INT CHAR X EXTEN LENGTH S EXTFN MKSTRING X EXTFN STRING DOWNCASE STR EXTFN STRING UPCASE STR EXTFN STRING lt S1 S2 EXTFN STRING S1 S2 EXTFN STRING LEFT TRIM CH STR EXTFN STRING LIKE STR PAT EXTFN STRING LIKE I STR PAT EXTFN STRING POS STR X EXTFN STRING RIGHT TRIM CH STR EXTFN STRING TRIM CH STR EXTFN STRINGP X EXTFN SUBSTRING P1 P2 STR EXTFN 15 Description Returns the integer encoding the first character in string STR Unlike CommonLisp there is no special data type for characters in ALisp and instead CHAR INT takes a string rather than a character as argument Coerce the arguments STR to strings and concatenate them Makes a list of the characters in X list of strings If possible return the character string with the encoding integer X otherwise return NIL Unlike CommonLisp there is no special data type for characters in ALisp and instead a string with a single character is used Retur
87. sp function SYMBOL FUNCTION nm that returns the function definition of nm if there is one otherwise it returns nil A function definition can be one of the following 1 A lambda function which is a function defined in Lisp Sec 3 2 1 A lambda function definition is 6 ii iii iv v represented as a list LAMBDA args body It is defined by the system special function DEFUN e g gt defun rev x cons cdr x car x REV gt rev 1 2 2 1 A macro Sec 3 13 is defined by the system special function DEFMACRO A macro is a Lisp function that takes as its argument a form and produces a new equivalent form Many system functions are defined as macros They are Lisp s rewrite rules An external Lisp function 1s implemented in C 2 A external Lisp function is represented by a special data type named EXTEN and printed as EXTFNn fn where n is the arity of the function and fn is its name E g the definition of CONS is printed as EXTFN2 CONS The EXTEN data structure contains a pointer to the C definition For example gt symbol function car EXTFN1 CAR A variable arity external Lisp function can take a variable number of actual arguments It definition is printed as EXTFN 1 fn For example gt symbol function list EXTFN 1 LIST A special form is a external Lisp functions with varying number of arguments and where the arguments are not evaluated the standard way
88. t FORM is the last Lisp form evaluated when the error was detected FRAME is the variable stack frame where the error occurred The ALisp default behaviour of FAULTEVAL first prints the error message and then calls the function RESET to signal an error to the system an error signal To reset Lisp means to jump to a pre specified reset point of the system By default this reset point is the top level read eval print loop It can also be a unwind protection to be explained next 6 1 Trapping exceptions The special form UNWIND PROTECT enables trapping error signals and clean up after error signals UNWIND PROTECT FORM CLEANUP The FORM is evaluated as usual until it is terminated whether naturally or by means of a regular exit or an error signal The cleanup form CLEANUP is then evaluated before control is handed back Note that the cleanup form of an UNWIND PROTECT 42 is not protected by that UNWIND PROTECT so errors produced during evaluation of CL can cause problems The solution is to nest UNWIND PROTECT The function HARDRESET bypasses UNWIND PROTECT and directly resets the system UNWIND PROTECT traps any local or non local exit including error signals and THROW Sec 3 12 For example a throw form may cause a catcher to be exited leaving a file open This is clearly undesirable so a mechanism is needed to close the file and do any other essential cleaning up on termination of a construct no matter how or when the termi
89. t 2 In this case the dynamic argument list is constructed by inserting ARG ARG 1 into ARG i e the dynamic argument list becomes LIST ARG ARGx APPLYARRAY EN A EXTEN Apply the Lisp function FN on the arguments in the array A EVAL FORM EXTFN Evaluate FORM Unlike CommonLisp the form is evaluated in the lexical environment of the EVAL call F L FN ARGS FORM MACRO F 1 X FORM lt gt FUNCTION LAMBDA X FORM is equivalent to the CommonLisp read macro also supported LAMBDA X FORM FUNCALL FN ARG1 EXTEN Call function FN with arguments ARG1 FUNCALL is used when the called function FN is computed at run time e g bound to a variable FUNCTION FN SPECIAL Make a closure of the function FN Do not use QUOTE for functional expressions as ALisp will then not know that a closure Section 3 10 1 should be formed 3 11 Map functions Map functions are functions and macros taking other functions as arguments and applying them repeatedly on elements in lists and other data structures Map functions provide a general and clean way to iterate in a functional programming style over data structures They are often a good alternative to the more conventional iterative statements Sec 3 12 3 They are also often a good alternative to recursive functions as they don t eat stack as recursive functions do The classical map function is MAPCAR It applies a function on every element of a list
90. tening on port number PORTNO on host HOSTNAME HOSTNAME must not be NIL which would indicate aserver connection socket The result of OPEN SOCKET is a SOCKET object which is a regular ALisp VO stream that can be used by any I O function Thus once OPEN SOCKET is called the regular Lisp I O functions can be used for communication A SOCKET stream behaves like any other I O stream Notice that data is not sent on a socket stream before calling the function FLUSH S To check whether there is something to read on a socket use 40 POLL SOCKET S TIMEOUT POLL SOCKET returns T if something arrived on socket stream S within TIMEOUT seconds and NIL otherwise Polling can be interrupted with CTRL C When a client has finished using a socket it can be closed and deallocated with CLOSE SOCKET S Notice that all pending data is lost when CLOSE SOCKET is called The garbage collector automatically calls CLOSE SOCKET when a socket object is deallocated 5 3 2 Remote evaluation There is also a higher level remote evaluation mechanisms where system can be set up as a server evaluating incoming Lisp forms from other Amos II peers With remote evaluation Lisp forms are sent from one peer to another for evaluation there after which the result is shipped back to the caller The remote evaluation requires the receiving peer to listen for incoming forms to be evaluated The remote evaluation mechanism requires ALisp to run inside
91. ton while lt var to _do setq var 1 var FOR lisp 1 gt for i 2 4 print i Macros expanded by interpreter 2 3 4 NIL Value of FOR When defining macros as in the example one normally have a code skeleton in which one replaces elements with actual arguments In the example we use SUBAIR to do the substitution A more convenient CommonLisp facility to define code skeleton is to use backquote which is a variant of QUOTE where pieces can be marked for evaluation Using backquote FOR could also have been written as gt defmacro for var from to do let var from while lt var to e BE setq var 1 var FOR REDEFINED FOR gt for i 2 4 print i 2 3 4 NIL gt The backquote character marks the succeeding expression to be back quoted In a back quoted expression the character indicates that the next expression is to be evaluated Macros can be debugged like any other Lisp code Sec 7 In particular it might be interesting to find out how a macro transform a given call For this the system function MACROEXPAND can be used normally in combination with pretty printing with PPS Sec 5 For example macroexpand for i 2 4 print i LAMBDA I WHILE lt I 4 PRINT I SETQ I 1 1 2 pps macroexpand for i 2 4 print i LAMBDA 1 PPS makes more readable printing of code WHILE lt I 4 PRINT 1 SETO I
92. ved image issue the OS command amos2 filename dmp 3 Basic Primitives This section describes the basic Lisp data types and the functions operating over them 5 The CommonLisp standard functions are defined in 1 Significant differences between an ALisp function and the corresponding CommonLisp function are described in the function descriptions in this document 3 1 Data types Every object in ALisp belongs to exactly one data type There is a system provided type tag stored with each object that identifies its data type Each data type has an associated type name as a symbol The symbolic name of the data type of an ALisp object O can be accessed with the ALisp function TYPENAME 0 ALisp provides a set of built in basic data types However through its C interface ALisp can be in addition extended with new datatypes implemented in C The system tightly interoperates with C so that i data structures can be shared between C and ALisp Sec 8 11 the ALisp garbage collector is available in C Sec 8 111 ALisp can call functions implemented in C as documented in 2 iv ALisp functions can be called from C and v C can utilize ALisp s error management 3 2 Symbols A symbol data type name SYMBOL is a unique text string with which various system data can be associated Symbols are used for representing functions macros variables and property lists Functions and macros represent executable ALisp code variabl
93. when it is called repeatedly to speed up execution CLEAR MEMO FUNCTION EN clears the cache Implemented by ADVISE AROUND For example memo function defun fibonacci x if lt x 2 1 fibonacci x 1 fibonacci x 2 Extend the system s database image size to SIZE If SIZE NIL the current image size is returned The image is normally extended automatically by the system when memory is exhausted However the automatic image expansion may cause a short halting of the system while the OS is mapping more virtual memory pages By using IMAGESIZE these delays can be avoided QUIT EXTFN Quit Lisp If ALisp is embedded in another system it will terminate as well ROLLOUT FILE EXTEN Save the ALisp memory area image in file FILE It can be restored by specifying FILE on the command line the next time ALisp is started SETF P1 V1 P2 V2 MACRO Update the location Pi to become Vi A location can be e g a variable value a structure element a property a hash table index or a B tree index More than one location can be updated at once A location Pi is specified with a particular access function depending on the kind of desired update e g AREF updating arrays GETL updating free property lists GETPROP updating symbol property lists GETHASH updating hash tables GET BTREE updating B trees or PUSH POP CAR CDDDR FIRST TENTH REST updating lists It can also be a symbol in which case SET
94. wing functions operate on relative times Function Type MKTIME HOUR MINUTE SECOND Description EXTEN Construct a new TIME object TIMEP TM EXTFN Return T if TM is a TIME otherwise NIL TIME HOUR TM EXTEN Return the number of hours given a TIME TM TIME MINUTE TM EXTEN Return the number of minutes given a TIME TM TIME SECOND TM EXTEN Return the number of seconds given a TIME TM 4 4 Relative Date Values Relative date values are represented by the datatype DATE It has three components year month and day The 35 following functions operate on dates Function Type Description MKDATE YEAR MONTH DAY EXTFN Construct a new date DATEP DT EXTFN Return T if DT is a date otherwise NIL DATE YEAR DT EXTFN Return the number of years DATE MONTH DT EXTFN Given a date DT return the number of months given a date DT DATE DAY DT EXTEN Return the number of days given a date DT 5 Input and Output The I O system is based on various kinds of streams A stream is a datatype with certain attributes allowing its instances to be supplied as argument to the basic Lisp I O functions such as PRINT and READ Examples of streams are i file streams type STREAM for terminal file I O ii text streams type TEXTSTREAM for reading and writing into text buffers and iii socket streams type SOCKET for communicating with other Amos II Alisp systems The storage manager allows the programmer to define new kinds of stream 2

Download Pdf Manuals

image

Related Search

Related Contents

Trust 2.1 Speaker Set SP-3500  DMC-FZ30PP DMC-FZ30PL DMC-FZ30EB DMC  AD-5601A AD-5605H AD  Trust eLight, DE  MANUEL DE REPARATION  Samsung 2233RZ Benutzerhandbuch  Avaya 3920 Wireless Telephone User`s Guide  gohastings.com POWERPOD 400 User's Manual    SNB-9000 User Manual  

Copyright © All rights reserved.
Failed to retrieve file