gkz / LiveScript

LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.
http://livescript.net
MIT License
2.31k stars 155 forks source link

Why we need to add `do` in order to provide arguments? #950

Closed askucher closed 6 years ago

askucher commented 7 years ago

func do 
  1
  2

#why not just 

func 
  1
  2

I am asking because trying to implement pug like syntax based on LiveScript and attract React developers (https://github.com/flyber-net/lsx-pug)

determin1st commented 7 years ago

you have unreadable syntax in both cases. imo.

caasi commented 7 years ago

I'd remember that you can write React in this way:

div do
  className: 'book' # props
  Presentation.render @props.data, @props.scale # children
igl commented 7 years ago

The compiler does not know that func is indeed a function. You have to provide a hint to create an argument-list from this code-block

askucher commented 7 years ago

@igl please read it https://hackernoon.com/react-livescript-livescript-2-0-164d35ca5373#.q5m3pjmdl

rhendric commented 7 years ago

@askucher, getting rid of the do would indeed make your DSL look nicer, but if you want to understand why having to write the do is useful, you should probably look at some different applications of LiveScript.

For example, here's some LiveScript that works today that would mean something different if LS had indentation-based do inference:

args =
  \--options silent-opt
             noninteractive-opt
  \-- filename

This snippet takes advantage of the fact that indentation is irrelevant inside a list, and is obviously not intended to mean

args =
  \--options silent-opt do
             noninteractive-opt
  \-- filename
ozra commented 7 years ago

I agree on the DSL pro, that's why I tried it out in (LS-inspired) Onyx... https://github.com/ozra/onyx-lang/issues/60#issuecomment-201954355 - sure it has type inference - but parsing is done before typing (to avoid the hellishly slow C++-compile times), so it would obviously work in JS-transpile-lang, if it wasn't for wasting possibilities on... not so necessary features. LS has been very good to me over the years (still use it daily aside from the to-native langs) - but there can definitely be something better.