Axel Svensson <>

>> related to my attempts to write an Emacs-like command-line for PicoLisp?
> No, it is not related. A "reader", as I use the word here, is a
> function used to parse the code before it is executed. The syntax of
> the language therefore depends on the reader, and by altering the
> reader you can alter the syntax.
>> Or is that an entirely different topic- maybe you could expand a bit on
>> the possible use-cases of your pilreader?
> Suppose you want to change or add some syntax to the picolisp
> language. What you would want to do then is to change the (read)
> function. Since (read) is a C-level function, this is impractical. The
> recommended approach is to implement your own reader. So to make a
> small change to the syntax, you need to implement the whole reader
> first in picolisp, then add your customizations.
> pilreader implements a reader function (r) which mimics the behaviour
> of (read), except (r) is implemented in picolisp rather than C. So it
> gets you right to the point of adding your customizations. To make
> changes to the syntax, use the pilreader code and change it
> accordingly.
> A hello world example follows:
> #!/usr/bin/picolisp /usr/lib/picolisp/lib.l
> #Load the reader
> (load "pilreader.l")
> #eval loop to use pilreader instead of (read) for the rest of this file.
> (while (r) (eval @))
> #Make semicolon a comment character.
> (r-syntax ";" (until (= "^J" (char))) (r))
> ;Change the syntax for comma to mean enclosing two items in a list.
> (r-syntax "," (char) (list (r) (r)))
> ,prin "Hello " ;This means (prin "Hello ")
> (prinl "World!") #The old syntax still works.
> ,bye 0
> This trivial example uses the r-syntax function provided by pilreader.
> For more complex syntax changes, you would have to change the code -
> the point is you don't have to start all over.

I see, very interesting, so one could easily emulate the syntax of other
languages while still using PicoLisp. 

Say you want to read files in some mark-up syntax (e.g. Org-mode with
its tree-like outline stucture) and construct a parse tree with all
elements in the file stored in nested lists. What would be the pro's and
con's of using r-syntax for converting Org-mode syntax-elements into
lists following your example

| ;Change the syntax for comma to mean enclosing two items in a list.
| (r-syntax "," (char) (list (r) (r)))

instead of simply using standard PicoLisp functions for reading and
processing the file in the usual way?



Reply via email to