Re: `rd' behavior
Also, a + at the end of the command line is special; it turns on *Dbg and is not included in (argv). > > bare dash. is there any way around it? Make a wrapper like this: #!/bin/bash /usr/bin/picolisp /usr/lib/picolisp/lib.l file.l +++ "$@" +++ Then in file.l, remove the extraneous +++: (setq Arguments (cdr (reverse (cdr (reverse (argv)) (for A Arguments (prinl A)) (bye) This makes sure there will never be a dash as first argument, or a plus sign as the last. A little cumbersome perhaps, but it is caused by how the picolisp interpreter works. -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: `rd' behavior
Hi Dexen, > * by default, many derivative cat use single, bare dash (`-') to stand for > /dev/stdin, but picolisp (the interpreter) seems to skip arguments after > first > bare dash. is there any way around it? Right, a single dash has a special meaning on the command line. It inhibits the loading/executing of further command line arguments, to have them passed as plain arguments to the application (shortly described in "http://software-lab.de/doc/ref.html#invoc";, "Invocation". This is observed when loading all arguments with (load T), or by (opt). (argv), however, behaves a little different. It returns all remaining arguments, even if they contain "-", but NOT if the "-" is the first one because it then assumes it is the remaining position of the above rule. Quite confusing ... So I would discourage from using a single "-" as a command line argument, and use "--" in such cases if necessary. Cheers, - Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: `rd' behavior
Hi Jose, Alexander, HOn Monday 05 of November 2012 16:15:39 you wrote: > (...) > and instead of 'argv' use 'opt': > >(while (opt) > (in @ > (while (rd 1) > (wr @) ) ) ) > > and thus we are almost at José's solution ;-) thanks you both for explanations, it helps a lot :-) two things should be corrected to converget o UNIX `cat': * by default, stdin should be copied to stdout if there's no arguments; that's easy with (unless (argv) (in @ (echo) ) ) * by default, many derivative cat use single, bare dash (`-') to stand for /dev/stdin, but picolisp (the interpreter) seems to skip arguments after first bare dash. is there any way around it? cheers, -- dexen deVries [[[↓][→]]] I have seen the Great Pretender and he is not what he seems. -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: `rd' behavior
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
Re: `rd' behavior
On Mon, 05 Nov 2012 15:29:42 +0100 dexen deVries wrote: > On Monday 05 of November 2012 10:54:20 you wrote: > > rd without argument (or with a sym) means binary read, it tries to > > read an atom or expression in the binary PLIO format (used by pr). > > Rd with a number argument means to read the given amount of bytes > > as a bignum. The sym argument is an optional end of file flag to > > return instead of the default (NIL). > > > thanks, i get it now :-) > > 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: > > #!/usr/bin/env plmod > > (mapcar '( > (file) > > (in file > (use X > (until (== NIL > (setq X (rd 1)) ) > (wr X) ) ) ) ) > > (argv)) > > (bye) > > > guess it could be shorter... > Maybe this? (while (opt) (in @ (echo))) Though it doesn't really handle well pipelines (if something downstream dies it doesn't seem to die properly like cat does). > > cheers, cheers, José -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: `rd' behavior
On Monday 05 of November 2012 15:29:42 dexen wrote: > (...) here goes the venerable cat: ..and a bugfix -- support the all-important "-" ;-) #!/usr/bin/env plmod (mapcar '( (file) (in (if (= file "-") NIL file ) (use X (until (== NIL (setq X (rd 1)) ) (wr X) ) ) ) ) (argv)) (bye) cheers, -- dexen deVries [[[↓][→]]] How often I found where I should be going only by setting out for somewhere else. -- R. Buckminster Fuller -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: `rd' behavior
On Monday 05 of November 2012 10:54:20 you wrote: > rd without argument (or with a sym) means binary read, it tries to read > an atom or expression in the binary PLIO format (used by pr). Rd with a > number argument means to read the given amount of bytes as a bignum. > The sym argument is an optional end of file flag to return instead of > the default (NIL). thanks, i get it now :-) 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: #!/usr/bin/env plmod (mapcar '( (file) (in file (use X (until (== NIL (setq X (rd 1)) ) (wr X) ) ) ) ) (argv)) (bye) guess it could be shorter... cheers, -- dexen deVries [[[↓][→]]] How often I found where I should be going only by setting out for somewhere else. -- R. Buckminster Fuller -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: `rd' behavior
On Mon, 05 Nov 2012 14:37:07 +0100 dexen deVries wrote: > hello list, > > why does `rd' return NIL in simplest use ('sym or NIL argument): > (in "info.txt" >(print (rd] > > while it seems to work fine with 'cnt argument: > (in "info.txt" >(print (rd 1] > > guess i'm doing something wrong @_@ > > using picoLisp-3.1.0.tgz. > rd without argument (or with a sym) means binary read, it tries to read an atom or expression in the binary PLIO format (used by pr). Rd with a number argument means to read the given amount of bytes as a bignum. The sym argument is an optional end of file flag to return instead of the default (NIL). -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe