News for hackers. Stuff that matters.
Re:Stop writing lambda expressions in Python by nikofeyn on Thursday September 27, 2018 @04:27PM (#18088281)
f# (and also ocaml and sml) have all those and much more. they are much more consistent and principled in their design, which makes things simpler to understand.

for example, in all three languages above, expressions are much easier to understand because they always return a value. this makes code easier to reason about. this is not true in python.

the languages i mentioned do have static typing but they have type inference. so you get the best of both worlds. you do need to type annotate at some points to clarify things, but this isn't a problem as it documents to both the user and compiler.

given your above reasons, you owe it to yourself to learn an ml. there is the programming languages course on coursera by dan grossman, which uses sml in the first part, and the ocaml mooc just started where you still have time to register and complete it.

https://www.coursera.org/learn/programming-languages

https://www.fun-mooc.fr/courses/course-v1:parisdiderot+56002...

Re:Stop writing lambda expressions in Python by pdonis on Thursday September 27, 2018 @05:21PM (#18088812)
> f# (and also ocaml and sml) have all those and much more

F# has curly braces. Also, as you say, it requires some type annotations.

I see that F# has a REPL, but it seems bolted on as an afterthought instead of being an integral part of the language. (Also, it's not clear whether the REPL is available in Mono on Linux. I am allergic to Windows and anything built by Microsoft.)

> expressions are much easier to understand because they always return a value. this makes code easier to reason about. this is not true in python

Huh? Python expressions always return a value.

Perhaps what you mean is that Python also has statements, which do not return a value, whereas these languages do not--everything is an expression, as in Lisp?

> you owe it to yourself to learn an ml

I don't owe it to myself to learn anything unless I decide to. I wasn't trying to convince anyone else to use Python; I was just giving reasons why I like Python. Please extend me the same courtesy when you talk about things you like about your favorite languages.

Re:Stop writing lambda expressions in Python by nikofeyn on Thursday September 27, 2018 @06:17PM (#18089307)
okay, f# has curly braces. but not in the sense of other C-like languages like c++, java, and c#. they are primarily used for sequence expressions and computation expressions like async.

> I see that F# has a REPL, but it seems bolted on as an afterthought instead of being an integral part of the language. (Also, it's not clear whether the REPL is available in Mono on Linux. I am allergic to Windows and anything built by Microsoft.)

well that first sentence is simply not true, and i don't know what gave you that impression. f#'s repl, f# interactive, is available on linux through mono and will soon be available through .net core. i can't help you being needlessly allergic to a major operating system or company. f# came out of microsoft research.

> Huh? Python expressions always return a value.

they do? take:

  def test(x):
    "something"
so what does

  test(2)
return?

> I don't owe it to myself to learn anything unless I decide to. I wasn't trying to convince anyone else to use Python; I was just giving reasons why I like Python. Please extend me the same courtesy when you talk about things you like about your favorite languages.

i don't know why you're upset. i am not for sure where i was discourteous. i didn't mean anything by my statement other than to check out the languages and courses (the coursera one is very good). if those are your reasons for python, i just thought you would honestly like an ML-based language. i just used "owe it to yourself" as an expression, which apparently came out wrong through text. of course you don't owe anyone anything. i was just making a suggestion.

Re:Stop writing lambda expressions in Python by pdonis on Thursday September 27, 2018 @08:26PM (#18090040)
> of course you don't owe anyone anything

Yes, and thanks for acknowledging that. But then the phrase "owe it to yourself" didn't really communicate your intent correctly, which is why I objected to it.

Re:Stop writing lambda expressions in Python by firefwing24 on Thursday September 27, 2018 @06:41PM (#18089495)
Replying to your reply of the child comment:

> i guess that is true in python3 but it is not in python 2.7.

No, it's always been there.

    >>> def f():
    ...     pass
    ...
    >>> f() is None
    True
Re:Stop writing lambda expressions in Python by codexon on Thursday September 27, 2018 @06:27PM (#18089380)
>>> test(2) is None

True

Re:Stop writing lambda expressions in Python by nikofeyn on Thursday September 27, 2018 @06:34PM (#18089435)
i guess that is true in python3 but it is not in python 2.7.
Re:Stop writing lambda expressions in Python by xapata on Thursday September 27, 2018 @06:39PM (#18089482)
False. You're just not familiar with how the REPL works.

    >>> None
    >>> print(None)
    None

In the future, you might want to refrain from strong criticism of a thing you're not familiar with. That habit leads to all sorts of -isms.
Re:Stop writing lambda expressions in Python by nikofeyn on Thursday September 27, 2018 @07:54PM (#18089884)
i do know how the repl works. i explicitly tried it out. i defined the function just as i said and ran

  test(2) is None
and got false. i just now went to try it out again at home and got true. i don't know what to tell you other than something must have got shadowed somewhere.
Re:Stop writing lambda expressions in Python by pdonis on Thursday September 27, 2018 @08:22PM (#18090018)
Here's what I get from the Python 3 REPL:

    peter@localhost:~$ python3
    Python 3.5.2 (default, Nov 23 2017, 16:37:01)
    [GCC 5.4.0 20160609] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> def test(x):
    ...     "something"
    ...
    >>> test(2) is None
    True
And Python 2:

    peter@localhost:~$ python
    Python 2.7.12 (default, Dec  4 2017, 14:50:18)
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> def test(x):
    ...     "something"
    ...
    >>> test(2) is None
    True
If you post such a transcript from your REPL session where you get False, it should be easier to tell what's different between your setup and mine (which is a stock Python install on Ubuntu 16.04).

However, there is another even more direct experiment you could have run at the Python REPL to see what Python expressions return: just type the expression directly at the REPL and see what it prints back at you. In Python 3:

    peter@ToshibaSatellite:~$ python3
    Python 3.5.2 (default, Nov 23 2017, 16:37:01)
    [GCC 5.4.0 20160609] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> "something"
    'something'
And in Python 2:

    peter@ToshibaSatellite:~$ python
    Python 2.7.12 (default, Dec  4 2017, 14:50:18)
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> "something"
    'something'
So, in your test function above, the expression "something" does return itself; it just does it inside the function, and that return value then gets thrown away when the function exits, because you didn't return it from the function itself.
Re:Stop writing lambda expressions in Python by nikofeyn on Saturday September 29, 2018 @04:49PM (#18102727)
i know how to use the repl. i moved between computers during comments and wasn't able to inspect my repl session where it originally returned false. as i mentioned, i must have redefined something or shadowed something which caused confusion, and i just didn't realize it at the time.