10 ms·
Best? If we'd all agree on what "best" means, we wouldn't discuss anything ever. Scheme and all the other Lisp variants look terrible to me. Having an excessiv
by ahoge 11y ago
Best? If we'd all agree on what "best" means, we wouldn't discuss anything ever.
Scheme and all the other Lisp variants look terrible to me. Having an excessively simple syntax doesn't mean that it's nice to use. They went too far.
This is probably the primary reason why Lisp dialects aren't more popular. Even the simplest code examples look like some sort of practical joke.
(let ((hello0 (lambda() (display "Hello world") (newline))))
(hello0))
[Edit: This example was taken from Wikipedia's Scheme article.]
Something like that in Dart:
hello() => print('Hello world');
hello();
Dart's syntax is way more complicated, but this is much easier to understand, isn't it?
- Arcanum-XIII 11y agoSeriously ? (defn hello [] (println "hello world")) (hello) ;; in Clojure (defun hello () (format t "hello world")) (hello) ;; in Common Lisp.
- ahoge 11y agoThe example was taken from Wikipedia's Scheme article. I do not know how to write Hello World in Scheme. By the way, I really like how everyone's Hello World looks different.
- sklogic 11y agoSo, you know nothing about Scheme, but yet dare to have an opinion?
- ahoge 11y agoYes, I "dare" to have an opinion on that syntax. I like it from a theoretical point of view. It's very uniform which is convenient for implementers. It's brilliant, really. However, I dislike it from a practical point of view, because this uniform soup is hard to scan and also hard to write. I pretty much like any other language's syntax better than this one. Even fairly cryptic ones like Erlang's.
- sklogic 11y ago> Yes, I "dare" to have an opinion on that syntax. Is not it stupid, to have an opinion about something you do not know and do not understand? > It's very uniform which is convenient for implementers. It's not that uniform, really. It's so flexible that you can make it look any way you like. Any existing language syntax is a subset of this syntax. > because this uniform soup is hard to scan and also hard to write Just use a better text editor then.
- ahoge 11y ago> [Scheme's syntax is] not that uniform, really. "Scheme's very simple syntax is based on s-expressions, parenthesized lists in which a prefix operator is followed by its arguments. Scheme programs thus consist of sequences of nested lists." That's as uniform as it gets. Everything is the same.
- sklogic 11y agoFirstly, Racket is not a Scheme. There are reader macros and all that bells and whistles. Does this look like S-expressions to you? https://github.com/soegaard/minipascal https://github.com/soegaard/minipascal Secondly, even most Schemes allow to use [ ] and { } in addition to ( ).
- ahoge 11y ago> Firstly, Racket is not a Scheme. Did I talk about Racket anywhere? > Does this look like S-expressions to you? "MiniPacal implemented in Racket" Are you really arguing that implementing some other language is the way to go? https://github.com/eudoxia0/cmacro https://github.com/eudoxia0/cmacro http://research.swtch.com/shmacro http://research.swtch.com/shmacro Totally legit "C".
- sklogic 11y ago> Did I talk about Racket anywhere? This is a thread about Racket, if you did not notice. > Are you really arguing that implementing some other language is the way to go? This is exactly what Lisps are about. You've got a nearly raw AST at the bottom (S-expressions) and then you build up a hierarchy of languages on top of it.
- davexunit 11y ago>I really like how everyone's Hello World looks different. Because everyone is posting hello world examples in different languages. Lisp is a family, a category of languages, not a single language.
- talideon 11y agoYou can't effectively criticise a language without actually knowing it. That's why you're being downvoted. The example you gave is using the lowest level primitives to printing with zero syntactic sugar. It's equivalent to writing the following in JavaScript (assuming functions called 'display' and 'newline': (function () { var hello = function() { display('Hello world'); newline(); }; hello(); })(); Practical Scheme implementations include additional macros that add syntactic sugar so you an use much more straightforward mechanisms to do things.
- brlewis 11y agoThe second example is more readable for several reasons. 1. You chose a better function name (hello0 looks a little confusing) 2. You [EDIT: actually Wikipedia] decided for whatever reason to use let rather than define in the Scheme example. 3. Dart's "print" function is more suitable for console output on a single line than Scheme's "display". Here's the fix: (define (print something) (display something) (newline)) (define (hello) (print "Hello world")) All of a sudden (f a b) doesn't seem way more complicated than f(a, b);.
- jcromartie 11y agoRacket has a displayln that is similar to puts or System.out.println.
- cmiles74 11y agoFor the sake of completion... (define (hello) (displayln "Hello world"))
- _halgari 11y agoThat's mostly because such lisps are overly verbose. The same code in Clojure: (let [hello (fn [] (println "Hello World"))] (hello)) Or assuming hello is a global in your dart example: (defn hello [] (println "Hello World")) (hello) Nothing too complicated about that. Clojure is way less verbose than some scheme variants.
- jcromartie 11y agoThe equivalent code in Racket is exactly as complex as your Clojure example.
- ahoge 11y ago> Or assuming hello is a global in your dart example The way it's written implies that it's somewhere inside some block, because "main()" is always the entry point. I wrote it like that because I couldn't be bothered to figure out how this stuff works in Scheme. With entry point: main() => print('Hello World'); Alternatively: main() { print('Hello World'); }
- 59nadir 11y ago> I wrote it like that because I couldn't be bothered to figure out how this stuff works in Scheme. I think that sums everything up, really. This is how shallow the complaints about parens are. No one who actually bothers will make a point about what delimits expressions in a language. To complain about parens is also doubly wrong, as they do bring something technical to the table. What Carmack talks about when he says S-expressions are nice for reading in terms of network communication, for example, is that the messages can be read exactly like other expressions over the wire. This is true for any I/O; you can read the data just as if it was code, because the code is data. The same mechanism that reads the code you are executing is available to you to read full expressions through any medium, and use that data/code as you see fit.
- ahoge 11y ago"This stuff" was referring to the entry point. I didn't complain about parenthesis. ASM's syntax is also extremely simple, but that doesn't make it easy to use, does it? If everything looks the same, it's hard to scan. C-like languages provide more visual hooks than Lisp dialects.
- deleted 11y ago[deleted]
- jcromartie 11y agoIs this just trolling? Why a let and "hello0"? Is that just to make it look weird on purpose? (define (hello) (displayln "Hello, World!")) (hello)
- ahoge 11y agohttps://en.wikipedia.org/wiki/Scheme_%28programming_language%29#Input.2Foutput https://en.wikipedia.org/wiki/Scheme_%28programming_language...
- thechao 11y agoI used to program in a LISP (the language predates Lisp) derivative called "Boot". (It booted a computer algebra system.) It added two rules to LISP: unparenthesized expressions bind "to the function call", using dynamic lookup to determine arity, and failing if the binding wasn't unambiguous; and, ';' to delimit expressions. It's been a decade since I used the language, but it would look something like this: define (hello) displayln "Hello, World!"; hello; The boot 'compiler' only did name resolution and parenthesization, then it kicked everything back to an underlying LISP. (In this case, SBCL, which rocked!) The second level language built on Boot was Spad, which used a slightly friendlier syntactic top-form: e : t = x With compact forms: e := x e = x e : t e Which lets you uniformly parse packages, modules, domains, categories, functions, annotations, etc. etc. For instance, we had a Spad-lite syntax: Monoid : Domain = public : _* : (y : Monoid), (x : Monoid) _0 : Monoid Then you could assert membership: assert(Integer, Monoid) := _* : (y : Integer), (x : Integer) = (_*:Integer)(x, y) _0 = (0:Integer) An implementation would be: Monoid : Domain = public : -- see above. = implements : -- implementations.
- agumonkey 11y agoQuite a beautiful addition to sexps. I've seen implicit rules about top-level expression being implicitely wrapped in parens you one can write defun fact (n) (cond .. ..) which makes lisp so much more bearable to parensophobic people.
- 59nadir 11y agoEven if you use this redundant `let` form you can still make it more readable by doing the following: (let ([hello-func (lambda () (displayln "Hello world!"))]) (hello-func)) This applies globally; when it makes sense, differentiate between some lists by using brackets instead of parens. Some Lisps take this further by using other bracket types to signify certain things. I would advise not to hop on Wikipedia and assume things about languages. Scheme is not very hard to get into and with variants where batteries included you can build useful stuff right out of the box. Go to http://www.racket-lang.org/ http://www.racket-lang.org/ if you want to see a good example of a pragmatic and useful Scheme variant that may just dispel some of your prejudices.
- sklogic 11y ago> Scheme and all the other Lisp variants look terrible to me Baby duck syndrome? > Having an excessively simple syntax doesn't mean that it's nice to use. Having an excessively simple syntax ensures that you can add any amount of syntax on top of it, whatever you fancy. Do not like S-expressions? Fine. Code in any syntax you like. > but this is much easier to understand, isn't it? No, it is not.
- klibertp 11y agoThe code you pasted is used to illustrate the concepts of ports. You took it out of context. It's not an example of hello world like you're claiming. Also, the code on Wikipedia doesn't always match actual practice of programming in a language.. If you want to see more realistic examples go to RosettaCode, pick interesting task and look for Scheme, Racket and Clojure entries. You can then compare them to each other and to other languages you know. The other thing is that your code in Scheme and Dart don't do the same thing at all, unless I underestimate Dart semantics very much. A translation of your Scheme code to JS, with as much semantics preserved as possible, would look something like: (function (){ // let introduces new scope var hello0 = function (){ // hello0 is a variable holding an anonymous function return console.log("Hello world"); }; return hello0(); })(); That's quite a bit of work less in Scheme, isn't it? But for when you don't need these semantics you can do a translation the other way round (Dart->Lisps). In Racket your Dart example would look like: (define (hello) (displayln "Hello world")) (hello) Now, that looks better, right? It's worth noting that the Racket version has only one pair of parens than Dart.
- klibertp 11y agoTo expand on this a little, here is a thing that you can't translate to most programming languages. By defining a simple, pattern-based macro we can get much closer to the Dart version: (func: hello() => (displayln "Hello world")) (hello) All you need to do this - to change the language syntax to look like that - is to write this: (define-syntax func: (syntax-rules (=>) [(_ name (formal ...) => expr ...) (define name (lambda (formal ...) expr ...))]))