Re: Do people dislike parentheses or the conceptual mismatch with trees?
- From: Rainer Joswig <joswig@xxxxxxx>
- Date: Fri, 19 Oct 2007 10:54:48 +0200
In article <Pine.LNX.4.56L0.0710181146450.25942@localhost>,
Ville Oikarinen <ville@xxxxxxxxxxxxx> wrote:
On Thu, 18 Oct 2007, Espen Vestre wrote:
I agree. I think the xml mindset does a lot of damage here - one tries
to force everything into tree-like structures, even things which
really is better thought of as unordered sets of complex objects. In
the real life cases where you actually /have/ tree-like structures,
the nodes often contain a lot of information, not only "labels", so
they are typically implemented as CLOS objects with their own child
pointers.
Like I said earlier, there are lots of "forced" trees (I mentioned the
filesystem as an example) that harm our thinking.
Still, it's not about trees having "only" labels. I see it this way: the
difference between a list (b c) and a tree a {b c} is that the tree is
kind of a list (child list) "with" a label, and the list is "only" a list.
The "label" can be interpreted as a type, for example. An object can be
represented as a tree, where its type (class) is the root, and all fields
and methods are children.
Lists are more primitive. They allow two interpretations
1) one is list based, just read it and you get the list data structures
(which are in Common Lisp based on cons cells)
1a) you can leave it that way
1b) you can traverse the internal list-based data-structure
and create some other data-structure
2) one is based on a custom parser that generates other
data structures
(And again, everything can be expressed as lists and sets, too, but tree
is the only of these three that explicitly supports a hierarchy between
the contained objects.)
The Lisp list is basically only a shorthand notation
for binary trees. It already knows about hierarchies.
Touretsky wrote SDRAW-LOOP, which is a top-level with an added
printer based on 2d printing of cons cells:
http://www.cs.cmu.edu/~dst/Lisp/sdraw/
RJMBP:~ joswig$ openmcl
Welcome to OpenMCL Version 1.1-pre-070512 (DarwinX8664)!
? (load "/Lisp/sdraw-generic.lisp")
#P"/Lisp/sdraw-generic.lisp"
? (sdraw-loop)
Type any Lisp expression, or :ABORT to exit.
S> '(* (+ 2 (sin b)) (cos a))
[*|*]--->[*|*]------------------------------------>[*|*]---> NIL
| | |
v v v
* [*|*]--->[*|*]--->[*|*]---> NIL [*|*]--->[*|*]---> NIL
| | | | |
v v v v v
+ 2 [*|*]--->[*|*]---> NIL COS A
| |
v v
SIN B
Result: (* (+ 2 (SIN B)) (COS A))
S> '((klaus :male) (herbert :male) (martha :female))
[*|*]------------------>[*|*]------------------->[*|*]---> NIL
| | |
v v v
[*|*]--->[*|*]---> NIL [*|*]---->[*|*]---> NIL [*|*]--->[*|*]---> NIL
| | | | | |
v v v v v v
KLAUS :MALE HERBERT :MALE MARTHA :FEMALE
Result: ((KLAUS :MALE) (HERBERT :MALE) (MARTHA :FEMALE))
S>
It also has an inspector:
? (scrawl (copy-tree '(* (+ 2 (sin b)) (cos a))))
Crawl through list: 'H' for help, 'Q' to quit.
[*|*]--->[*|*]------------------------------------>[*|*]---> NIL
| | |
v v v
* [*|*]--->[*|*]--->[*|*]---> NIL [*|*]--->[*|*]---> NIL
| | | | |
v v v v v
+ 2 [*|*]--->[*|*]---> NIL COS A
| |
v v
SIN B
'(* (+ 2 (SIN B)) (COS A))
SCRAWL> h
Legal commands: A)car D)cdr B)back up
S)start Q)quit H)help
SCRAWL> a
*
(car '(* (+ 2 (SIN B)) (COS A)))
SCRAWL> b
[*|*]--->[*|*]------------------------------------>[*|*]---> NIL
| | |
v v v
* [*|*]--->[*|*]--->[*|*]---> NIL [*|*]--->[*|*]---> NIL
| | | | |
v v v v v
+ 2 [*|*]--->[*|*]---> NIL COS A
| |
v v
SIN B
'(* (+ 2 (SIN B)) (COS A))
SCRAWL> d
[*|*]------------------------------------>[*|*]---> NIL
| |
v v
[*|*]--->[*|*]--->[*|*]---> NIL [*|*]--->[*|*]---> NIL
| | | | |
v v v v v
+ 2 [*|*]--->[*|*]---> NIL COS A
| |
v v
SIN B
(cdr '(* (+ 2 (SIN B)) (COS A)))
SCRAWL> d
[*|*]---> NIL
|
v
[*|*]--->[*|*]---> NIL
| |
v v
COS A
(cddr '(* (+ 2 (SIN B)) (COS A)))
SCRAWL> a
[*|*]--->[*|*]---> NIL
| |
v v
COS A
(caddr '(* (+ 2 (SIN B)) (COS A)))
SCRAWL> d
[*|*]---> NIL
|
v
A
(cdaddr '(* (+ 2 (SIN B)) (COS A)))
SCRAWL>
.
- References:
- Do people dislike parentheses or the conceptual mismatch with trees?
- From: Ville Oikarinen
- Re: Do people dislike parentheses or the conceptual mismatch with trees?
- From: Tim Bradshaw
- Re: Do people dislike parentheses or the conceptual mismatch with trees?
- From: Ville Oikarinen
- Re: Do people dislike parentheses or the conceptual mismatch with trees?
- From: Raffael Cavallaro
- Re: Do people dislike parentheses or the conceptual mismatch with trees?
- From: Tim Bradshaw
- Re: Do people dislike parentheses or the conceptual mismatch with trees?
- From: John Thingstad
- Re: Do people dislike parentheses or the conceptual mismatch with trees?
- From: John Thingstad
- Re: Do people dislike parentheses or the conceptual mismatch with trees?
- From: Tim Bradshaw
- Re: Do people dislike parentheses or the conceptual mismatch with trees?
- From: Espen Vestre
- Re: Do people dislike parentheses or the conceptual mismatch with trees?
- From: Ville Oikarinen
- Do people dislike parentheses or the conceptual mismatch with trees?
- Prev by Date: Re: Then why do people dislike s-expressions (and talk about parentheses)?
- Next by Date: Re: loading a local assembly rdnzl
- Previous by thread: Re: Do people dislike parentheses or the conceptual mismatch with trees?
- Next by thread: Re: Do people dislike parentheses or the conceptual mismatch with trees?
- Index(es):
Relevant Pages
|
Loading