Hi Dexen,

> inspired by recent post on HN, i want to learn picoLisp (at last :P) by re-
> implementing some basic UNIX tools. here goes the venerable cat:

OK, so let me refine it.

As already pointed out by José, it could be simply reduced to 'echo'.

However, if you do it by hand,

> #!/usr/bin/env plmod

I wouldn't use that in a script. It loads too much overhead. Simply use
as the first line

   #!/usr/bin/picolisp /usr/lib/picolisp/lib.l

(or a path to a local installation).


> (mapcar '(
>       (file)
> 
>       (in file
>               (use X
>                       (until (== NIL
>                                       (setq X (rd 1)) )
>                               (wr X) ) ) ) )
> 
>       (argv))
> 
> (bye)
> 
> 
> guess it could be shorter...

Yes, first I would clean it up:

   (mapcar
      '((file)
         (in file
            (use X
               (until (== NIL (setq X (rd 1)))
                  (wr X) ) ) ) )
      (argv) )

   (bye)


The most glaring problem is using 'file' as a variable. This would
conflict with the built-in 'file' function. Use 'File' instead.

The phrase (until (== NIL ..) ..) is the same as (while .. ..)

'mapcar' is overkill here, as it constructs a list to return which is
not used here. Use 'mapc' instead.

The 'use' is not needed, as an implied variable could be used. Then
we have

   (mapc
      '((File)
         (in File
            (while (rd 1)
               (wr @) ) ) )
      (argv) )

Instead of 'mapc', you could also use 'for':

   (for File (argv)
      (in File
         (while (rd 1)
            (wr @) ) ) )

and instead of 'argv' use 'opt':

   (while (opt)
      (in @
         (while (rd 1)
            (wr @) ) ) )

and thus we are almost at José's solution ;-)

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to