Arc Forumnew | comments | leaders | submitlogin
New Syntax Feature- Dangling Dot
5 points by drcode 5758 days ago | 3 comments
Hi- I was just playing around inside the compiler again to scratch a syntax itch. What should an intrasymbol dot do if it's the last character of a function? Currently, it throws an ugly error.

I would argue it should just call the function without parameters:

BEFORE

  arc> (date)
  "2008-07-18"
AFTER

  arc> date.
  "2008-07-18"
It's a very simple change that doesn't interfere with anything else. From a cognitive standpoint, it makes sense that a function ending in a period is being funcalled, since periods at the end of a single word usually denote a verbal command in human language. Since functions without parameters are very common, this syntax is also widely useful.

To add this feature, make the following change to "build-sexpr" in ac.scm (tested in the pg version of arc only)

  (define (build-sexpr toks)
    (cond ((null? toks) 
           '())
          ((eqv? (car toks) #\.)
           (if (null? (cadr toks))
               '()
               (cons (chars->value (cadr toks))
                     (build-sexpr (cddr toks)))))
          ((eqv? (car toks) #\!)
           (cons (list 'quote (chars->value (cadr toks)))
                 (build-sexpr (cddr toks))))
          (#t
           (cons (chars->value (car toks))
                 (build-sexpr (cdr toks))))))


4 points by almkglor 5757 days ago | link

Or by using ssyntaxes.arc on Anarki:

  (require "ssyntaxes.arc")
  (add-ssyntax-bottom
    #\. (L))

-----

2 points by pg 5747 days ago | link

Interesting idea. Also fits neatly with what intrasymbol . means. Will think about it.

-----

1 point by rntz 5746 days ago | link

It does fit, but on the other hand, being able to have a hanging or prefixed dot could allow useful naming conventions, and as long as it's standardized where dots are allowed, this won't conflict with intrasymbol dots (ie: "foo..bar" translates to one of "(foo .bar)" or "(foo. bar)"). I'm not so concerned about this with regards to dots, but with regard to #\! and #\?, used as suffixes for destructive and predicate functions respectively.

-----