After reading some articles and books on fractals, I began seeing fractals or -fractally generated- shapes everywhere. All forms, natural or man-made could be -somehow- described by fractal means. Some time after, I discovered other models -which I find superior and still now take most of my interest back then reserved for fractals- that I realize how much an idea can become an obsession. Such an obsession would distort your perception of reality to the point where you can't differentiate between that idea explaining some aspect of reality or the opposite, a perversion of your understanding of reality to ...


As I said in a previous post, I was going to write about extensions of procedures like map for multiple values. I think we should better define these procedures as "multiple values iterations and transformations". In this post I'll show four procedures/macros of vital importance when working with values. Of course, we will make use of the definitions we saw before. I've done some ASCII graphics for visualizing what they do (please, let me know if normal vector graphics are really needed). Also, the names chosen for these high-order procedures are as descriptive and short I could ...


We could call "conditional mapping" to a map procedure that acts differently depending on a set of predicates. For instance, a combination with the cond form does that, so generally, in its simplest configuration, would be something like this:

(map
 (lambda (x)
   (cond
    ((predA? x)
     (car x))
    ((predB? x)
     (cdr x))
    (else
     x)))
 lis)

Also, if we need to pre-process the element from the mapped list for each one of the cond clauses -for instance, applying a selector is very comon.

(map
 (lambda (x)
   (let ((e (selector x)))
     (cond
      ((predA? e)
       (car e))
      ((predB? e)
       (cdr e))
      (else
       e))))
 lis ...

SXML trees

For general n-ary trees in Scheme, SXML seems like an appealing model, even though it was originally conceived for manipulation of XML within Scheme environments. It has already a portable library supporting several kind of operations. In essence, a SXML tree looks like this when printed:

(root (@ (attribute-1 "value-1")
        (attribute-2 "value-2"))
  (child "content")
  (empty-child))

There are 4 kinds of elements in a node: tag, value, attributes and children. You can see a deeper explanation in Oleg Kiselyov's web. Besides having an almost-standard library and the advantages of a solid library, it can be easily augmented to have ...


I'm going to make some posts about extending Scheme procedures with values handling, some ideas that I found very useful when coding. I must admit there is always the doubt that you should be using values at all, but there are cases where using values helps designing cleaner and more understandable code in the user side. There is no doubt that the implementation of procedures that operate on several values can be more obfuscated than, for instance, the same using plain lists. However, there are some neat ideas that can take advantage of values that actually help in building ...