3

I am interested in S-expressions, but I still don't have the right idioms in mind.

Imagine a VLSI component, characterized by a name and a list of typed ports. What is preferable :

(component name (p1 float) (p2 float))

or

(component name ((p1 float) (p2 float)))

?

user229044
  • 232,980
  • 40
  • 330
  • 338
JCLL
  • 5,379
  • 5
  • 44
  • 64

3 Answers3

9

The first says,

I am absolutely sure, for all time, that the component item consists of a name and 0-n ports, and nothing else.

The second states:

The component item consists of a name and a list of ports, and I might decide to add some other things later.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • 2
    The first also adds: "If, God forbid, I'm wrong you'll get probably a funky keyword-based ad-hoc syntax for what I'll need to add". – 6502 Oct 31 '11 at 22:06
  • 1
    @6502 what, an ah-hoc syntax in S-Expressions? I'm Shocked! – bmargulies Nov 01 '11 at 00:00
2

I'd personally prefer the first because it's more readable/editable, but either is possible. It depends on how complicated your sexprs are going to be and how you're going to process them.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
2

It depends why you want S-expressions.

You can view them as a way to express textually some structured data. (In that broad sense, JSON, YAML and even XML could be similar).

Or you can view them as expressions for some interpreter which interprets them. Then you have to define that interpreter.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547