[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can s-exprs represent a graph without eval?



Guy Steele - Sun Microsystems Labs wrote:

> Sometimes an circular structure can be used to "advantage".
> Consider this bit of code:
> 
>   (mapcar #'+ x '#1=(1 -1)) ;; [assume '#1=(1 -1 #1#)]

This is useful!  I've employed a similar pattern quite often in Web
page generation.  Say you're given a list of names

  Garbo
  Monroe
  Dietrich
  DiMaggio
  Brando
  Dean
  Kelly
  Jean

and you want their background colors to alternate: white, grey, white,
grey, ....  Set COLORS to 

  '#0=("white" "grey" #0#)

Now you can peel off the CAR and CDR of COLORS for as many names as
there are on your list.  Better still, if your want to rotate colors
in threes, the change is trivial: set COLORS to

  '#0=("white" "grey" "yellow" #0#) 

instead.  I'm sure you've run into similar uses with JScheme.

Shriram