7 ms·
Python: sum(range(1,11)) I think this more explanatory than the Lisp. Perhaps that's just me.
by willvarfar 11y ago
Python:
sum(range(1,11))
I think this more explanatory than the Lisp. Perhaps that's just me.
- jokoon 11y agoYes, this article shows several different ways to do one same thing, you can't really expect programmers to remembers all this syntax. from https://www.python.org/dev/peps/pep-0020/ https://www.python.org/dev/peps/pep-0020/ : > There should be one-- and preferably only one --obvious way to do it. I don't know if common lisp is an "easier" lisp, but I sure would like to have a watered down version of lisp so I can learn its paradigms. I don't even know if that's what haskell is.
- willvarfar 11y agoI picked Python as its the language I think most easy to write and read. Concise enough without being write-only.
- m0skit0 11y agoI disagree. You say so because you're used to Python. In Python you need to remember quite a few syntax rules. How many different symbols you need to write a relatively complex program? How many symbols/words are reserved? In LISPs there's much less syntax to remember.
- whostolemyhat 11y agoYep, in Lisp all you need to remember is (). Python has more syntax to remember than in Lisp, but ends up being a lot more readable (eg lists, dicts etc)
- SSLy 11y ago> lists, dicts Clojure does them right, imho.
- falcolas 11y agoAnd uses the same symbols as Python, Ruby, and a number of other high level programming languages.
- m0skit0 11y agoNo, it doesn't. In fact, you can avoid them if you wish and build everything from simple lists. Point being: I don't have to remember a specific syntax for "for" loop, or for equality (==)...
- m0skit0 11y agoI don't really see how having to remember more symbols and syntax rules makes anything more readable. It doesn't. You have to know what those symbols mean, and the more there are, the less readable it is by definition because you need more knowledge to understand it. I understand it is more readable for YOU because you already have that knowledge. The same applies where English is readable for me but Chinese is not. If Chinese "syntax" was simpler, I could actually learn it way faster, as everyone else, which would make it more "readable" to everyone that has not previous knowledge, not just to YOU :)
- jokoon 11y agoso why am I failing to learn lisp ?
- JackMorgan 11y agoAre you failing to learn it? What have you tried? What's holding you back? I'm offering a free Clojure workshop next Saturday if you're in the Philadelphia region. http://www.meetup.com/Clojadelphia/events/221835485/ http://www.meetup.com/Clojadelphia/events/221835485/ Otherwise, I worked through SICP a couple years back, and I found it invaluable to getting familiar with Lisps and functional programming in general. I remember sitting down one day (before working through SICP) and saying, "I'm great at PHP, I'll probably just be able to write a Clojure project off the top of my head!" Cue clown music as I beat my head against a language much more expressive than anything I'd encountered to date. It was a few solid weeks of effort before I could get anywhere, but I remember remarking at the time, "if I can learn this well enough, I'll be a wizard!"
- jokoon 11y agosicp is pretty hardcore I tried reading lisp courses or tutorials, it really did not help. It's either too steep, or it just talks about simple things like adding numbers like (+ 5 9) I'm more into what makes me understand lisp as a better language.
- JackMorgan 11y agoI've heard rave reviews of Joy of Clojure as a good book to "get it". I found I really had to work at the problem from several angles before it "clicked". I started with Land of Lisp, but it felt very arcane to me at the time. I would copy in code from the book, and then look back at just jibberish. I gave up on that a few chapters in. Then I made that site in Clojure, one error at a time, pounding like a monkey until it worked. I then read Clojure Programming twice, followed by working through Let Over Lambda. About halfway through Let Over Lambda, I think it "clicked". I finished with an amazing online course in Programming Languages through Brown University. I finished with SICP chapters 1-3. Nothing worthwhile is ever easy. If you need any help please reach out, you can't waste my time.
- willvarfar 11y ago(old thread, sorry) Python is designed to be human readable. Here's an old blog post by me, which may be hard to jump into because its part of a longer conversation on proggit or something, but anyway: http://williamedwardscoder.tumblr.com/post/18319031919/programming-language-readability http://williamedwardscoder.tumblr.com/post/18319031919/progr...
- m0skit0 11y agoIt fails. The more symbols and syntax rules you have, the less readable it is. I think this is pretty straightforward to understand :) Human language has pretty much non-existant symbols besides the alphabet.
- dzpower 11y agoRacket (a Scheme descendant) might be a good fit. It has teaching languages, which are simplified, and a nice IDE (DrRacket), and books (HTDP/2e (free online), Realm of Racket, etc.) Close match to the Python above: (apply + (range 1 11))
- Someone 11y agoCommon lisp = committee lisp; it's not "easier". It standardized lisp by including about every feature that any of a set of competing Lisp's had. For example, the 'format' function can write numbers in roman digits, spell out numbers, and capitalize words (http://www.gigamonkeys.com/book/a-few-format-recipes.html http://www.gigamonkeys.com/book/a-few-format-recipes.html) Beginners probably are better of using scheme or racket.
- hga 11y agoCommon Lisp == Mainline Lisp. It's the direct descendant of original formula McCarthy LISP, and has accumulated a lot of warts and random stuff. Plus it's more generally multi-paradigm than Scheme, Racket or Clojure, and has no bias towards simplicity and a limited one towards elegance.
- lispm 11y agoCommon Lisp is basically the successor to Maclisp - which already had the FORMAT function. Common Lisp does not force you to use FORMAT. It has a bunch of simpler IO functions, too.
- calibraxis 11y agoOk, if you have `sum` defined: (sum (range 1 11)) If we refuse to normalize the languages by defining `sum`, then it’s an API battle... And Clojure/Clojurescript has easy access to Java and Javascript. (Plus if we count Clojure on .NET...)
- agumonkey 11y agowhere is times(range(1,11)) ? --- (apply #'* (-range 1 11)) python is weirdly halfway on 'math oriented' abstractions.
- falcolas 11y agoJust not included in to the standard library (it doesn't really have a common use case), but certainly implementable, and without loops to boot! >>> def times(input): ... return reduce(lambda x, y: x*y, input, 1) ... >>> times(range(1,11)) 3628800
- agumonkey 11y agoOf course, it's just weird to see `sum` built-in all alone. They even have operator.mul so... >>> Prod = lambda xs: fp.reduce(op.mul, xs, 1) >>> Prod(range(1,11)) 362880
- TheLoneWolfling 11y agofrom functools import reduce from operators import mul def times(data): return reduce(mul, data)
- agumonkey 11y agoI'm not saying it's not possible, just that they stopped too early. >>> times([]) TypeError: reduce() of empty sequence with no initial value from functools import reduce from operators import mul def times(data): return reduce(mul, data) Proper neutral element: >>> times = lambda l: reduce(mul, l,1) >>> times([]) 1
- TheLoneWolfling 11y agoWhoops, but again as you say that is trivial to fix.
- 11y ago
- brudgers 11y agoHow did 11 come into the problem? Aren't the integers the domain over which we are operating? How is the comma obvious from the problem statement? If I can assume a person knows a particular language, the J version is perfectly clear. +/ 1+ i.10
- espadrine 11y agoOr Perl6: [+] 1 ... 10
- TheLoneWolfling 11y agoPythonic range(a,b) is [a...b[ over the integers(in the interval sense.) But yes, I acknowledge that every programming language requires a certain amount of knowledge about generalities, Python being no exception. And I really should sit down at some point and learn an APL variant.