home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / E17INFO.ZIP / CL next >
Encoding:
GNU Info File  |  1993-06-18  |  30.8 KB  |  870 lines

  1. This is Info file ../info/cl, produced by Makeinfo-1.55 from the input
  2. file cl.texinfo.
  3.  
  4.    Copyright (C) 1987 Cesar Quiroz
  5.  
  6. 
  7. File: cl,  Node: Top,  Next: Generalities,  Up: (DIR)
  8.  
  9. Common Lisp Extensions
  10. **********************
  11.  
  12.    The routines described in this chapter provide some of the
  13. functionality of Common Lisp inside Emacs Lisp.
  14.  
  15. * Menu:
  16.  
  17. * gen: Generalities.           Things you need to know.
  18. * sym: Symbols.                Gensym, gentemp, keyword-p, ...
  19. * lis: Lists.                  List*, pairlis, acons, ...
  20. * seq: Sequences.              Every, any, notevery, notany, ...
  21. * con: Conditionals.           When, unless, case, ecase.
  22. * ite: Iterations.             Do, do*, dolist, dotimes, ...
  23. * mul: Multiple Values.        Values, values-list, ...
  24. * ari: Integer Arithmetic.     cl-floor, cl-ceiling, cl-round, cl-truncate, ...
  25. * stf: Generalized Variables.  Setf and friends.
  26. * str: Structures.             Like Pascal records or C structs.
  27. * mis: Miscellanea.            Odds and ends that didn't fit elsewhere.
  28. * tod: To Do.                  Suggestions for future hackery.
  29.  
  30. 
  31. File: cl,  Node: Generalities,  Next: Symbols,  Prev: Top,  Up: Top
  32.  
  33. Generalities
  34. ============
  35.  
  36.    This section tells you want you need to know about the routines in
  37. the file `cl.el', so that you can use them.  The distribution also
  38. includes this documentation and perhaps a few example files.
  39.  
  40. License, Availability, Maintenance
  41. ----------------------------------
  42.  
  43.    These files are covered by the GNU Emacs General Public License (if
  44. you don't know its terms, try `C-h C-c') and the statement of no
  45. warranty (again, you can type `C-h C-w' if you don't know its terms)
  46. also applies to them.
  47.  
  48.    I, Cesar Quiroz, the original author of the software described here,
  49. will appreciate hearing about bug reports (and fixes), suggestions and
  50. comments, applying both to the code and to this documentation.  I don't
  51. promise to act on those communications, but whenever they might conduce
  52. to improvements of this software, I will make those improvements
  53. available to the general community through the Free Software
  54. Foundation.  You can reach me at the following net addresses:
  55.      quiroz@seneca.cs.rochester.edu quiroz@rochester.arpa {allegra |
  56.      seismo | ... } ! rochester ! quiroz CSNET: Cesar Quiroz at node
  57.      Rochester
  58.  
  59. Purpose and Limitations
  60. -----------------------
  61.  
  62.    These routines were written with two purposes in mind:
  63.  
  64.   1. To make programming in Emacs Lisp even more compatible with Common
  65.      Lisp.  Indeed, my original motivation was to have a `do' macro.
  66.  
  67.   2. To facilitate to novice Lisp programmers a chance to practice with
  68.      features commonly found only in expensive implementations of Lisp.
  69.  
  70.    In order to satisfy these purposes, the routines were written in
  71. such a way that it is practical to use them inside Emacs: no effort was
  72. given to implement features that could slow down the host Emacs
  73. unnecessarily nor require recoding of the Emacs Lisp interpreter.
  74.  
  75.    For instance, no support is given to floating point arithmetic.
  76.  
  77.    So, I have tried to implement a subset of the functionality of
  78. Common Lisp.  Whatever is implemented, has syntactic and semantic
  79. properties like the equally named features of Common Lisp, but not all
  80. the relevant features have been implemented (*note To Do::., for some
  81. suggestions).  When deciding what to include, I have tried to strike a
  82. balance between these constraints:
  83.  
  84.   1. Keep it simple, I didn't want to spend much time in this idea.
  85.  
  86.   2. Keep it compatible with Common Lisp.
  87.  
  88.   3. Keep it flexible, so my code doesn't oppose a better
  89.      implementation (when this looked hard, I just didn't implement the
  90.      feature).
  91.  
  92.   4. Keep an eye on the intended use of Emacs Lisp: to support an
  93.      advanced editor.  I don't expect that more arithmetic support will
  94.      be as conducive to this goal as having better iterations and
  95.      conditionals will.
  96.  
  97.    For background, the reference is "Common Lisp: The Language" by Guy
  98. Steele Jr. (Digital Press, 1984).  For all the features described here
  99. you can assume that the intent has been to provide the syntax and
  100. semantics of the features of like name in the book.  For the most part,
  101. this documentation will concentrate on how my routines fail to
  102. implement Common Lisp faithfully.
  103.  
  104. Specific Limitations
  105. ....................
  106.  
  107.    Emacs Lisp and Common Lisp differ enough to make some of the
  108. emulation difficult, expensive or nearly impractical.  Some specific
  109. limitations are stated here:
  110.  
  111.   1. Common Lisp is lexically scoped (mostly), while Emacs Lisp is
  112.      dynamically scoped.  Things like `block', `return', `tagbody' are
  113.      then practically impossible to imitate correctly (in principle,
  114.      rewriting `eval', `apply' and a couple of other functions would
  115.      suffice, problem is that such rewriting amounts to  a new
  116.      interpreter on top of the old.)  Things like `implicit-blocks',
  117.      `implicit-tagbodies' and the like have not been implemented at all.
  118.      Where they are needed, the most you can assume is that I tried to
  119.      put `implicit-progns' around places where it made sense.
  120.  
  121.   2. Emacs Lisp's `lambda' does not support all the possible argument
  122.      markers.  Similarly, `defmacro' doesn't support automatic
  123.      destructuring of the calls.  An approximation to a keyword-based
  124.      calling style was implemented, mainly for the sake of `defstruct',
  125.      but is not general enough.
  126.  
  127.   3. Emacs Lisp supports arithmetic only on integers.
  128.  
  129.   4. Emacs Lisp doesn't support many of the basic types of Common Lisp.
  130.      In particular, there are no arrays beyond vectors and strings
  131.      (although these ones are compatible), characters are essentially
  132.      small integers, etc.
  133.  
  134.   5. There are no declarations in Emacs Lisp (in the sense of Common
  135.      Lisp's `declare', `proclaim', ...) nor there is a explicit lattice
  136.      of types.  These limitations could be effectively overcome from
  137.      Lisp code (to a extent), but I don't see them as a very pressing
  138.      need, if a need at all in Emacs Lisp.  `defstruct' can be used to
  139.      generate new types that can be recognized at runtime.
  140.  
  141.   6. The Emacs Lisp reader is not programmable.  The syntax it accepts
  142.      is almost standard, but it preempts '?' as a dispatching macro of
  143.      sorts.  The `format' function is incompatible with Common Lisp.
  144.      There isn't a `quasi-constant' notation (the usual `backquote' of
  145.      Common Lisp).  None of these differences causes any problems when
  146.      writing Emacs Lisp (although the lack of backquoting is felt
  147.      sorely), but they oppose a Common Lisp emulation.
  148.  
  149.  
  150. Loading and Compiling
  151. ---------------------
  152.  
  153.    The file `cl.el' provides the `cl' feature, you can use this to test
  154. whether these routines have been loaded, or to load them from your code
  155. (by means of `(require 'cl)').  The compiled file is a little larger
  156. than 50K bytes.
  157.  
  158.    If you need to recompile the sources, make sure you load them first
  159. on the Emacs that will do the recompilation.  This is because many
  160. syntactic characteristics (like the special forms) have been
  161. implemented as macros and you need to make sure that macros are known
  162. to the compiler before they are used.
  163.  
  164.    These extensions work correctly when interpreted in a GNU Emacs of
  165. version 17.64 or beyond.  Compiling them requires a more recent byte
  166. compiler, preferably one strictly younger than version 18.XX.
  167.  
  168. On Line Help
  169. ------------
  170.  
  171.    The routines in this file have documentation strings, so you can (and
  172. should) consult them for the exact syntax allowed.  That information is
  173. not repeated in this manual.  Some of the routines are also documented
  174. explicitly in the Common Lisp reference, their doc-strings begin with
  175. `[cl]' to represent this fact.
  176.  
  177.    The rest (those without the `[cl]' mark) are auxiliary functions or
  178. macros used by the rest of the implementation.  They are not constrained
  179. by any standard and are advertised only in as much as they can be useful
  180. in other applications.
  181.  
  182.    Each of the following sections contains a subsection called `Features
  183. Provided'.  It lists briefly the user-visible features of this
  184. implementation.  In its entries, names by themselves refer to functions.
  185. Macros and variables are identified by a `MACRO' or a `VARIABLE' ahead
  186. of their names.
  187.  
  188. 
  189. File: cl,  Node: Symbols,  Next: Lists,  Prev: Generalities,  Up: Top
  190.  
  191. Symbols
  192. =======
  193.  
  194.    The most important omission is that of a PACKAGES mechanism.  (For a
  195. possible implementation, *note To Do::.)  Whenever a Common Lisp
  196. function expects a package, I have substituted an obarray.  There is a
  197. hack to have pseudo-keywords, see below.
  198.  
  199.    There are two other notorious omissions over which I haven't lost any
  200. sleep.  The first is the lack of a `remprop' function, which could be
  201. easily provided if needed.  The second is the lack of ways to modify the
  202. print name of a symbol.  This one would probably be good only to
  203. introduce strange bugs, so I don't miss it.
  204.  
  205. Features Provided
  206. -----------------
  207.  
  208. `VARIABLE *gensym-index*'
  209. `VARIABLE *gensym-prefix*'
  210. `VARIABLE *gentemp-index*'
  211. `VARIABLE *gentemp-prefix*'
  212.      These variables are used to keep the state of the generator of new
  213.      names.  Better leave them alone.
  214.  
  215. `gensym'
  216. `gentemp'
  217.      These do the same as the Common Lisp names of like names.
  218.  
  219. `MACRO defkeyword'
  220. `keyword-of'
  221. `keywordp'
  222.      These provide the pseudo-keywords implementation.
  223.  
  224. Keywords
  225. --------
  226.  
  227.    The lack of packages makes it difficult to implement keywords
  228. correctly.  I have provided a macro `defkeyword' that takes a symbol
  229. and makes sure it evaluates to itself.  (So, it is like `defconst'.)
  230. If your programs ever need keywords, put a bunch of calls to
  231. `defkeyword' at the beginning of your code, so when loaded they will be
  232. in effect.
  233.  
  234.    The (standard) predicate `keywordp' tests to see if the given
  235. symbol's name begins with a colon and then ensures that it evaluates to
  236. itself.
  237.  
  238.    The function `keyword-of' takes a symbol and returns a keyword of
  239. like name.
  240.  
  241.       (keyword-of 'foo)
  242.      :foo
  243.       (keyword-of ':bar)
  244.      :bar
  245.  
  246.    This feature was added mainly to support `defstruct' and the tests of
  247. the sequence functions.  It is fragile and easy to fool.
  248.  
  249. New Symbols
  250. -----------
  251.  
  252.    A common need (especially when writing macros) is to be able to
  253. invent new names for things.  I provide the `gensym' and `gentemp'
  254. functions.  The global state needed is kept in the variables
  255. `*gentemp-index*', `*gentemp-prefix*', `*gensym-index*' and
  256. `*gensym-prefix*'.  Changing them, especially the index ones, is a very
  257. bad idea.  I am not providing the Common Lisp default prefixes ('G' for
  258. `gensym' and 'T' for `gentemp') because of debugging paranoia.  My
  259. default prefixes are harder to come by when giving sane names to
  260. things.
  261.  
  262. 
  263. File: cl,  Node: Lists,  Next: Sequences,  Prev: Symbols,  Up: Top
  264.  
  265. Lists
  266. =====
  267.  
  268.    Lists (indeed, conses) are so deeply involved in Lisp that there
  269. seems to be little need to justify improving the list handling of a
  270. Lisp.
  271.  
  272.    Common Lisp, however, is a rather huge Lisp.  I haven't provided all
  273. the functions in the chapter of lists, mainly because some of them
  274. could be implemented correctly only if keyword arguments were supported.
  275. That explains why I haven't rushed to provide `subst', `sublis', etc.
  276. Also, that explains the rather temporary nature of the implementation
  277. of `member' and `adjoin'.  I will welcome any efforts to extend this
  278. work.
  279.  
  280. Features Provided
  281. -----------------
  282.  
  283. `endp'
  284. `list*'
  285. `list-length'
  286.      Very standard utilities.  List* has proven especially useful to
  287.      overcome the lack of a real `backquote'.  In addition, things that
  288.      usually required the relatively clumsy
  289.           (cons 'a (cons 'b oldlist))
  290.           (append (list a b) oldlist)
  291.      can now be simply put:
  292.           (list* 'a 'b oldlist)
  293.      See also `acons'.
  294.  
  295. `member'
  296.      Another well known function.  Supports test with `eql' only.
  297.  
  298. `acons'
  299. `pairlis'
  300.      These two are part of the standards association lists
  301.      implementation.  I am leaving `sublis' as an exercise for the
  302.      reader.
  303.  
  304. `adjoin'
  305.      Done mainly for the sake of `pushnew'.
  306.  
  307. `butlast'
  308. `last'
  309. `ldiff'
  310.      Occasionally useful ways to access the last cons or a specified
  311.      tail of a list.  I don't remember why there isn't a `tailp' here.
  312.  
  313. `c[ad][ad][ad][ad]r, up to four a's or d's'
  314.      These 28 functions (and their setf inverses) have been provided
  315.      once and for all.  Many packages contributed to Emacs Lisp contain
  316.      macros that implement some of these, I think this code will make
  317.      most of them unnecessary.
  318.  
  319. `first'
  320. `rest'
  321. `second'
  322. `third'
  323. `fourth'
  324. `fifth'
  325. `sixth'
  326. `seventh'
  327. `eighth'
  328. `ninth'
  329. `tenth'
  330.      More standard accessors (and their setf inverses).  Not
  331.      particularly useful but easy to provide.
  332.  
  333. `setnth'
  334. `setnthcdr'
  335.      These functions are non-standard.  They are here for `defsetf'
  336.      purposes only, but they might be useful on their own.
  337.  
  338. 
  339. File: cl,  Node: Sequences,  Next: Conditionals,  Prev: Lists,  Up: Top
  340.  
  341. Sequences
  342. =========
  343.  
  344.    Sequences are partly supported in Emacs Lisp (see, for instance, the
  345. `elt' function).  This limited support is compatible with Common Lisp,
  346. so it should be easy to extend.  However, the lack of keyword arguments
  347. makes many of the functions impossible so far (but, as mentioned below,
  348. a basic framework for that extension is provided here).
  349.  
  350.    The functionality really provided here is given by the functions
  351. (essentially, predicates) `every', `some', `notevery', `notany'.  I
  352. have found them useful countless times, so I thought to provide them
  353. before anything else.
  354.  
  355.    That still leaves many omissions, though.
  356.  
  357. Features Provided
  358. -----------------
  359.  
  360. `every'
  361. `notany'
  362. `notevery'
  363. `some'
  364.      Extremely useful functions.  If your favorite Lisp doesn't have
  365.      them, you are missing a lot.
  366.  
  367. `setelt'
  368.      A setf-inverse to `elt'.
  369.  
  370. `add-to-klist'
  371. `build-klist'
  372. `extract-from-klist'
  373.      A "klist" is just an alist whose keys are keywords.  I based the
  374.      pseudo-keyword argument support of `defstruct' on this idea, but
  375.      their best fit is here, as they could help to write the remaining
  376.      sequence-handling functions (`find', `substitute', ...) that I
  377.      didn't provide for the lack of a good keyword arguments mechanism.
  378.  
  379. `elt-satisfies-if-not-p'
  380. `elt-satisfies-if-p'
  381. `elt-satisfies-test-p'
  382. `elts-match-under-klist-p'
  383.      The Common Lisp book defines some of the semantics of sequence
  384.      functions in terms of satisfaction of certain tests.  These
  385.      predicates provide that functionality, but I haven't integrated
  386.      them with the rest of the extensions.  However, I thought it was
  387.      better to include them anyway, as they can serve somebody else as
  388.      a starting point.
  389.  
  390. 
  391. File: cl,  Node: Conditionals,  Next: Iterations,  Prev: Sequences,  Up: Top
  392.  
  393. Conditionals
  394. ============
  395.  
  396.    An elementary incompatibility prevents us from producing true Common
  397. Lisp here.  The `if' forms are different.  In Emacs Lisp, `if' can take
  398. any number of subforms, there being a CONDITION form, a THEN form, and
  399. after them any number of ELSE subforms, which are executed in an
  400. implicit `progn'.  Moreover, that style is widely used in the Emacs
  401. sources, so I thought most impractical to break with it to support
  402. Common Lisp's `if' (where only one ELSE form is tolerated).  For the
  403. most part, I use `cond' almost always, so it doesn't bother me much.
  404. If you use single-branch `if's often, consider `when' or `unless' as
  405. alternatives.
  406.  
  407.    `case' and `ecase' are a convenient way to write things that usually
  408. end up in a very baroque `cond'.
  409.  
  410. Features Provided
  411. -----------------
  412.  
  413. `MACRO case'
  414. `MACRO ecase'
  415. `MACRO unless'
  416. `MACRO when'
  417.      The standard stuff, completely implemented.
  418.  
  419. 
  420. File: cl,  Node: Iterations,  Next: Multiple Values,  Prev: Conditionals,  Up: Top
  421.  
  422. Iterations
  423. ==========
  424.  
  425.    Having a `do' macro was my original motivation.  The alternatives in
  426. standard Emacs Lisp are either expensive (recursion) or correspond
  427. directly to the expansion of my macros:
  428.       (macroexpand '
  429.        (do ((i 0) (j 1 (+ 1 j)))
  430.            ((> j (foo i)) (cons i bar))
  431.          (setq i (baz i j))))
  432.      
  433.      (let ((i 0) (j 1))
  434.        (while (not (> j (foo i)))
  435.          (setq i (baz i j))
  436.          (psetq j (+ 1 j)))
  437.        (cons i bar))
  438.    So I prefer to leave to the macros the problem of remembering the
  439. details right.
  440.  
  441.    The incompatibilities are due to the problems already discussed
  442. (*note Generalities::., for more details).
  443.  
  444.    If you write Emacs Lisp code often, you will find enough uses for
  445. these.  Examples are cooking up a translation table to move C-s out of
  446. the way of multiplexers, switches, concentrators and similar fauna, or
  447. building keymaps.
  448.  
  449. Features Provided
  450. -----------------
  451.  
  452. `MACRO do'
  453. `MACRO do*'
  454. `MACRO dolist'
  455. `MACRO dotimes'
  456.      The standard, but for the lack of implicit blocks.
  457.  
  458. `MACRO loop'
  459.      The basic standard one, not the fancy one.  As per the book, warns
  460.      you about atomic entries at the surface of the macro (to guarantee
  461.      that the fancy `loop' macros can be made standard later).
  462.  
  463. `MACRO do-all-symbols'
  464. `MACRO do-symbols'
  465.      These operate on obarrays, the default is the current one.
  466.  
  467. 
  468. File: cl,  Node: Multiple Values,  Next: Integer Arithmetic,  Prev: Iterations,  Up: Top
  469.  
  470. Multiple Values
  471. ===============
  472.  
  473.    The multiple values mechanism covers (simply and elegantly, in my
  474. opinion) various common needs:
  475.  
  476.   1. The case where a function returns a composite value, that has to be
  477.      assembled in the callee and disassembled in the caller.  An
  478.      example is `pair-with-newsyms'.
  479.  
  480.   2. The case where a function might cheaply compute redundant
  481.      information that is useful to the caller only eventually.  For
  482.      instance, routines that compute quotients and remainders together,
  483.      whose callers might be more often interested in just receiving the
  484.      quotient.
  485.  
  486.   3. The case of functions that usually return a useful value, but
  487.      might need to elaborate on occasion (say, returning a reason code
  488.      too).
  489.  
  490.    The general idea is that one such function always returns the extra
  491. values, but only callers that are aware of this ability receive them.
  492. Unaware callers just receive the first value.
  493.  
  494.    I think my implementation is pretty much complete.  I am imposing no
  495. limits on the number of multiple values a function may return, so I am
  496. not providing the constant `multiple-values-limit'.  You can assume
  497. multiple values are bound by the memory size only.
  498.  
  499. Features Provided
  500. -----------------
  501.  
  502. `values'
  503. `values-list'
  504.      These are the forms that produce multiple values.
  505.  
  506. `MACRO multiple-value-bind'
  507. `MACRO multiple-value-call'
  508. `MACRO multiple-value-list'
  509. `MACRO multiple-value-prog1'
  510. `MACRO multiple-value-setq'
  511.      These are the forms that receive multiple values.
  512.  
  513. `VARIABLE *mvalues-count*'
  514. `VARIABLE *mvalues-values*'
  515.      Used by the implementation.  Don't touch them!
  516.  
  517. 
  518. File: cl,  Node: Integer Arithmetic,  Next: Generalized Variables,  Prev: Multiple Values,  Up: Top
  519.  
  520. Integer Arithmetic
  521. ==================
  522.  
  523.    I have provided most of the functions that are supposed to act on
  524. integers.  Of those that take arbitrary numbers, I have implemented
  525. those that have a reasonable implementation if restricted to integers
  526. only, although some more could be added (like a restricted form of
  527. `expt').
  528.  
  529.    Being a little worried about the bad fame that affects some
  530. implementations of the '%' C operator, I have taken perhaps unnecessary
  531. precautions whenever integer division is concerned (see the function
  532. `safe-idiv').  This should be of interest only when dividing numbers
  533. that might be negative, but I have preferred here to be safe rather
  534. than fast.
  535.  
  536. Features Provided
  537. -----------------
  538.  
  539. `abs'
  540. `signum'
  541.      The usual.
  542.  
  543. `gcd'
  544. `lcm'
  545.      The usual.
  546.  
  547. `isqrt'
  548.      A rather annoying function.  Only use I can think of: to cut short
  549.      a prime number sieve.
  550.  
  551. `evenp'
  552. `oddp'
  553. `plusp'
  554. `minusp'
  555.      A few predicates that use to come handy.
  556.  
  557. `cl-ceiling'
  558. `cl-floor'
  559. `cl-round'
  560. `cl-truncate'
  561. `mod'
  562. `rem'
  563.      The intention is to give everybody his preferred way to divide
  564.      integers.  I have tried not to depend on the unreliable semantics
  565.      of C's integer division, I hope I got it right.  Read the code
  566.      when in doubt.
  567.  
  568. 
  569. File: cl,  Node: Generalized Variables,  Next: Structures,  Prev: Integer Arithmetic,  Up: Top
  570.  
  571. Generalized Variables
  572. =====================
  573.  
  574.    This implementation has many limitations.  Take a look to see if you
  575. want to overcome them, the fixes might prove unnecessarily expensive for
  576. Emacs purposes.  The ones I am clearly aware of:
  577.  
  578.   1. Common Lisp suggests an underlying mechanism (the setf-methods) to
  579.      implement generalized variables.  I have used ad-hoc ideas that
  580.      gave me a rather trivial implementation that suffers from some
  581.      inflexibility.  As a result, `defsetf' only admits the simplest
  582.      form and there is no `define-modify-macro' nor there are functions
  583.      to handle the (nonexistent) setf-methods.
  584.  
  585.   2. I haven't implemented (I was uninterested) `getf' and friends.
  586.      This shouldn't be hard.
  587.  
  588.    In addition to providing this mechanism, I have written `defsetf's
  589. for almost every accessor I thought of.  There is room for improvement
  590. here, as Emacs Lisp provides many types of its own (buffers, windows,
  591. keymaps, syntax tables, ...) for which pairs of accessors and mutators
  592. could be defined.
  593.  
  594.    If you want to check whether a function has a setf-inversor, look at
  595. the property `:setf-update-fn' of its name.  This is a characteristic
  596. of my implementation, not mandated by Common Lisp, so you shouldn't use
  597. it in code, but only to determine interactively what can be setf'd.
  598.  
  599. Features Provided
  600. -----------------
  601.  
  602. `MACRO setf'
  603. `MACRO psetf'
  604.      Almost complete implementation.  `Setf' should handle `apply'
  605.      inside itself and not in a `defsetf', but the difference is so
  606.      minute I feel lazy about fixing this. `Psetf' is the version where
  607.      the assignments occur in parallel.
  608.  
  609. `MACRO defsetf'
  610.      Very sketchy implementation.  I will appreciate if somebody puts
  611.      some time in implementing the whole works of setf-methods and such.
  612.  
  613. `MACRO incf'
  614. `MACRO decf'
  615.      The usual and standard.
  616.  
  617. `MACRO pop'
  618. `MACRO push'
  619. `MACRO pushnew'
  620.      Should be the usual, but I haven't had the time to test them
  621.      properly.
  622.  
  623. `MACRO rotatef'
  624. `MACRO shiftf'
  625.      Very fancy.  Good for implementing history rings and such.  To
  626.      swap two values, the following forms are equivalent:
  627.           (rotatef a b)
  628.           (psetf a b b a)
  629.           (psetq a b b a)  ;not good for anything but variables
  630.  
  631. 
  632. File: cl,  Node: Structures,  Next: Miscellanea,  Prev: Generalized Variables,  Up: Top
  633.  
  634. Structures
  635. ==========
  636.  
  637.    I haven't had the time to construct a complete implementation of
  638. structures, but the part provided should stand on its own for many
  639. purposes.  I am not supporting `BOA constructors', nor typed slots (the
  640. `:type', `:named' and `:initial-offset' options), nor explicit
  641. representational types.  The rest should be pretty much complete.  See
  642. the example file `fractions.el' for an idea of how complete the
  643. implementation is, and for exercises.
  644.  
  645.    When writing these functions, I noticed I was incurring in lots of
  646. auxiliaries.  I used dollar signs in their names, in the hope that this
  647. could prevent clashes with user functions.  In retrospect, I should have
  648. done it in the other sections, too.
  649.  
  650. Features Provided
  651. -----------------
  652.  
  653. `MACRO defstruct'
  654.      Create records (a la C structs) and use them as types in your
  655.      programs.  Almost completely standard.
  656.  
  657. `make$structure$instance'
  658.      This non-standard function implements most of the `guts' of the
  659.      `make-' constructors.  It can be used as an example of the pseudo
  660.      keyword-arguments.
  661.  
  662. 
  663. File: cl,  Node: Miscellanea,  Next: To Do,  Prev: Structures,  Up: Top
  664.  
  665. Miscellanea
  666. ===========
  667.  
  668. Features Provided
  669. -----------------
  670.  
  671. `MACRO psetq'
  672.      A parallel-assignments version of `setq', makes the expansions of
  673.      `do' and `do*' be very similar, as they should.  Otherwise used to
  674.      swap two values, now superseded by `rotatef'.
  675.  
  676. `duplicate-symbols-p'
  677. `pair-with-newsyms'
  678. `reassemble-argslists'
  679. `unzip-list'
  680. `zip-lists'
  681.      These are utilities I find useful when parsing a call or
  682.      generating code inside a macro.  Non standard.
  683.  
  684. 
  685. File: cl,  Node: To Do,  Prev: Miscellanea,  Up: Top
  686.  
  687. To Do
  688. =====
  689.  
  690.    No doubt many people will like to extend the functionality of these
  691. routines.  When considering doing so, please try and do it in such a way
  692. that your implementation of a subset of the functionality of Common Lisp
  693. is not inimical with a more extensive or more correct one.  For
  694. definiteness, ask yourself the questions:
  695.  
  696.    * Will my code run under a correct implementation of Common Lisp?
  697.  
  698.    * Will a correct implementation of Common Lisp run if my code is
  699.      loaded?
  700.  
  701. The first question tests the pertinence of your extensions.  The second
  702. tries to discover "extensions" that prevent correct implementations of
  703. other features.  Please tell me if you notice a case in which my code
  704. fails to pass any of those tests.
  705.  
  706.    The next subsections propose some more extensions.  I hope that they
  707. are attempted by people learning Lisp, as a way to enhance their
  708. understanding.  Of course, experts are also admitted.
  709.  
  710. Keyword Arguments
  711. -----------------
  712.  
  713.    Some effort has been done to handle keywords almost right.  For
  714. instance, a structure constructor (*note Structures::.) can be invoked
  715. with keyword arguments.
  716.  
  717.    Look for the functions whose names have a `klist' in them.  They
  718. were written to facilitate parsing calls with keyword arguments, but I
  719. haven't done a complete implementation yet.  (Note that `member',
  720. `assoc' and perhaps some other function, have to be implemented
  721. independently of the general framework.  More details by Email if you
  722. want to try your hand at this.)
  723.  
  724. Mapping Functions
  725. -----------------
  726.  
  727.    There is enough support to write `maplist', `mapl', etc.  Emacs Lisp
  728. already provides some of the mapping functions, the trick now is to
  729. code the rest in a very efficient manner, so there will be an incentive
  730. to use `maplist' over an explicit iteration.  I have a draft
  731. implementation, but I don't have the time to test it now.
  732.  
  733. Complete the current implementation
  734. -----------------------------------
  735.  
  736.    Some of the features described above are only a partial
  737. implementation of the Common Lisp features.  Things that cry for a more
  738. complete form:
  739.  
  740. `defsetf'
  741.      Only the simplest format is supported.  The most general one is
  742.      needed too.  Also, try to get `define-setf-method' and
  743.      `get-setf-method' to work.
  744.  
  745. `define-modify-macro'
  746.      Same as above.  The modify-macros provided are all ad hoc.
  747.  
  748. `defstruct'
  749.      I think my version recognizes all the options and then proceeds to
  750.      ignore most of them.  Making sure that at least good error
  751.      messages are produced would be nice.  Also, what about BOA
  752.      constructors?
  753.  
  754.    There are other places where your programming ingenuity would help us
  755. all.  For instance, `subst', `sublis' and the like could be easily
  756. provided in the LISTS section.  (I haven't done it because I wanted to
  757. have the keyword arguments stuff first.)
  758.  
  759. Hash Tables
  760. -----------
  761.  
  762.    A very simple implementation of hash tables would admit only strings
  763. as keys.  For each string and a given number of buckets (a prime is
  764. desirable here), add the numeric values of all (or of a reasonable
  765. subset) of the characters and assign the bucket whose index is the
  766. remainder of the sum modulo the (prime) number of buckets.
  767.  
  768.    A more convenient implementation can then be based on using
  769. `prin1-to-string' on an arbitrary Lisp object and using the output
  770. string as a key. This should make it easy to write `sxhash'.  Remember
  771. that one needs to ensure that `(equal x y)' should imply that
  772. `(= (sxhash x) (sxhash y))'; and also that the keys are state-less (so
  773. you can write them to a file and read them back later).
  774.  
  775.    Don't forget to provide a `defsetf' for `gethash'.
  776.  
  777. Packages
  778. --------
  779.  
  780.    Packages should be easy to implement on top of a good hash table
  781. implementation, either by using it directly or by reusing some shared
  782. code.  Don't worry too much about efficiency: package qualification has
  783. no run-time cost, only read- and print-time costs.
  784.  
  785.    The difficult thing is to integrate it correctly.  You have to
  786. replace the built-in functions `read' and `write'.  This is not as bad
  787. as writing a programmable reader, but still a pain.  For starters, your
  788. routines could remember the default definitions of the above mentioned
  789. functions:
  790.  
  791.      (setf def-reader  (symbol-function 'read))
  792.      (setf def-printer (symbol-function 'print))
  793.      ...
  794.  
  795.    And then your specialized functions could just use `apply' to
  796. exercise the default ones, intercepting their activity in time to do the
  797. package qualification.  You might have to do this to `prin1',
  798. `prin1-to-string' and friends.
  799.  
  800. Streams and Files
  801. -----------------
  802.  
  803.    This is the first "To Do" that might require doing some C
  804. programming.  The purpose is to construct an efficient byte stream
  805. abstraction that will allow Streams and Files to be handled.  Think of
  806. stdio, not Unix I/O, because Emacs already runs under other operating
  807. systems.  Also, think of doing it in a way that can be generalized
  808. easily (for instance, streams kept in memory without a file behind,
  809. streams as an interface to a windowing system, etc.)  Of course, the
  810. intended syntax is that of Common Lisp.
  811.  
  812. Reader and Printer
  813. ------------------
  814.  
  815.    The Emacs Lisp reader (the C function `Fread') is not reentrant nor
  816. programmable.  It could be fixed as Lisp Code, but that is probably
  817. uglily expensive (as bad as redoing `eval' and `apply' to support
  818. lexical scoping).  Doing this  extension is probably a bad idea: a
  819. Common Lisp reader is incompatible with Emacs Lisp code (because of the
  820. `?\' constructions) and the most important rule to keep in mind is that
  821. this code is running under Emacs, so the host shouldn't be burdened too
  822. much with these emulations.  Same goes for a more complete printer (a
  823. Common Lisp `format' would be incompatible with the Emacs Lisp one).
  824.  
  825. Backquote
  826. ---------
  827.  
  828.    Even if the reader is not made programmable nor reentrant, a
  829. backquoting mechanism could come handy.  You need to study the way the
  830. current reader does `quote' and hack from there.  This might be a more
  831. worthwhile extension than the complete rewrite of the reader.
  832.  
  833. Wild Ideas
  834. ----------
  835.  
  836.    Perhaps there is a way to implement `block', `tagbody', `return' and
  837. friends in spite of the dynamic scoping of Emacs Lisp.  By this, I mean
  838. an adequate definition that preserves remotely the original intent and
  839. still provides a sensible set of constructs.  Other dynamically scoped
  840. Lisps have these features, so implementing them is not necessarily
  841. impossible.
  842.  
  843.    In the same spirit of these extensions would be to provide a port of
  844. something like Flavors (was there a PD version from Maryland, for Franz
  845. perhaps?) and then rephrase the language of major and minor modes in an
  846. Object Oriented paradigm.
  847.  
  848.    Also, the rather gross `loop' macros that are out there in many Lisp
  849. systems could be helpful to some people (but then think of a
  850. `lisp-indent-hook' that handles them properly).
  851.  
  852.  
  853. 
  854. Tag Table:
  855. Node: Top125
  856. Node: Generalities1096
  857. Node: Symbols8275
  858. Node: Lists10739
  859. Node: Sequences12894
  860. Node: Conditionals14689
  861. Node: Iterations15681
  862. Node: Multiple Values17136
  863. Node: Integer Arithmetic18851
  864. Node: Generalized Variables20204
  865. Node: Structures22545
  866. Node: Miscellanea23713
  867. Node: To Do24264
  868. 
  869. End Tag Table
  870.