Hacker News new | ask | show | jobs
by chdjdjdnc 3648 days ago
I really, really like the concept, but I strongly dislike the syntax. Excessive punctuation is the enemy of code readability.

Someone need to make lisp without the parentheses, where scoping can also be managed by indentation like in python. Throw in some strong imperative programming so that it's a lisp masquerading as C (because purism sucks), and you'd have one very powerful language

12 comments

Wisp (aka Whitespace Lisp; actually Scheme but whatever):

http://www.draketo.de/english/wisp/shakespeare

OpenDylan (I have heard it referred to HN as a Lisp without parens more than once):

http://opendylan.org/

And Rebol, not being lispy by the standards of few/some/many, is insane with macros from what I gather. Someone posted Red, a Rebol analogue that is an open source attempt to duplicate its expressiveness out of admiration.

http://www.red-lang.org/2015/12/answers-to-community-questio...

I am confused though because this is says macros are not there. I obviously don't use it, but the last HN thread about it made it sound crazy.

https://news.ycombinator.com/item?id=11364447

Anyway, re the strong imperative thing, someone posted Bone Lisp a couple days back, but this will not please you, it is classic parens Lisp, sans GC (I read but still have no clue how that works).

IIRC OpenDylan maintainer expressed regrets about the syntas a few times. An historical burden from some Apple decisions long ago.
I still have Apple's Dylan book where it has Lisp-like syntax somewhere. The infix they came up with is ugly.

Dylan was supposed to be used for Apple's Newton handheld, but was too late and basically died in the 1990s. I'm no expert, but I recall it was basically a dumbed down Lisp with OO extensions and module support that was changed to a dumbed down Algol with OO extensions and module support.

I have the books for Harlequin Dylan, but the language never got traction.

It was basically an infix lisp with focus on hygiene (because it was basically a Lisp 1), and the possibility of sealing modules (making it impossible to alter / inherit from them ).

This IIRC; it's a long time ago...

I think the problem is more the example than the syntax, it basically has keyword arguments (foo: bar), square brackets for lambda ([echo :x]) and :foo for block arguments.

I.e. this

    1 to: 5 do: [echo :x]
is pseudopython's

    loop(from=1, to=5, do=lambda x: echo x)
    loop(1, 5, lambda x: echo x)

which have comparable punctuation, mostly trading "," for ":" .

Being smalltalkish, you also get extra characters when a block is used for control structures, but that saves on the need to have two different syntaxes for single and multi-line/expression lambdas or N syntaxes for blocks and control structures.

How do you see that handled in your ideal language?

Ruby, another language in the Smalltalk lineage, did without the [ ] at the cost of the "end" keyword to terminate blocks, but there is also the equivalent {} notation, recommended for one liners.

A Python indented Ruby would probably able to do without [ ] but I should think about whether there are some unresolvable ambiguities with that approach. I won't recommend that personally because syntactical spaces introduce bugs. I run into one a few days ago when I moved code around a file and forgot to fix the indentation of a few lines. Luckily this one cost me only five minutes. Many people like Python though.

Overall I like the terseness of

    1 to: 5 do: [echo :x]
instead of the more verbose

    loop(1, 5, lambda x: echo x)  # Python
    (1..5).each do { |x| echo x } # Ruby
    (1..5).each do |x|            # Ruby again
      echo x
    end
But all those : are annoying: they increase the noise/signal ratio. I'd even do without the | | in the multi line Ruby version. I wonder if the compiler could add the : automatically by matching what it sees with the signatures of the defined function.

    1 to 5 do [echo :x]
Then, why you need :x and couldn't use x without the : ? Furthermore, how do I know how the name of the block argument if I didn't write the function. Isn't that an unnecessary coupling between the name chosen by the developer of the library and my code? I probably didn't understand everything is going on here. Edit: it has been explained in another comment in the parent's thread.

And there are so many commonly used languages that use { } to define code blocks and [ ] for arrays. I'd stick with the majority for an easier onboarding of developers.

The possibility of defining pseudo keywords thanks to the infix/suffix arguments is great. That's probably anathema in the Python world (only one way of doing things) and also in Go's. It should be acceptable in Ruby's.

I'd prefer something like this

   func (n)to(m)do(blk) {
     x = n
     ...
     do blk x
     ...
   }
The order of arguments and function names is clear because you read them from left to right without going through two different lists.

Is anybody using Spry for real world programs?

   func (n)to(m)do(blk) {
     x = n
     ...
     do blk x
     ...
   }
This looks ambiguous. Your function does not have a name, how do you do if another library wants to do something different with the same keywords? And how do you know when arguments should be evaluated? In your case, "blk" seems to be a set of statements to be executed when "do" is applied, is it right? shall we scan the body to detect if we use "do" on our arguments or does "do" in the signature have a special meaning?
I was describing a syntax I'd like starting from the idea that the compiler should bend to developers and not viceversa.

Let's see if we can make it work.

func (n)to(m)do(blk) could be syntactic sugar for to:do: funci (n, m, blk). I saw funci in the examples, I didn't investigate if there are other type of function definitions. However, if the definition starts with (arg) it should be easy to map it into a funci. This either solves the problem of name clashes with other libraries, or the problem is unsolved right now.

