Arc Forumnew | comments | leaders | submitlogin
Block Inclusion Syntax
4 points by nlavine 5556 days ago | 2 comments
This is a new idea I just thought of, and I would like comments from other members of the community.

The goal is to address code like this:

  (with (foo 5 bar 6)
    (synchronized-zone (something)
      (extra-coolness
        (lambda (whatever) ... ))))
It seems like nested forms can sometimes become a lot to keep track of, and cause the code to be indented a lot. Furthermore, a lot of the time, a function will have the structure of a bunch of outer binding forms, or forms that otherwise modify how code is executed, and then a few statements on the inside, like the above example.

To try to make this more manageable, I thought of making ,# a special syntax character. When ,# appears in a form, then the reader would look at all of the statements following that form in whatever encloses it and splice them all in as a list at the point of the ,#. So the above example would become

  (with (foo 5 bar 6) ,#)
  (synchronized-zone (something) ,#)
  (extra-coolness ,#)
  (lambda (whatever) ...)
This would let you easily use forms of the pattern

  (modify (in this way) code ...)
By writing it as

  (modify (in this way) ,#)
  code ...
If you don't like the fact that it grabs the entire rest of the block, you can work around it with just one level of nesting:

  (do
    (with (foo 12 bar 'u) ,#)
    (synchronize (backend) ,#)
    (get-data))
  (do
    (with (foo 12 bar 'z) ,#)
    (synchronize (frontend) ,#)
    (write-data))
If you did this at the beginning of a file at the top level, you could effectively change the programming language you were using for the rest of the file, which I think has interesting uses for DSLs.

I chose comma by analogy with the quasiquote syntax, and put a # after it because I don't think it's being used for anything else right now.



5 points by shader 5556 days ago | link

If it has to be a single character, here are some other choices:

(with (a 1 b 2) &) (with (a 1 b 2) *) (with (a 1 b 2) @)

There might be more possibilities, but I think the first two make the most sense.

Here's an interesting way to come up with syntax features for a language: Write out some code with a random symbol, syntax, or function name. Either read it yourself, or have a disinterested third party read it, and see what they think it means. If it doesn't make any sense, it might not be the best choice. On the other hand, if it means what you think it should mean, it's probably a step in the right direction.

However, I worry sometimes about some of arc's attempts to shorten code. Coming up with a powerful set of axioms and basic functions that allow you to express your self with a limited number of syntactic objects is probably a good thing, but abbreviating everything so that it looks like perl line noise without actually reducing the amount of code you have to write, just letters, is actually going in the wrong direction. This is because you actually have more to think about. Not only do you have to think about the same number of objects, but they are in a relatively unintelligible form. I'm not saying that this particular symbol, or any other, is necessarily bad; I'm just saying that we should be careful about abbreviating all of our English to vowel-less words and funny symbols. Lisp has the distinction of being able to abstract away most repetitive coding via macros; let's not waste it by making the code involved unintelligible to begin with.

-----

1 point by CatDancer 5556 days ago | link

That is nifty.

I wouldn't mind finding a different syntax than ,# though, if we can think of something better.

-----