Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Let block #36

Closed
wende opened this issue Apr 29, 2017 · 14 comments
Closed

Implement Let block #36

wende opened this issue Apr 29, 2017 · 14 comments

Comments

@wende
Copy link
Owner

wende commented Apr 29, 2017

Add:
Let

Example:

let 
  a = 1
in
  a * 2

->

a = 1
a * 2
@net
Copy link

net commented May 1, 2017

Is there a need for let instead of simply writing

a = 1
a * 2

?

@OvermindDL1
Copy link

Is there a need for let instead of simply writing

Beside that it is not valid elm? It allows you to define recursive structures too.

@wende
Copy link
Owner Author

wende commented May 1, 2017

Exactly. So far we're trying to be syntactically idiomatic to Elm. When we succeed to copy the whole language we might discuss some changes. But it's definitely not a time for that yet :)

Plus having let... in has a very important implication which is being consistent about functions being only one expression

@net
Copy link

net commented May 1, 2017

It allows you to define recursive structures too.

Could you elaborate on this @OvermindDL1?

@net
Copy link

net commented May 1, 2017

Plus having let... in has a very important implication which is being consistent about functions being only one expression

Assignment is not an expression in Elm.

@OvermindDL1
Copy link

Could you elaborate on this @OvermindDL1?

Some valid elm, you can create inline mutually recursive functions and calls and such.

import Html exposing (text)

main =
  let
    r = c 1
    a b = 21 * b
    c d = a (d+1)
  in text (toString r)

I still prefer the OCaml method though, much more clear and redefinable...

@net
Copy link

net commented May 1, 2017

You could still achieve that without the let syntax.

main =
  r = c 1
  a b = 21 * b
  c d = a (d+1)

  text (toString r)

@OvermindDL1
Copy link

The purpose is to allow rebinding as well (this is not valid elm because elm is a bit stupid in how it does a lot of things):

import Html exposing (text)

main =
  let
    r = c 1
    a b = 21 * b
    c d = a (d+1) in
  let r = r + 1 in
  text (toString r)

In addition to controlling scoping and more things.

Plus, it does not matter, it is still not valid elm to leave the let out. ;-)

@wende
Copy link
Owner Author

wende commented May 2, 2017

Assignment is not an expression in Elm.

@net Exactly. But the let..in block is

@net
Copy link

net commented May 2, 2017

@OvermindDL1 Is rebinding in an expression really that important? Many would argue that rebinding only causes confusion. Pick better variable names instead.

Scoping is entirely possible with the non-let syntax.

@net
Copy link

net commented May 2, 2017

@wende Right, so allowing assignments before an expression does not violate the one-expression-per-function rule.

@OvermindDL1
Copy link

@wende Right, so allowing assignments before an expression does not violate the one-expression-per-function rule.

Unless you are getting into whitespace sensitivity (ew) then it becomes ambiguous:

  a = 4
  b = 4 + a
  b + 6

Unless the language is whitespace sensitive (big ew) it is parsed like:

  (a = 4) (b = (4 + (a b) + 6)

The let ... in ... defines bounds.

But still, it is a moot point, elm does not allow it. ;-)

@wende wende self-assigned this May 3, 2017
@wende wende closed this as completed in #25 May 3, 2017
@wende
Copy link
Owner Author

wende commented May 3, 2017

@OvermindDL1
Elm is a little bit whitespace sensitive when it comes to case branches and function calls.
For example

...
Something -> 
  fun 
     a
     b
     c
SomethingElse b c ->
...

You can't really know where fun ends, and SomethingElse starts. It's a big issue to solve for us right now #40 and it's gonna be really hard because of whitespace sensitivity.
So I definitely preach to your ew

@OvermindDL1
Copy link

Elm is a little bit whitespace sensitive when it comes to case branches and function calls.

I know, it endlessly bugs me. ^.^;

Honestly I'd say you should write a new backend for OCaml that compiles to Elixir instead. ^.^
I've been wanting to do that, but so very much lacking on time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants