Working on a child of s-exp

  • 6 Replies
  • 2440 Views
*

Zero

  • Eve
  • ***********
  • 1287
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
  • *******************
  • Prometheus
  • *
  • 4659
  • 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          https://openai.com/blog/

*

ivan.moony

  • Trusty Member
  • ************
  • Bishop
  • *
  • 1723
    • mind-child
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 »

*

Zero

  • Eve
  • ***********
  • 1287
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
  • ************
  • Bishop
  • *
  • 1723
    • mind-child
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.

*

LOCKSUIT

  • Emerged from nothing
  • Trusty Member
  • *******************
  • Prometheus
  • *
  • 4659
  • 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          https://openai.com/blog/

*

Zero

  • Eve
  • ***********
  • 1287
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 »

 


OpenAI Speech-to-Speech Reasoning Demo
by ivan.moony (AI News )
Today at 01:31:53 pm
Say good-bye to GPUs...
by MikeB (AI News )
March 23, 2024, 09:23:52 am
Google Bard report
by ivan.moony (AI News )
February 14, 2024, 04:42:23 pm
Elon Musk's xAI Grok Chatbot
by MikeB (AI News )
December 11, 2023, 06:26:33 am
Nvidia Hype
by 8pla.net (AI News )
December 06, 2023, 10:04:52 pm
How will the OpenAI CEO being Fired affect ChatGPT?
by 8pla.net (AI News )
December 06, 2023, 09:54:25 pm
Independent AI sovereignties
by WriterOfMinds (AI News )
November 08, 2023, 04:51:21 am
LLaMA2 Meta's chatbot released
by 8pla.net (AI News )
October 18, 2023, 11:41:21 pm

Users Online

302 Guests, 0 Users

Most Online Today: 346. Most Online Ever: 2369 (November 21, 2020, 04:08:13 pm)

Articles