Working on a child of s-exp

  • 6 Replies
  • 987 Views
*

Zero

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1000
  • Ready?
    • Thinkbots are free
Working on a child of s-exp
« 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./

*

LOCKSUIT

  • Emerged from nothing
  • Trusty Member
  • ******************
  • Hal 4000
  • *
  • 4097
  • First it wiggles, then it is rewarded.
    • Main Project Thread
Re: Working on a child of s-exp
« Reply #1 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?
Emergent

*

ivan.moony

  • Trusty Member
  • ***********
  • Eve
  • *
  • 1410
    • e-teoria
Re: Working on a child of s-exp
« Reply #2 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.
« Last Edit: August 27, 2018, 05:55:46 PM by ivan.moony »
There exist some rules interwoven within this world. As much as it is a blessing, so much it is a curse.

*

Zero

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1000
  • Ready?
    • Thinkbots are free
Re: Working on a child of s-exp
« Reply #3 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.

*

ivan.moony

  • Trusty Member
  • ***********
  • Eve
  • *
  • 1410
    • e-teoria
Re: Working on a child of s-exp
« Reply #4 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.
There exist some rules interwoven within this world. As much as it is a blessing, so much it is a curse.

*

LOCKSUIT

  • Emerged from nothing
  • Trusty Member
  • ******************
  • Hal 4000
  • *
  • 4097
  • First it wiggles, then it is rewarded.
    • Main Project Thread
Re: Working on a child of s-exp
« Reply #5 on: August 27, 2018, 06:15:00 PM »
(   ((I) (am))   (letters)   )

Here we combine I and am......then I am and letters
Emergent

*

Zero

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1000
  • Ready?
    • Thinkbots are free
Re: Working on a child of s-exp
« Reply #6 on: August 28, 2018, 01:41:14 PM »
You understood correctly. Here is the translation:

Code

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

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

« Last Edit: August 28, 2018, 02:10:41 PM by Zero »

 


Users Online

11 Guests, 0 Users

Most Online Today: 25. Most Online Ever: 340 (March 26, 2019, 09:47:57 PM)

Articles