4 ms·
This is cool, but you can go pretty far w/ FP idioms in Python without requiring a DSL/transpiler: - Toolz (http://toolz.readthedocs.io/en/latest/ http://toolz
by hcarvalhoalves 10y ago
This is cool, but you can go pretty far w/ FP idioms in Python without requiring a DSL/transpiler:
- Toolz (http://toolz.readthedocs.io/en/latest/ http://toolz.readthedocs.io/en/latest/) provides the same primitives from Clojure (including partial functions, compose, juxt, etc)
- Pysistence (https://pypi.python.org/pypi/pysistence/ https://pypi.python.org/pypi/pysistence/) provides immutable data structs
- For parallel map you can use https://pypi.python.org/pypi/python-pmap/1.0.2 https://pypi.python.org/pypi/python-pmap/1.0.2
- TCO is achievable w/ a decorator regardless of AST manipulation (like Clojure's `loop/recur` construct)
The only thing left is pattern matching and more powerful destructuring (Python already has limited support for it), I guess.
- _navaneethan 10y agoPattern matching Is it mimics the Erlang behaviour?
- spraak 10y agoReminds me a lot of Elixir actually. I'd really prefer a purely functional language with LISP syntax. Does anyone know of any? I find it easier to understand than Haskell..
- benley 10y agoIs Clojure close enough? Or perhaps LFE (Lisp-flavored Erlang)?
- fiddlerwoaroof 10y agoThere's also Shen: http://shenlanguage.org/ http://shenlanguage.org/
- fiatjaf 10y agoNo, you can't, because lambdas.
- Lambdanaut 10y agoCould you elaborate on that?
- merlincorey 10y agoPython lambdas are explicitly artificially limited to a single expression. Python has statements which are not expressions, mostly control statements and looping constructs.
- fovc 10y agoThe syntax isn't the greatest, but you can get pretty far with Python's ternary expression. Generators in my experience remove the need for most loops. Where lambdas feel really subpar for me is the lack of 'let' and error-handling.
- deleted 10y ago[deleted]
- Phrodo_00 10y agoWhile it IS a conscious decision to force lambdas to be a single expression, extending it to be able to be multiline would screw up with indentation being irrelevant inside of a function call too.
- SwellJoe 10y agoPython lambda is somewhat limited, compared to lambda in some other languages. Guido isn't overly fond of lambda or other functional building blocks (and even planned to remove it from Python, before there was a sufficient outpouring of support for keeping it). http://www.artima.com/weblogs/viewpost.jsp?thread=98196 http://www.artima.com/weblogs/viewpost.jsp?thread=98196 As I understand it, the primary limitation is that Python lambda only works with a single expression (I think it also has some weirdness regarding scope when calling functions?). I haven't poked seriously at Python since around about the time they were talking about removing it, so I probably have no idea what I'm talking about. The idea is that generators and list comprehensions do the things most people do with lambdas in a more Pythonic way.
- coconutlang 10y ago> The only thing left is pattern matching and more powerful destructuring (Python already has limited support for it), I guess. Coconut does both of those!