Processing Text in PicoLisp
Hi List, related to the nice idea of publishing the Rosettacode examples (which would actually be nicer _with_ the task descriptions included) I have a few (probably rather newbie) technical questions about manipulating the file-system and processing text in PicoLisp: 1. How to make, concat, and kill files (and directories) on Linux with PicoLisp? Using the system functions? 2. How to realize the following workflow (from Emacs, using Emacs Lisp) in PicoLisp: You open a text file in an Emacs buffer, goto beginning-of-buffer, do a regexp-search for pattern1. Get the point position of the start of pattern1, then delete all the text between beginning-of-buffer and start-of-pattern1. Do another regexp-search for pattern2, get point position of end-of-pattern2. Then treat end-of-pattern2 like beginning-of-buffer and search for start-of-pattern3 etc. The idea is to identify certain blocks in the text and delete everything around them. Thats a very typical task for Emacs Lisp in Emacs, but I'm not quite sure how to do this in PicoLisp. Probably would need a book with all the Rosettacode examples on my desk to easily look it up ;) 3. Is it possible to use 'prog' or 'let' with 'apply', i.e. apply a whole sequence of functions instead of only one to the 'lst argument? Thanks for any tips. -- cheers, Thorsten -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Processing Text in PicoLisp
Hi Thorsten. Below I've pasted links to descriptions of functions that might or might not be what you want based on a quick glance on your questions: 1.) http://software-lab.de/doc/refC.html#call 2.) http://software-lab.de/doc/refM.html#match 3.) I don't really get this one, isn't it possible for you to simple loop through the functions in questions with for instance for or mapc and then apply them one by one? Hope that helps. /Henrik Sarvell On Mon, Jul 23, 2012 at 10:35 AM, Thorsten Jolitz tjol...@googlemail.comwrote: Hi List, related to the nice idea of publishing the Rosettacode examples (which would actually be nicer _with_ the task descriptions included) I have a few (probably rather newbie) technical questions about manipulating the file-system and processing text in PicoLisp: 1. How to make, concat, and kill files (and directories) on Linux with PicoLisp? Using the system functions? 2. How to realize the following workflow (from Emacs, using Emacs Lisp) in PicoLisp: You open a text file in an Emacs buffer, goto beginning-of-buffer, do a regexp-search for pattern1. Get the point position of the start of pattern1, then delete all the text between beginning-of-buffer and start-of-pattern1. Do another regexp-search for pattern2, get point position of end-of-pattern2. Then treat end-of-pattern2 like beginning-of-buffer and search for start-of-pattern3 etc. The idea is to identify certain blocks in the text and delete everything around them. Thats a very typical task for Emacs Lisp in Emacs, but I'm not quite sure how to do this in PicoLisp. Probably would need a book with all the Rosettacode examples on my desk to easily look it up ;) 3. Is it possible to use 'prog' or 'let' with 'apply', i.e. apply a whole sequence of functions instead of only one to the 'lst argument? Thanks for any tips. -- cheers, Thorsten -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Processing Text in PicoLisp
Alexander Burger a...@software-lab.de writes: Hi Alex, thanks a lot, thats what I needed to know, now I have to give it a try. 3. Is it possible to use 'prog' or 'let' with 'apply', i.e. apply a whole sequence of functions instead of only one to the 'lst argument? I'm not sure what you mean here. Perhaps it helps to know that the mapping functions take an arbitrary number of lists? Can you give an example? I will try to get as far as I can and then maybe ask again with a better specified question. -- cheers, Thorsten -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Processing Text in PicoLisp
Henrik Sarvell hsarv...@gmail.com writes: Hi Henrik, Below I've pasted links to descriptions of functions that might or might not be what you want based on a quick glance on your questions: 1.) http://software-lab.de/doc/refC.html#call 2.) http://software-lab.de/doc/refM.html#match Thanks, I will look those up (have to get used to do these things without regexp, but it does make sense somehow, since regexp sometimes appear like textbook examples for the meaning og 'cryptic'. 3.) I don't really get this one, isn't it possible for you to simple loop through the functions in questions with for instance for or mapc and then apply them one by one? That question was obviously not well formulated, I think I give it a try now with the info I got and maybe ask again later on based on what I got. -- cheers, Thorsten -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Processing Text in PicoLisp
Alexander Burger a...@software-lab.de writes: For making files where you will usually use 'out', and write directly to the file. To concat two files, you could do: (out c (in a (echo)) (in b (echo))) Erasing a file is not implemented as a PicoLisp function. You can simply call 'rm' (call 'rm c) Is there a way to make 'out' write directories too? ,- | (out /new/dir/newfile (in a (echo)) (in b (echo))) `- (This doesn't work for me) Or do I have to use something like ,-- | (call 'mkdir /new/dir/) `-- then ,--- | (call 'cd /new/dir/) `--- then , | (out newfile (in a (echo)) (in b (echo))) | ` ? -- cheers, Thorsten -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Processing Text in PicoLisp
AFAIK out doesn't do auto dir creation or any dir creation for that matter. Looks good but the cd thing should not be necessary, just use the absolute path in the last call. Note that you can use info to check stuff, could possibly be used in a function that checks a certain path from top to bottom and creates any missing dirs on the way. Ie if new exists it will create dir. On Mon, Jul 23, 2012 at 10:15 PM, Thorsten Jolitz tjol...@googlemail.comwrote: Alexander Burger a...@software-lab.de writes: For making files where you will usually use 'out', and write directly to the file. To concat two files, you could do: (out c (in a (echo)) (in b (echo))) Erasing a file is not implemented as a PicoLisp function. You can simply call 'rm' (call 'rm c) Is there a way to make 'out' write directories too? ,- | (out /new/dir/newfile (in a (echo)) (in b (echo))) `- (This doesn't work for me) Or do I have to use something like ,-- | (call 'mkdir /new/dir/) `-- then ,--- | (call 'cd /new/dir/) `--- then , | (out newfile (in a (echo)) (in b (echo))) | ` ? -- cheers, Thorsten -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Processing Text in PicoLisp
Henrik Sarvell hsarv...@gmail.com writes: AFAIK out doesn't do auto dir creation or any dir creation for that matter. ok Note that you can use info to check stuff, could possibly be used in a function that checks a certain path from top to bottom and creates any missing dirs on the way. Ie if new exists it will create dir. didn't know about info, thats definitely usefull, thanks -- cheers, Thorsten -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Processing Text in PicoLisp
Hi Thorsten, Is there a way to make 'out' write directories too? No, 'out' just creates or opens a file for writing. Or do I have to use something like ,-- | (call 'mkdir /new/dir/) `-- Yes. But this works only if /new/ already exists. If /new/ is also missing, you can create the complete path with (call 'mkdir -p /new/dir/) (BTW, do you really want to write to the root directory /?) ,--- | (call 'cd /new/dir/) `--- then , | (out newfile (in a (echo)) (in b (echo))) | ` No. 'cd' is a shell builtin, and cannot be used wit 'call'. There are two lisp functions for that, 'cd' and 'chdir' (cd /new/dir/) or (chdir /new/dir/ .. body ..) The difference is that 'chdir' executes the body and then restores the original working directory (also if an exception (throw) occurs within the body). (chdir /new/dir/ (out newfile ..)) But in general I would be careful with 'cd' and 'chdir', as it modifies the working directory of the whole process. For example, a and b above will not be found (as the directory is new), and you must use ../../a or something like that. Better is usually to call (let Dir /new/dir/ (call 'mkdir -p Dir) (out (pack Dir newfile) (in a ...)) ) Cheers, - Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe