Mapping circular lists from Emacs Lisp to PicoLisp

2013-06-28 Thread Thorsten Jolitz

Hi List, 

I try to figure out if it would be possible to map circular lists from
Emacs Lisp to PicoLisp. Here is a quote from the Emacs Lisp manual :

#+begin_quote
If the cdr of a list's last cons cell is some value other than nil, we call
the structure a dotted list, since its printed representation would use dotted
pair notation (see Dotted Pair Notation). There is one other possibility: some
cons cell's cdr could point to one of the previous cons cells in the list. We
call that structure a circular list.
#+end_quote

In PicoLisp, the cdr of a circular list always seems to point to the beginning
of the list. In Emacs Lisp the term 'shared structures' is used too, and 'the
cell's cdr could point to one of the previous cons cells in the list', not
only to the beginning of the list. 

The syntax for this looks like this (again from the Emacs Lisp manual):

#+begin_quote
To represent shared or circular structures within a complex of Lisp objects,
you can use the reader constructs ‘#n=’ and ‘#n#’.

Use #n= before an object to label it for later reference; subsequently, you
can use #n# to refer the same object in another place. Here, n is some
integer. For example, here is how to make a list in which the first element
recurs as the third element:

 (#1=(a) b #1#)

#+end_quote

Thus, somewhere in a nested list, an object is labelled for later use (not
necessarily the beginning of the list), and later it is referred to one or
several times (not necessarily at the end of the list), e.g.

#+begin_src emacs-lisp
  (:parent #5=(headline ...
  ...  :parent #5#)
#+end_src

I wonder how this can be expressed in PicoLisp?

-- 
cheers,
Thorsten

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


Re: Mapping circular lists from Emacs Lisp to PicoLisp

2013-06-28 Thread Alexander Burger
Hi Thorsten,

 In PicoLisp, the cdr of a circular list always seems to point to the beginning
 of the list.

Yes, as far as the directy reader/printer syntax is concerned. But you
can easily specify a list where the last cell points to some other cell.

For example, in this list of 6 cells the last 3 cells form a circular
list:

   : (1 2 3 . (4 5 6 .))
   - (1 2 3 . (4 5 6 .))
   :  (more @)  
   1 
   2
   3
   4
   5
   6
   4
   5
   6
   4
   ...

Personally, I find syntax much simpler and cleaner than using labels.


What cannot be directly expressed, however, is a pointer into a sublist
of the current list (or even into arbitrary other lists).

Here you have to resort to labels, by setting a variable to the
(sub)list in question:

   : (1 2 (3 4 . `(setq n1 (5 6))) 7 . `n1)
   - (1 2 (3 4 5 6) 7 5 6)

   : (1 2 3 ~(setq n2 (4 5 6)))
   - (1 2 3 4 5 6)
   : (7 8 ~n2) 
   - (7 8 4 5 6)

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


Re: Mapping circular lists from Emacs Lisp to PicoLisp

2013-06-28 Thread Thorsten Jolitz
Alexander Burger a...@software-lab.de writes:

Hi Alex,

 In PicoLisp, the cdr of a circular list always seems to point to the
 beginning of the list.

 Yes, as far as the directy reader/printer syntax is concerned. But you
 can easily specify a list where the last cell points to some other
 cell.

 For example, in this list of 6 cells the last 3 cells form a circular
 list:

: (1 2 3 . (4 5 6 .))
- (1 2 3 . (4 5 6 .))
:  (more @)  
1 
2
3
4
5
6
4
5
6
4
...

 Personally, I find syntax much simpler and cleaner than using labels.

I see, and indeed it looks clean and nice.

 What cannot be directly expressed, however, is a pointer into a sublist
 of the current list (or even into arbitrary other lists).

 Here you have to resort to labels, by setting a variable to the
 (sub)list in question:

: (1 2 (3 4 . `(setq n1 (5 6))) 7 . `n1)
- (1 2 (3 4 5 6) 7 5 6)

: (1 2 3 ~(setq n2 (4 5 6)))
- (1 2 3 4 5 6)
: (7 8 ~n2) 
- (7 8 4 5 6)

Does not look as clean and nice as before, but what counts - it can be
done, great. 

Thanks again, I'm glad I asked, it would have taken me forever to
(probably not) figure this out. 

-- 
cheers,
Thorsten

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