Re: PicoLisp Book

2012-07-23 Thread Meadowlark technology
Another excellent idea.

I have often wondered whether it would be a good idea to compile all the
pl parts of Rosettacode into a single document!

Thank you very much.


On Fri, 2012-07-20 at 14:45 +0200, Alexander Burger wrote:
> On Fri, Jul 20, 2012 at 02:32:00PM +0200, Thorsten Jolitz wrote:
> > Terry Palfrey 
> > writes:
> > 
> > > Will this include the Rosetta Code examples?
> > ...
> > Thats not a bad idea at all, but it depends a bit on the technical side.
> > It would seem to be too much work if I had to transform the Rosetta Code
> > html to Tex and then pick out the PicoLisp parts. 
> 
> Well, I have all the solutions I posted so far in a single large source
> file ("rosettacode.l", 17194 lines as of today).
> 
> So I uploaded it now to software-lab.de. Perhaps it helps?
> 
>http://software-lab.de/rosettacode.l
> 
> Cheers,
> - Alex


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


Processing Text in PicoLisp

2012-07-23 Thread Thorsten Jolitz

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

2012-07-23 Thread Alexander Burger
Hi Thorsten,

> 1. How to make, concat, and kill files (and directories) on Linux with
>PicoLisp? Using the system functions?

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")


> 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.

PicoLisp doesn't have regular expressions built-in, though you can call
the C library, or do similar things with 'match'. But usually it is
easier and more efficient to use 'echo', 'from', 'till' and related
functions directly on the file:

   (call 'mv "file" "file.old")# Save original file
   (in "file.old"  # Read original
  (out "file"  # Write new
 (from "pattern1") # (assuming a fixed pattern)
 (echo "pattern2") ) )

This works only for fixed strings "pattern1" and "pattern2". For more
complicated cases, it is usually possible to search for specific
substrings and the proceed with 'char', 'line' etc. to process the data.
Another possibility is to use 'till' to read all data up to a certain
character into a list, and operate on that list with 'match' or other
functions.

So, this is in sync with the "dynamic" philosophy of PicoLisp (instead
of a "static" approach with regular expressions) by "programming" the
solution in a step-by-step refinement of the search, possibly using
'if's and 'while's, and not with a kill-all predefined regular
expression.


> 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?

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


Re: Processing Text in PicoLisp

2012-07-23 Thread Henrik Sarvell
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 wrote:

>
> 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

2012-07-23 Thread Thorsten Jolitz
Alexander Burger  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


Enhanced ref doc for the 'for' forms

2012-07-23 Thread Jon Kleiser

Hi Alex,

For quite some time I've felt that the ref. documentation for the 'for' 
forms could need some improvements. The 'for' function is a very 
important function, and for most people who are new to PicoLisp, it will 
be one of the first functions they will have to learn. At the same time, 
the 'for' function has so many forms and options that a non-Lisper may 
have a hard time figuring out how to use it. That's why I have tried to 
enhance the docs for this function.


What I've done is (a) inserted a few  line breaks so that the 
descriptions of the three forms are separated, and so that it will be a 
little clearer that the sentence starting with "If a clause has NIL or T 
.." may apply to all the three forms. Then (b) I have organized the 
examples into three groups, one group for each form, adding examples for 
the first form (that was entirely missing). Take a look at (and copy 
what you like from) my enhanced docs here:



Please verify that I have done the three example groups correctly. ;-)

/Jon
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Processing Text in PicoLisp

2012-07-23 Thread Thorsten Jolitz
Henrik Sarvell 
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: Enhanced ref doc for the 'for' forms

2012-07-23 Thread Alexander Burger
Hi Jon,

> For quite some time I've felt that the ref. documentation for the
> 'for' forms could need some improvements. The 'for' function is a

Very true!


> What I've done is (a) inserted a few  line breaks so that the
> descriptions of the three forms are separated, and so that it will
> be a little clearer that the sentence starting with "If a clause has
> NIL or T .." may apply to all the three forms. Then (b) I have
> organized the examples into three groups, one group for each form,
> adding examples for the first form (that was entirely missing). Take
> a look at (and copy what you like from) my enhanced docs here:
> 

Great! You are right, now it is much better.

Many thanks! I've incorporated your changes.

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


Upper limit for list lenght in PicoLisp?

2012-07-23 Thread Thorsten Jolitz

Hi List, 
I have a rather strange problem:

I want to (from within Emacs)

,--
| (setq X (list "string1" ... "string200"))
`--

and it seems PicoLisp just freezes - no error messages, but no output
either, and the process seems to be frozen. 
Now when I split the list into 

,
| (setq Y (list "string1" ... "string100"))
| (setq Z (list "string101" ... "string200"))
`

both evaluations work, and quite fast. I could make Y even smaller and Z
bigger - until a certain limit (Y = 25, Z = ca. 180 or so), and both
assignments work just fine. But when I add both parts together, PicoLisp
freezes again when assigning X.

Is there something like an upper limit for how many Strings can be in a
list in PicoLisp? Or might that be Emacs related?

200 or 300 are not really that big numbers ...

-- 
cheers,
Thorsten


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


Re: Upper limit for list lenght in PicoLisp?

2012-07-23 Thread Alexander Burger
Hi Thorsten,

> Is there something like an upper limit for how many Strings can be in a
> list in PicoLisp? Or might that be Emacs related?

