Re: Structures



On Sat, 29 Mar 2008 13:06:23 -0700, Tayssir John Gabbour wrote:

On Mar 29, 8:31 pm, dstein64 <DStei...@xxxxxxxxx> wrote:
Is it still common to use structures in common lisp code? Is there
any reason I should avoid them? It seems that some of the newer
guides do not mention them. Thanks!


I started off using lists for my compiler but eventually I got sick of
remembering that (nth 11 data-item) was level-nbr, etc. Especially I got
sick of forgetting these pieces of information. So I switched to structs to
hold the various parse tree elements. This has worked quite well.

* Gives fields meaningful names.
* Provides some error checking at run time.

Lisp allows structures to incorporate other structures: "(:include
included-structure-name {slot-description}*)". This is good because all my
grammar structures can share a common header.

On the down side it makes the code more verbose at times. One problem with
completely dynamic typing is that the compiler does not know the types of
data and so you always have to tell it at some cost in tokens you have to
type in. Also defstruct by default names the accessors
[struct-name]-[field-name] which makes for long names.

Another downside is that generic routines that walk trees and lists no
longer work because they don't understand structures. I wrote a structure
walking function that supports a visitor type pattern to get around this.

Tim
.



Relevant Pages

  • Re: More static type fun.
    ... > perception of how common runtime type errors are. ... to invest in unit tests to catch bugs and gotchas in my program would ... and about placating the compiler. ... > to explicitly tell the compiler that you want to use lists with more ...
    (comp.lang.lisp)
  • Aurora Beta 1
    ... The Aurora compiler has just been updated to Beta 1. ... non-indexed triangle lists. ... The ClassView pane in the IDE now does something. ...
    (comp.lang.misc)
  • Re: Symbols, metacircular evaluation, external representation.
    ... You could only use strings, and you would have to use parsers all the time. ... same kind of symbolic expressions, it's very easy to write functions ... writting a metacircular interpreter (or a lisp compiler), ... lists. ...
    (comp.lang.scheme)
  • Re: foreach enhancement
    ... > strong typing is not an option, and that optimization will not be able to ... > concerned with optimization of for loops and typing - since lists will be ... *very* different and the compiler itself will certainly be able to know the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: builtin lists and Intel SSE support?
    ... > 2) has support for lists in the language syntax itself, ... > SSE compiler support, although indeed that would be nice if it existed. ... which would hopefully allow you to insert the SSE instructions you want. ...
    (comp.lang.lisp)