5 ms·
once you "get" lisp anything beside s-expressions/prefix notation feels "inside out" and asymmetrical. I think [ ] and { } should be reserved for things like di
by shaunxcode 16y ago
once you "get" lisp anything beside s-expressions/prefix notation feels "inside out" and asymmetrical. I think [ ] and { } should be reserved for things like dicts, vectors or lambdas.
- silentbicycle 16y agoMostly agreed, but I've used Lisps for years, and prefix for arithmetic still feels weird. My personal preference is infix without operator precedence (like APL and Smalltalk) or postfix (like Forth). All-prefix, all-postfix, or all-infix consistently make sense. Infix with arbitrary transposition due to historical "order of operation" doesn't, but it's the common convention, and minor changes to it (e.g. +. for floating-point-addition in OCaml) seem to really piss people off. Most other function calls are already in prefix notation, people just think (f x y) is totally weird, while f(x, y) is normal. Cognitive dissonance. Also, I think it's cute that Prolog sticks all arithmetic under an "is" operator ("X is Y+Z*3"), rather than letting it dominate the language the way it usually tends to.
- zephyrfalcon 16y ago"Mostly agreed, but I've used Lisps for years, and prefix for arithmetic still feels weird." But that is just because you learned the conventional notation from a very young age, right? We all did, hence the name "conventional". When we learned to add and subtract, we also learned that the notation was 2+3, not (+ 2 3). That's why any other notation feels "unnatural". I do wonder if it would be possible to teach kids prefix notation instead, and whether such notation would seem completely natural to them. (I suspect the answer to both is yes.)
- silentbicycle 16y agoI learned arithmetic at a young age, yes (and I taught myself BASIC when I was 5-6ish). My main objection to prefix notation for arithmetic is that it's cumbersome. Mostly because if the arity of ops aren't predefined (e.g., + isn't limited to 2 arguments), parenthesis are needed for grouping. Infix, w/ order of op: y^2*(6x^3 - 3x^2 + 2x - 9) Prefix: (* (^ y 2) (+ (* 6 (^ x 3)) (* -3 (^ x 2)) (* 2 x) -9)) Infix, no order of op: y^2*((6* x^3) - (3* x^2) + (2* x) - 9) But as long as we're talking polynomials, J wins, IMHO: (y^2)*+/_9 2 _3 6*(x^i.4)
- waterhouse 16y agoThat is an interesting question. I see one possible argument (whose correctness I don't know enough to judge, I'm just making it up) why infix is more natural than prefix: A kid will start by seeing an object, and only once you have an object does it make sense to combine it (by addition or whatever) with another object. Also, note that a certain amount of English syntax is infix: "I went to the store", not "Went to I the store". ...However, I think that in some other languages, postfix notation is common. I think my friend who studies Spanish told me that they say the equivalent of "I her it gave" (meaning "I gave it to her"), and I think I remember Shakespearean English using postfix. ...Looking at the text of Romeo and Juliet, I see both prefix and postfix. Prefix: "O, where is Romeo? saw you him to-day?" Postfix: "The which if you with patient ears attend" On the one hand, we could say that, since these plays were apparently rather successful, people obviously didn't have too much trouble understanding them. On the other hand, since this sort of strange permutation has been mostly dropped from common usage (so that I recognize it as strange), that may be evidence that these things are just harder to use. On the other hand, that could just be because "common usage" comes mostly from people who have been educated in schools, and schools have no reason to teach more than one method of speaking. On the other hand, Shakespeare seems only to have done that in order to make lines fit into rhyming iambic pentameter; in no way was this natural to him. I should probably note that a lot of speech deals with object method calls more than function calls ("I.saw(Bob.win(a_game))" or, as it would probably be expressed in Arc, "(I!saw (Bob!win a-game))"; function call would be like (saw I (win Bob a-game))). And adjectives and adverbs act kind of like keyword arguments: (I!drove :to (the store) :[qualifier] fast). From that perspective, the distinction might be "object method calls" vs "function calls", rather than "infix" vs "prefix". Does someone who knows more than I about other human languages (or English, for that matter) know about the prevalence of postfix notation (and prefix, if it so happens)?
- silentbicycle 16y agoTurkish and Japanese both typically end sentences with verbs, IIRC. There are probably several others; I really should just buy a copy of Comrie's _The World's Major Languages_ already. In German (which I'm at least a little familiar with, unlike those two), auxiliary verbs stack at the end of the sentence: "I have eaten my breakfast." -> "Ich habe mein Frühstück gegessen." (lit. "I have my breakfast eaten.") It's unusual to have more than a couple, though - human languages typically don't nest very deeply. OTOH, comparing natural languages and programming languages may not be that useful - programming language design places a high priority on avoiding ambiguity, while natural languages assume have quite a bit of it. It may be better to consider programming languages as a kind of notation for math, logic, rules, instructions, declarations, etc. Kenneth Iverson had some interesting ideas about that. Another issue with method calls is that many things don't have a clear primary actor. In single-dispatch OOP languages, this turns into ugly workarounds (e.g. the Visitor pattern), "who owns this method?" debates, and tedious rewriting. Multimethods avoid that issue entirely.