6 ms·
JavaScript = C + Lisp
- PieSquared 18y agoAye, but minus the low level features of C and the high level features of Lisp. Like pointer and memory manipulation and macros. Still, it can be a very nice language, I just wouldn't say it is "C + Lisp". Also I'm not sure what the article had to do with either Lisp or C, it seemed more like a discussion of haskell... Am I missing something? Edit: I'm still confused. Anyone want to take a better shot at explaining what a monad is? Or, more precisely, what's so special about it that it deserves a special name?
- maw 18y agoA monad is a means by which people who are pedantically attached to the notion of pure functional programming can write programs that /actually do something/ while still claiming that they're functional.
- silentbicycle 18y agoA monad is a kind of control structure between functions. Kind of like if you could overload add extra hook functionality to the Unix shell pipe, besides just piping stuff along. For instance, seed it with a countdown, and every time stuff is piped to another process, see how much time has elapsed; if at any point it's been more than, say, 30 seconds, just stop the whole series and return an error. Or find a path through a maze by backtracking every time it hits a dead end, returning to the most recent unexplored path. They're a necessary workaround to do some stuff in pure functional languages (which is why Haskell users make such a big deal out of them), but you can do some really cool tricks with them. (NB: This is a really vague summary. I found this OCaml-based monad intro helpful, because it mostly avoids entangling the monad concepts with unrelated issues in Haskell. http://enfranchisedmind.com/blog/2007/08/06/a-monad-tutorial-for-ocaml/ http://enfranchisedmind.com/blog/2007/08/06/a-monad-tutorial... There's a good Monads-in-Scheme intro, too, I forget where.)
- procrastitron 18y ago"They're a necessary workaround to do some stuff in pure functional languages" This isn't actually true. You can still write imperative programs in a pure FP language. The most obvious way is to write your code in continuation passing style and pass the new state of the world to each continuation; taking the implicit state changes of an imperative language and making them explicit. The real reason for using monads is that the scheme I just described is inhumanly complicated. Monads are a much more structured way of doing the same thing. Instead of writing these state passing CPS functions, you write functions that build them for you. A consequence of this is that monads perform much the same function as macros in Lisp; they are programs that build programs.
- silentbicycle 18y agoAgreed. I guess I should have added, "without making things unnecessarily complicated.". I think that monads, too, are generally presented in a way that makes them more complicated than they really are. (Hence, I suppose, SPJ's comment about how they should have been called "warm fuzzy things".) Part of my trouble understanding them confronting the basics of Haskell at the same time, and I (along with much of what I read) focused on the IO monad. That's probably one of the most complicated ones. The ideas started to click when I switched to the Maybe monad -- not only is that one considerably more straightforward, but I (and probably many others) had already written essentially the same construct elsewhere, albeit without the formal notation.
- deleted 18y ago[deleted]
- SamReidHughes 18y agoMonad is the name for an algebraic structure, the same way that 'field' and 'group' and 'monoid' and 'integral domain' and 'vector space' are names for algebraic structures. In particular it's useful for actions. It has only two functions, 'return' and '>>=': (return x) -- an action that returns the value x (a >>= f) -- the action produced by attaching the -- continuation f to the action a It is the algebraic structure of attaching continuations to things.
- smanek 18y agoAs my old boss used to say: "JavaScript is my favorite language with curly braces" (we were lispers)
- martinflack 18y agoJavaScript = subset(C) + subset(Lisp)
- cheponis 18y agoMore like SyntaxOf(C) + subset(Lisp)
- SwellJoe 18y agoNot really news, is it? Brendan Eich himself has said that he wanted to use Scheme as the embedded language in the browser, but the higher ups thought people would be frightened off by all the parentheses. So, he sneakily implemented Scheme with C-style syntax and nobody seemed to notice for a few years.
- jsmcgd 18y agoImagine how different the programming landscape would look if he had stuck to his guns. We can but dream ...
- SwellJoe 18y agoYou reckon he didn't stick to his guns? I think he did alright for a relatively junior level developer, a lone developer to boot, given the task of "add scripting to the browser". I can imagine far worse fates, particularly given how enamored of Java the entire industry was at the time. I have nothing but respect for Eich and JavaScript. It's held up strikingly well for what could have been, and odds were in favor of it being, a band aid solution. Given the circumstances, I think we're just lucky that Netscape had some of the best developers in the world working on it at that time...because the one who got stuck adding "scripting" happened to be quite gifted and ambitious, and took the task very seriously and came up with something quite clever. It was a very different time, and dynamic languages were a bit downtrodden. Tcl was the closest to a "standard embedded scripting language" and I think I'm comfortable calling JavaScript a more powerful language than Tcl (at least at the time, though I think the two have stayed the same related to one another over that time, despite advances in both). And, of course, Tcl was only popular among UNIX nerds. Getting Windows developers on board might have been a problem...a whole new "simple" language like JavaScript may have been exactly what the industry needed. I dunno. It's certainly apparent that JavaScript has revealed itself to be a very powerful language in the past few years.
- jsmcgd 18y agoDon't get me wrong, I'm a big fan of Javascript. I'm just saddened that we didn't get a complete Scheme. Things like, for example, metaprogramming are massively helpful when interacting with HTML. Collectively we all might have had a lot less work to do.
- d0mine 18y agoJust a side note: acceptOnlyIf name doesn't tell what the function does. acceptEach or acceptAll could be a clearer alternatives (at least for a python programmer (there are any() and all() general functions in Python)).
- volida 18y agojavascript is javascript, i don't see the need to say it's C with Lisp...