The block passing is more serious. Maybe we could mark blk in such a way we know it's a block. Ruby uses & as in

    func (n)to(m)do(&blk)
Maybe Spry uses & in an incompatible way and I don't like it much anyway. It's developers bending to the compiler, but let's be realistic: we don't want slow compilers.

What Ruby also does is having a yield keyword that calls an anonymous block passed at the invocation point of the function (a method in Ruby's world). The block is not declared as argument of the function/method. Maybe:

    func (n)to(m)do() { # an empty arg is a block
     x = n
     ...
     do x
     ...
    }

    1 to 5 do { echo x }
But I think this is getting far away from the way of Spry.
I am sympathetic to the idea that compilers should bend for developers and that's partly why I love Lisp. Your new syntax has to be learnt by the compiler and that does not scale necessarily well. The regularity of Lisp's syntax is what helps writing code that writes code. Messing up with the readtable, you could obtain something like this:

    {1 to 5 (echo x)}
... which would read into:

    (loop for x from 1 upto 5 do (echo x))
Note that binding `x` implicitly is bad style, as well as defining terse syntax for every construct.
I should mention that Spry uses all of () []{}. The () are reified as Paren as in Rebol which makes it useful in templating etc. {} are used to create Maps, like {x = 1} creates a Map with one kv pair.
I tried to find an example of the macro-like approach of Spry and couldn't. How is it expressed?
You could also use mixfix notation for this:

    _to_do_
      n to m do f =
        x := n
        ...
No, Spry is not at that point yet. Or at least I sure hope noone is! :)

What you describe (interesting syntax) is a way to declare argument names and Spry doesn't declare them. That's a discussion in itself of course, but right now it doesn't.

Yes, correct. It's worth noting that echo is a prefix function so Spry supports both infix (first argument is on the left) and prefix functions, and if there is a series of keywords the parser will rewrite the keyword call to a prefix/infix call like this:

array at: 1 put: 2 ==> array at:put: 1 2

Thus a keyword call is purely syntactic sugar.

And also, the block [echo :x] doesn't use declarations of parameters - instead the ":x" is an operation that pulls in the next argument from the call site and stores it into the local binding x in the closure. Almost Forth-ish, but there is no stack.
> Excessive punctuation is the enemy of code readability.

So why is a standard trope about Lisp that with some acclimation the parentheses disappear? This is something that depends on what you're used to, and in some cases identifiable characteristics of individuals' visual processing, it's not a universal truth.

Lisp can already be written like C. Most of the Lisp crowd doesn't give into any notion of "purism".

The parentheses of lisp provide a canonical serialization format. What you're actually asking for is "don't represent lists with brackets." Even Python uses brackets (and commas) for lists.

Tcl is lisp without parens. Doesn't get much love these days but a still a serviceable workhorse that has been gradually modernized in the last few releases.
Thanks for mentioning Tcl, in a lot of ways it resembles Lisp/Scheme, and with addition of tailcall, apply, coroutines the resemblance has increased over time. It remains very useful and versatile, and Tcl/Tk may still be the easiest way to create a GUI application that will run on several platforms.
I agree that symbols tend to make code harder to read, but I find that it's the number of different symbols that mostly cause issues, and that a few symbols that are used in simple and obvious ways, like parens and curly braces, don't tend to make code more difficult to read.
> Someone need to make lisp without the parentheses [...] Throw in some strong imperative programming so that it's a lisp masquerading as C

This actually describes the R programming language pretty well. A lisp with C-like syntax and vectorized primitives.

It's a toy like several others mentioned in this thread, but this language I worked on has ultra powerful lisp macros (f-exprs), guesses parens from indentation, provides infix, and supports imperative programming as well as Arc: http://akkartik.name/post/wart. Here's an example showing off all these features: https://gist.github.com/akkartik/4320819
So, if you leave out parentheses it uses indentation and switches to infix?
No, the two are independent. The rules for parentheses:

1. Multi-word lines without leading parens are grouped with later indented lines.

2. Indentation is not sensitive inside parens.

More info, unpacking the implications: https://github.com/akkartik/wart/blob/47e3572a29/004optional...

Infix works by using a disjoint set of 'operator characters' that isn't available to prefix symbols. More info: https://github.com/akkartik/wart/blob/47e3572a29/006infix

Just curious about what you refer to as "excessive punctuation"? You mean blocks []?

There are no statement separators (!) in Spry and the grammar is very, very minimalistic. You could argue in some ways Spry is "a Lisp without parenthesis", and although I like indentation (Nim uses it) for scoping I also find Smalltalk VERY readable.

Also, it's not yet apparent but the syntax/grammar of Spry (and homoiconicity) makes it very suitable for DSL construction, very much similar to Rebol/Red.

> Someone need to make lisp without the parentheses, where scoping can also be managed by indentation like in python. Throw in some strong imperative programming so that it's a lisp masquerading as C (because purism sucks), and you'd have one very powerful language

Funny, that's an almost exact description of Nim :-)

http://nim-lang.org

One person's excessive punctuation is another's dream.
Is close to english :)