Live data from Hacker News

Not Lisp again (2009)

funcall.blogspot.com

81–90 of 276 posts

Re: Not Lisp again (2009)

#81
post #77

a lot of people handwave the parenthesis and prefix notation as something you get used to, but it really is the thing that I think most people can't get a handle on. There's a reason why DSPs and languages that look like a real languages are sought after - it makes conversion between business logic/requirements to code easier. It makes maintenance easier - it's easy to make sure you made the right changes when the ch…

What's DSP in this context?

I'm guessing he meant DSLs.

Re: Not Lisp again (2009)

#82

Earlier quoted context omitted.

Well, in 1992 (IIRC), I did a numerical integration in C. For a "first class function", it just took a function pointer. That approach would have been available in C in 1983...

That's not really the same thing at all. What's missing is the ability to close over values, which is a key part of first-class functions. You could not re-create the original example in C, which is to return a new function. You'd have to return some sort of object that keeps a reference to the function pointer, and provides a special mechanism for calling it, i.e. a poor man's closure.

Sigh. How soon they forgot. You create a thunk that provides the closure. Which used to be a common thing to do when you wrote C code.

Note: I'm not saying that C could express closures and first-class function objects anywhere near as neatly as Lisp. But the idea that only Lisp allowed you to use them, and C was the land of straightforward procedural code... does not represent what I saw back then.

Just as you can write FORTRAN code in any language, you can transfer ideas from other languages to C. What's great about Lisp is that it made the ideas easily accessible.

Re: Not Lisp again (2009)

#83
post #73

Earlier quoted context omitted.

Indeed, posts like this are of historical interest, but today, take Python: dx = 0.0001 def deriv(f): return lambda x: (f(x + dx) - f(x)) / dx This works just the same as the author's example and looks even more like the calculus formula people are used to.

f(x + dx) does look more conventional than (f (+ x dx)), but (/ numerator denominator) looks more like the conventional fraction syntax than putting a / somewhere in the middle of a line.

I'll give you that but also, ask 100 random people what "3/4" means and what "(/ 3 4)" means.

Re: Not Lisp again (2009)

#84
post #35

The objections the author had way back in the day are no longer the objections programmers of mainstream languages have to Lisp today. Today the objections I hear are more along the lines of: 1 - All those parenthesis. (Still a top objection) 2 - Lisp doesn't look like or work like what I'm used to. 3 - Lisp doesn't have as many libraries as the most popular mainstream programming languages. 4 - There aren't nearly a…

I guess the stuff about parentheses that's highly confusing in Lisp is that x is different from (x). Outside of that, it's just ordinary grouping.

In JavaScript it's confusing that these are different:

  function(x) { return x; }
  function(x) { return x; }()
To reduce confusion, JavaScript programmers follow the Lisp convention and put parens around expressions like the latter. Once you take the 5 minutes needed to get used to the difference between x and (x) it's actually less confusing than popular alternatives.

Re: Not Lisp again (2009)

#85

Earlier quoted context omitted.

That's not really the same thing at all. What's missing is the ability to close over values, which is a key part of first-class functions. You could not re-create the original example in C, which is to return a new function. You'd have to return some sort of object that keeps a reference to the function pointer, and provides a special mechanism for calling it, i.e. a poor man's closure.

> What's missing is the ability to close over values, which is a key part of first-class functions. This is not true. You can have first-class function which are not closures: every dynamically-scoped Lisp works that way, see Emacs Lisp without `lexical-binding: t` and the `lexical-let` implementation.

And the derivatives example will not work, because it needs to close over the variable f.

    (setq dx .0001)

    (defun deriv (f)
      (lambda (x)
	  (/ (- (funcall f (+ x dx)) (funcall f x))
	     dx)))

    (defun cube (x) (* x x x))

    (setq cube-deriv (deriv #'cube))

    (funcall cube-deriv 2)
    Error: Symbol's value as variable is void: f
Setting lexical-binding to t, so that deriv returns a closure, fixes the problem.

Re: Not Lisp again (2009)

#86
post #66

Earlier quoted context omitted.

Learning lisp or functional programming is more of a conceptual experience than a practical one. That is not to say it is not practical to learn lisp, but the state of the programming world as it is today makes it so that it is less practical to learn lisp than it is to learn about say something like java.

If you ever have to write JavaScript, a fairly practical and widespread language, the functional paradigm proves to be highly useful.

But luckily in newer versions, sane features like modules are introduced that are syntactic sugar over the trick with closures that have to be used to fake them. And things like Promises instead of passing callback functions everywhere.

The functional paradigm in Javascript is used everywhere because that's all there was.

Re: Not Lisp again (2009)

#87

a lot of people handwave the parenthesis and prefix notation as something you get used to, but it really is the thing that I think most people can't get a handle on. There's a reason why DSPs and languages that look like a real languages are sought after - it makes conversion between business logic/requirements to code easier. It makes maintenance easier - it's easy to make sure you made the right changes when the ch…

On the contrary, people not only get used to paren prefix notation, they quickly master it.

Mastering operator precedence in your typical infix language is harder.

Re: Not Lisp again (2009)

#88
post #17

The objections the author had way back in the day are no longer the objections programmers of mainstream languages have to Lisp today. Today the objections I hear are more along the lines of: 1 - All those parenthesis. (Still a top objection) 2 - Lisp doesn't look like or work like what I'm used to. 3 - Lisp doesn't have as many libraries as the most popular mainstream programming languages. 4 - There aren't nearly a…

For me it's not the paranthesis, but that Lisp posts always show low level code. At least half of my programming is tying together high level services and libraries. I know how I can express those concepts succinctly in Java, C++, JS, Swift etc. I'd love to see some examples of Lisp for something like a REST controller, where I call services, repositories etc.

> At least half of my programming is tying together high level services and libraries. I know how I can express those concepts succinctly in Java, C++, JS, Swift etc. I'd love to see some examples of Lisp for something like a REST controller, where I call services, repositories etc.

You should look at Racket. Racket is a Scheme-like[0] Lisp that aims to be "batteries-included". It includes things like a web-server out-of-the-box.

[0] it is technically a hybrid of R5RS and R6RS, so pedants can argue over whether it is really "a Scheme" or not.

Re: Not Lisp again (2009)

#89
The real power of this isn't just differentiating a given function; as others have pointed out, you can do this in, e.g., C with function pointers. Having first-class procedures and closures means you can actually return the derivative as a function. This lets you do things that the simple example doesn't show. For a physics example, see https://mitpress.mit.edu/sites/default/files/titles/content/... : given a Hamiltonian (generalized energy) describing a mechanical system, you can automatically construct a function that computes the associated Hamiltonian vector field. Pass the vector field and an initial condition into a numerical integrator, and out pops the trajectory.

Re: Not Lisp again (2009)

#90
post #57

Earlier quoted context omitted.

Yeah, this seems to be a common objection, but in my experience of actually having used a lisp (Clojure) in production, this was never a problem. Sure, you'll likely still end up with some technical debt, but no more than the Java project's we had at the same company. And not because of macros. When people first learn about macros, they go crazy trying to do all kinds of things that weren't possible without macros. B…

Clojure has a BDFL (Rich Hickey) and it lacks reader macros. It's kind of the exception that proves the rule.

To be fair, though, the macro-based River of Insanity newbie Lispers sometimes travel down is rarely based on reader macros.
Post reply on HN