No, there is no limit. Neither to the length of the command line (if you
use the built-in line editor).

How did you invoke PicoLisp? Does this also happen if you invoke just as

   $ pil +

i.e. PicoLisp alone, without Emacs?

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


Re: Upper limit for list lenght in PicoLisp?

2012-07-23 Thread Thorsten Jolitz
Alexander Burger  writes:

Hi Alex,

>> Is there something like an upper limit for how many Strings can be in a
>> list in PicoLisp? Or might that be Emacs related?
>
> No, there is no limit. Neither to the length of the command line (if you
> use the built-in line editor).
>
> How did you invoke PicoLisp? Does this also happen if you invoke just as
>
>$ pil +
>
> i.e. PicoLisp alone, without Emacs?

No, that works, although there are is someting strange happening too:
some of the strings in the list are replaces by NIL, and it seems as if
the '\' that signals a linebreak in an Emacs buffer is somehow
misinterpreted as an escaping backslash

 ,
 | "wiki/Binary_strings" "wiki/Bitmap"
 | "wiki/Bitmap/Bresenham%27s_line_algorithm"
 | "wiki/Bitmap/B%C3%A9zier_curves/Cubic"
 | "wiki/Bitmap/B%C3%A9zier_curves/Quadratic" "wiki/Bitmap/Flood_fill"
 | "wiki/Bitmap/Histogram" "wiki/Bitmap/Midpoint_circle_algorithm"
 | "wiki/Bitmap/PPM_conversion_through_a_pipe"
 | "wiki/Bitmap/Read_a_PPM_file"
 | "wiki/Bitmap/Read_an_image_through_a_pipe"
 | "wiki/Bitmap/Write_a_PPM_file" "wiki/Bitwise_IO"
 | "wiki/Bitwise_operations" "wiki/Boolean_values" "wiki/Box_the_compass"
 | "wiki/Break_OO_privacy" "wiki/Brownian_tree" "wiki/Bulls_and_cows"
 | "wiki/Bulls_and_cows/Player" "wiki/Caesar_cipher" "wiki/Calendar"
 | "wiki/Calendar_-_for_%22real%22_programmers"
 | "wiki/Call_a_foreign-language_function" "wiki/Call_a_function"
 | "wiki/Call_a_function_in_a_shared_library" "wiki/Call_an_object_method"
 | "wiki/Case-sensitivity_of_identifiers" "wiki/Catalan_numbers"
 | "wiki/Character_codes" "wiki/Character_matching" "wiki/Chat_server"
 | "wiki/Checkpoint_synchronization" "wiki/Chess_player"
 | "wiki/Chess_player/PicoLisp"
 `

becomes

  ,--
  | "wiki/Binary_strings" "wiki/Bitmap"
  | "wiki/Bitmap/Bresenham%27s_line_algorithm\" " NIL " " NIL " " NIL " "
  | NIL " " NIL " " NIL " " NIL " " NIL " " NIL " " NIL " " NIL " " NIL "
  | " NIL " " NIL " " NIL " " NIL " " NIL " " NIL " " NIL " " NIL " " NIL
  | " " NIL " " NIL " " NIL " " NIL " " NIL " " NIL " " NIL "
  | \"wiki/Chat_server" "wiki/Checkpoint_synchronization"
  | "wiki/Chess_player" "wiki/Chess_player/PicoLisp" 
  `--


So it looks more like an Emacs (PicoLisp mode) related problem. 

-- 
cheers,
Thorsten

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


Re: Upper limit for list lenght in PicoLisp?

2012-07-23 Thread Alexander Burger
Hi Thorsten,

> > How did you invoke PicoLisp? Does this also happen if you invoke just as
> >
> >$ pil +
> >
> > i.e. PicoLisp alone, without Emacs?
> 
> No, that works, although there are is someting strange happening too:
> some of the strings in the list are replaces by NIL, and it seems as if

You said that you call it as

   (setq X (list "string1" ... "string200"))

Note that this evaluates the transient symbols "string1" etc., so if one
of them has a value NIL (or anything else), it will be included in the
list.

What you actually want to do is

   (setq X '("string1" ... "string200"))


> the '\' that signals a linebreak in an Emacs buffer is somehow
> misinterpreted as an escaping backslash

A backslash at the very end of a line causes PicoLisp to continue
reading the next line, skipping possible white space:

: "abc\
   def"
-> "abcdef"

A linebreak by itself has no special meaning, but will be included
into strings, of course, if not escaped in the above way.

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


Re: Processing Text in PicoLisp

2012-07-23 Thread Thorsten Jolitz
Alexander Burger  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: Upper limit for list lenght in PicoLisp?

2012-07-23 Thread Thorsten Jolitz
Alexander Burger  writes:

Hi Alex,

> You said that you call it as
>
>(setq X (list "string1" ... "string200"))
>
> Note that this evaluates the transient symbols "string1" etc., so if one
> of them has a value NIL (or anything else), it will be included in the
> list.
>
> What you actually want to do is
>
>(setq X '("string1" ... "string200"))

yes, definitely... thanks

-- 
cheers,
Thorsten

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


Re: Processing Text in PicoLisp

2012-07-23 Thread Henrik Sarvell
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 wrote:

> Alexander Burger  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

2012-07-23 Thread Thorsten Jolitz
Henrik Sarvell 
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

2012-07-23 Thread Alexander Burger
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/" ..  ..)

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