Live data from Hacker News

Lisp after Python after Lisp

devlog.bigmonachus.org

11–18 of 18 posts

Re: Lisp after Python after Lisp

#11

Learning Scheme helped my Python by teaching me some new (to me) idioms, besides the first-class function stuff. For example, it is natural in Scheme to declare a lot of local information, including local function definitions. These have the great advantage of knowing about variables within the local environment. So rather than declaring an external function with heaps of parameters to pass in local state, you just d…

Instead of declaring a local function, you can use let (http://docs.plt-scheme.org/reference/let.html)

e.g.:

  > (let fac ([n 10])
      (if (zero? n)
          1
          (* n (fac (sub1 n)))))

  3628800

Re: Lisp after Python after Lisp

#12

Learning Scheme helped my Python by teaching me some new (to me) idioms, besides the first-class function stuff. For example, it is natural in Scheme to declare a lot of local information, including local function definitions. These have the great advantage of knowing about variables within the local environment. So rather than declaring an external function with heaps of parameters to pass in local state, you just d…

Instead of declaring a local function, you can use let ( http://docs.plt-scheme.org/reference/let.html ) e.g.: > (let fac ([n 10]) (if (zero? n) 1 (* n (fac (sub1 n))))) 3628800

Yes, "named let" is lovely, but perhaps less obvious for the non-cognoscenti. It also doesn't translate into Python, etc.

Re: Lisp after Python after Lisp

#13

Learning Scheme helped my Python by teaching me some new (to me) idioms, besides the first-class function stuff. For example, it is natural in Scheme to declare a lot of local information, including local function definitions. These have the great advantage of knowing about variables within the local environment. So rather than declaring an external function with heaps of parameters to pass in local state, you just d…

What do you mean by this? Is this the same method of declaring inner functions within the scope of the outer function?

Re: Lisp after Python after Lisp

#14

Learning Scheme helped my Python by teaching me some new (to me) idioms, besides the first-class function stuff. For example, it is natural in Scheme to declare a lot of local information, including local function definitions. These have the great advantage of knowing about variables within the local environment. So rather than declaring an external function with heaps of parameters to pass in local state, you just d…

What do you mean by this? Is this the same method of declaring inner functions within the scope of the outer function?

Pretty much. The trick is that since scheme is a lisp-1 there is no need for a different special operator to signify you're declaring a local function instead of a local variable (a la the flet/let dichotomy).

Re: Lisp after Python after Lisp

#15

Learning Scheme helped my Python by teaching me some new (to me) idioms, besides the first-class function stuff. For example, it is natural in Scheme to declare a lot of local information, including local function definitions. These have the great advantage of knowing about variables within the local environment. So rather than declaring an external function with heaps of parameters to pass in local state, you just d…

What do you mean by this? Is this the same method of declaring inner functions within the scope of the outer function?

Yes, in that case the inner function has access to the arguments of the outer function. But you can go deeper -- e.g. declaring an inner function inside code inside the out er function -- which also knows about the local variables in the outer function.

Or if you're only doing it once use a lambda (with the same advantages).

Re: Lisp after Python after Lisp

#16

Earlier quoted context omitted.

What do you mean by this? Is this the same method of declaring inner functions within the scope of the outer function?

Yes, in that case the inner function has access to the arguments of the outer function. But you can go deeper -- e.g. declaring an inner function inside code inside the out er function -- which also knows about the local variables in the outer function. Or if you're only doing it once use a lambda (with the same advantages).

Isn't this how you use closures? I think I've been doing this with my javascript code without even noticing it. :-)

Re: Lisp after Python after Lisp

#17

Earlier quoted context omitted.

Yes, in that case the inner function has access to the arguments of the outer function. But you can go deeper -- e.g. declaring an inner function inside code inside the out er function -- which also knows about the local variables in the outer function. Or if you're only doing it once use a lambda (with the same advantages).

Isn't this how you use closures? I think I've been doing this with my javascript code without even noticing it. :-)

Yes, these idioms would work in Javascript too.

I guess the point is that people are starting to discover that languages like Python and JS support these functional idioms quite nicely.

Remember when all the books on JS pretended that it was some kind of crippled cousin of Java (as the name suggests), rather than a Scheme-lite in Java-esque syntax (as its designer has opined).

Re: Lisp after Python after Lisp

#18

Earlier quoted context omitted.

Isn't this how you use closures? I think I've been doing this with my javascript code without even noticing it. :-)

Yes, these idioms would work in Javascript too. I guess the point is that people are starting to discover that languages like Python and JS support these functional idioms quite nicely. Remember when all the books on JS pretended that it was some kind of crippled cousin of Java (as the name suggests), rather than a Scheme-lite in Java-esque syntax (as its designer has opined).

Haha yes, I do remember those times. Now that you've mentioned it another language that fits the description of a Scheme-lite in Java-esque syntax is Lua.
Post reply on HN