Hi Konrad,

> Instead I get
> $385555801 NIL
>    "orange" 1
>    "orange" 1
> 
> I don't understand why two invocations of (read T) are returning two
                                             ^
(a minor remark: You certainly meant 'line' here, instead of 'read')


> symbols which look the same but are not equal. Its somthing

Yes, exactly. This effect results from the fact that the two symbols
subsequently read are not the same. And 'put', 'get' etc. search the
property list for pointer equality.

>  to do with dynamic scoping how do I get arround it.

(line T) reads a line into a transient symbol. Transient symbols are
only the same if they are read within the same read-eval-loop (i.e. the
'load' function). That is, if they are read within the scope of a single
source file.

Transient symbols created by some other means (e.g. 'line', or 'pack'
and son on) are always unique.


> The goal is to count the number of files a particular word appears in.

You could use association-lists instead of a symbol and 'put'.
Especially also because there is a function 'accu' which does the
counting:

   (de read-words (File-name)
      (in File-name
         (uniq
            (make
               (until (eof)
                  (link (line T))
              (uniq res) ) ) ) ) )

   (de main ()
      (let Acum NIL
         (for Fname (argv)
            (for Word (read-words Fname)
               (accu 'Acum Word 1) ) )       # 'accu' from "lib/misc.l"
         Acum ) )

(another remark: I strongly recommend to use upper case names for
locally bound symbols, to avoid clashes with global symbols like
function names)


If you have a lot of words (say, more than 100), neither a property list
nor an association list is a good idea. I'd recommend a tree structure:

   (de main ()
      (let Acum NIL
         (for Fname (argv)
            (for Word (read-words Fname)
               (if (idx 'Acum Word T)        # Find or insert into tree
                  (inc (car @))              # if found, increment
                  (set Word 1) ) ) )         # otherwise init to 1
         (mapcar
            '((Sym) (cons Sym (val Sym)))
            (idx 'Acum) ) ) )

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]

Reply via email to