Hi Luis,

On Wed, Jul 09, 2014 at 07:06:22PM +0100, Luis P. Mendes wrote:
> Hi again, sorry for these novice questions, but can't figure out why

No problem :)

> (de ffiles (dir_list)
>    (cond
>       ((=T (info (car dir_list))) (print "is directory"))
>       (print "is not directory")))

The syntax of 'cond' is wrong here. If the first clause (=T (info ..))
is true, then "is directory" is printed. But if not, then the second
clause is always true (the condition is the value of the symbol
'print'), and "is not directory" is _returned_ (but not printed).

Correct would be

   (de ffiles (dir_list)
         ((=T (info (car dir_list))) (print "is directory"))
         (T (print "is not directory")) ) )

Note the 'T' in the last line.

But 'cond' is rather overkill here, a simple 'if' would do:

   (de ffiles (dir_list)
      (if (=T (info (car dir_list)))
         (print "is directory")
         (print "is not directory") ) )

Now, as 'print' is called in both branches, it can be factored out:

   (de ffiles (dir_list)
         (if (=T (info (car dir_list)))
            "is directory"
            "is not directory" ) ) )

Then please note that function parameters (like local variables) should
be written with an uppercase character, to avoid redefining possible
global symbols:

   (de ffiles (Dir_list)
         (if (=T (info (car Dir_list)))
            "is directory"
            "is not directory" ) ) )

> $ pil pil_files.l -main +
> :
> (enters interactive mode)

OK, nothing was printed for the above reason.

> $ pil -main pil_files.l +
> !? (main)
> main -- Undefined

This error happens because (main) is called before it is defined in

> $ ./pil_files.l
> :
> (as there's a shebang, but this one seems correct to me as I didn't
> pass an argument and there's nothing to parse it).

Yes, that's all right, as long as "pil_files.l" is executable.

> But why does not `pil pil_files.l -main +`  execute the function
> ffiles with the list resulting from function `dir`?

So, in summary, 'ffiles' was well executed, but didn't output

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

Reply via email to