Live data from Hacker News

Ask HN: Is Lisp Simple?

news.ycombinator.com

11–18 of 18 posts

Re: Ask HN: Is Lisp Simple?

#11
post #2

The loop macro is an interesting example as its pretty much a mini language within Lisp just for looping purposes that doesn't use the normal s-expression based syntax - which is either a bad thing or a great example of how powerful Lisp can be... Personally, when I used to write Common Lisp for a living (a long long time ago) I was very fond of loop. As for "it's all just lists" - Common Lisp directly supports a var…

CLOS looks really interesting. So many good ideas. A lot that I have been thinking about for a while.

https://lispcookbook.github.io/cl-cookbook/clos.html:

> arguably one of the most powerful object systems available in any language.

https://en.wikipedia.org/wiki/Common_Lisp_Object_System:

> Another unusual feature is that methods do not "belong" to classes; classes do not provide a namespace for generic functions or methods. Methods are defined separately from classes, and they have no special access (e.g. "this", "self", or "protected") to class slots.

Love this.

And the multiple dispatch.

> :before, :after, and :around

Guess these are similar to aspect-oriented programming. Maybe useful for plugin systems.

> change-class

This looks pretty cool for GUI apps. So many times you want to change a component to something else.

Re: Ask HN: Is Lisp Simple?

#12
post #9
post #4

> I thought everything was suppose to be like: `(left . (left . right) )`. Could be, but you don't need the "." (or the list as so-called "cons pairs"). (a b c ...) is enough. > It seems as if there are actually a ton more special case primitives I need to know You need to know a handful of special forms like and, cond, let etc (corresponding roughly to keywords in other languages). Everything uses those with the sam…

(quote a b c) does not exist in Lisp. QUOTE takes exactly one argument, the object to quote. It's a special operator . '(a b c) is (quote (a b c)) > defun = special form DEFUN is not really a form in the standard. It's a operator. It's even not a special operator. It's a macro operator. A form is something meant to be evaluated. One could evaluate the symbol DEFUN, but by default it has no value.

So are these "specials" being parsed by a grammar?

Would be interesting to see how the interpreter works actually...

I would guess it checks what `defun` is, which is a macro...then expands it, and the expansion should ultimately result in an s-expression, which is then parses? Is this right?

Re: Ask HN: Is Lisp Simple?

#13
> it's all just lists. Yes, Lisp code is made up of lists.

> But it seems like there are so many special constructs and macros, that make it hard to read.

> (loop for i in '(1 2 3)

Common Lisp is a "programmable programming language" meaning that it's possible to make macros like the loop macro that aren't even what many consider "Lispy" - lots of people who otherwise like Common Lisp dislike the loop macro. But, it's a good example of a DSL and how far you can go with making one. Of course, there are other ways to do iteration besides loop, both standard built-in forms such as do or dolist, and even 3rd party libraries like series or iterate.

Also, when macros are expanded they resolve to lists - even the loop macro.

OTOH, something like MIT Scheme which was used in SICP is a much simpler Lisp compared to CL.

Re: Ask HN: Is Lisp Simple?

#14
> (defun (list of arguments) > "docstring" > (function body))

> How do I read this as an s-expression?

It's still a list.

You can re-write it as:

    (let ((my-list '(defun  (list of arguments) "docstring" (function body))))
     (print (first my-list))
     (print (second my-list))
     (print (third my-list))
     (print (fourth my-list)))
It will print:

    DEFUN
    
    (LIST OF ARGUMENTS)
    "docstring"
If "docstring" appears twice when you run the above, that's because it's the value produced by the final form in the block, so it shows up as the return value of the block.

Re: Ask HN: Is Lisp Simple?

#15
post #12
post #9

Earlier quoted context omitted.

(quote a b c) does not exist in Lisp. QUOTE takes exactly one argument, the object to quote. It's a special operator . '(a b c) is (quote (a b c)) > defun = special form DEFUN is not really a form in the standard. It's a operator. It's even not a special operator. It's a macro operator. A form is something meant to be evaluated. One could evaluate the symbol DEFUN, but by default it has no value.

So are these "specials" being parsed by a grammar? Would be interesting to see how the interpreter works actually... I would guess it checks what `defun` is, which is a macro...then expands it, and the expansion should ultimately result in an s-expression, which is then parses? Is this right?

>Would be interesting to see how the interpreter works actually...

It's quite easy to see, there are interpeters for Lisp in like 20 lines or so.

Here's a good one:

https://norvig.com/lispy.html

(It has the full code in a link towards the bottom)

There's also this:

https://github.com/kanaka/mal

> I would guess it checks what `defun` is, which is a macro...then expands it, and the expansion should ultimately result in an s-expression, which is then parses? Is this right?

Yes, but macros (like special forms, but macros can be user implementable) have some "special" powers regarding controlling the evaluation of the code they produce.

Here's some more discussion with examples:

https://stackoverflow.com/questions/42470940/how-is-the-defu...

Re: Ask HN: Is Lisp Simple?

#16
> I thought Lisp was suppose to be simple in that: it's all just lists.

"Lisp is simple" is mainly an ignorant meme that is used to belittle the interests of people who work in, or on, some kind of Lisp. There are simple aspects, but the aspects are numerous and the combination is complex.

Lisp has kept bright minds busy for sixty years and continues to do so.

Making a production Lisp from scratch is a pretty big undertaking.

Re: Ask HN: Is Lisp Simple?

#17
post #12
post #9

Earlier quoted context omitted.

(quote a b c) does not exist in Lisp. QUOTE takes exactly one argument, the object to quote. It's a special operator . '(a b c) is (quote (a b c)) > defun = special form DEFUN is not really a form in the standard. It's a operator. It's even not a special operator. It's a macro operator. A form is something meant to be evaluated. One could evaluate the symbol DEFUN, but by default it has no value.

So are these "specials" being parsed by a grammar? Would be interesting to see how the interpreter works actually... I would guess it checks what `defun` is, which is a macro...then expands it, and the expansion should ultimately result in an s-expression, which is then parses? Is this right?

(defun foo (a) (+ a 1)) is a s-expression. For evaluation Lisp expands the DEFUN macro then and this returns a new s-expression. Which then is evaluated.

> So are these "specials" being parsed by a grammar?

Every special operator (and there are only a limited amount and this is not user extensible) needs to be implemented by a Lisp source interpreter or a Lisp compiler. Other tools like a code walker also need to know the syntax.

Re: Ask HN: Is Lisp Simple?

#18
post #15
post #12

Earlier quoted context omitted.

So are these "specials" being parsed by a grammar? Would be interesting to see how the interpreter works actually... I would guess it checks what `defun` is, which is a macro...then expands it, and the expansion should ultimately result in an s-expression, which is then parses? Is this right?

> Would be interesting to see how the interpreter works actually... It's quite easy to see, there are interpeters for Lisp in like 20 lines or so. Here's a good one: https://norvig.com/lispy.html (It has the full code in a link towards the bottom) There's also this: https://github.com/kanaka/mal > I would guess it checks what `defun` is, which is a macro...then expands it, and the expansion should ultimately result i…

Thanks! Lisp is so damn cool.
Post reply on HN