Hi Jon,

> I would like collect file extensions into an idx tree X, and for
> each file F I think this expression should do the work:
> (let L (chop F) (when (index '. L) (idx 'X (pack (stem L '.)) T)))
> Now I want to make this into a function with the name 'collectExt'
> and arguments for X and F, which should be pretty trivial, but it
> seems I'm having problems with the X argument. Can anybody tell me
> how to do it?

You just have to remove the quote before the 'X' then:

   (de collectExt (X F)
      (let L (chop F)
         (when (index '. L)
            (idx X (pack (stem L '.)) T) ) ) )

BUT!!: This is a typical case where you might get a symbol conflict. If
you call it as:

   (collectExt 'I "abc.zip")

it works, but not if call as

   (collectExt 'X "abc.zip")

This is why the FAQ recommends transient symbols for "a parameter or
local, when that symbol might possibly be (directly or indirectly) bound
to itself".

Thus, if you do

   (de collectExt ("Var" F)
      (let L (chop F)
         (when (index '. L)
            (idx "Var" (pack (stem L '.)) T) ) ) )

   : (collectExt 'I "abc.zip")
   -> NIL
   : I
   -> ("zip")

   : (collectExt 'X "abc.zip")
   -> NIL
   : X
   -> ("zip")

♪♫ Alex
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to