Ai Dreams Forum

Member's Experiments & Projects => General Project Discussion => Topic started by: Zero on August 27, 2018, 03:57:29 pm

Title: Working on a child of s-exp
Post by: Zero on August 27, 2018, 03:57:29 pm

I know I know, s-exp are god, but I find some constructions hard to read, like those where the car are lists, like this:

Code
(((alpha a b c) are letters) is a fact)

So, if you just put the car outside of the parentheses, you get something more readable, like:

Code
alpha(a b c)(are letters)(is a fact)

The syntax would be

Code
document = element*
element = word | structure
structure = element "(" element* ")"

but this is a case of left recursion. So I managed to find a small workaround. Here is a PEGjs syntax for it:

Code
doc
= element*


element
= _ head:word body:block* _ {

var result = head;
   
    for (var b of body)
    result = { head: result, body: b };
       
    return result;
}


word
= c:[a-zA-Z0-9]+ { return c.join(''); }


block
= "(" e:element* ")" { return e; }


_
= [ \t\r\n]*

When given this:

Code
one two(foo) three(foo)(bar)

The parser yields this:

Code
[
   "one",
   {
      "head": "two",
      "body": [
         "foo"
      ]
   },
   {
      "head": {
         "head": "three",
         "body": [
            "foo"
         ]
      },
      "body": [
         "bar"
      ]
   }
]

Which is the result we want.

I think a decent minimalist programming language wouldn't need blocks at all, except to express data structures.

Here is a little html:

Code
<div id="here" class="stuff">foo bar</div>

It turns into this:

Code
div( id(here) class(stuff) )(foo bar)

Not bad IMO./
Title: Re: Working on a child of s-exp
Post by: LOCKSUIT on August 27, 2018, 04:46:17 pm
(((alpha a b c) are letters) is a fact)

What is that? Are you Building there?? And what do you use that Build for?
Title: Re: Working on a child of s-exp
Post by: ivan.moony on August 27, 2018, 05:07:24 pm
If we have `one two three`, how do we know if it is `one (two three)`, or `(one two) three`? And how do we tell apart trees from lists?

Nevertheless, I salute an attempt to introduce a key value over flat lists. I had some tries in that direction, but I gave up after having troubles with second order trees. I'll need a replacement for HTML in some point, so I'm curious about what your experiment will turn into.
Title: Re: Working on a child of s-exp
Post by: Zero on August 27, 2018, 05:44:32 pm
If we have `one two three`, how do we know is it `one (two three)`, or `(one two) three`?


Nevertheless, I salute an attempt to introduce a key value over flat lists.

a b c = a b c
(a b c) = a(b c)
(a b) c = a(b) c
((a b) c) = a(b)(c)

Do you still see an ambiguity?

(((alpha a b c) are letters) is a fact)

What is that? Are you Building there?? And what do you use that Build for?

The content is just blah blah, what matters here is the structure of the container.
Title: Re: Working on a child of s-exp
Post by: ivan.moony on August 27, 2018, 06:05:39 pm
If I understood correctly, we just pull the first element out of braces to the left? Sounds like a simple consistent rule, but somehow I can't get used to it. Maybe I need some more time and examples to process it.
Title: Re: Working on a child of s-exp
Post by: LOCKSUIT on August 27, 2018, 06:15:00 pm
(   ((I) (am))   (letters)   )

Here we combine I and am......then I am and letters
Title: Re: Working on a child of s-exp
Post by: Zero on August 28, 2018, 01:41:14 pm
You understood correctly. Here is the translation:

Code

( ((I) (am)) (letters) )

I()( am() )( letters() )