Hacker News new | past | comments | ask | show | jobs | submit login

You need a linked list to write hello world in any Lisp, though.

Seems like the glaring exception to the rule!




As source code, but not necessarily as running code.

SBCL:

    * (defun hello-world () (write-string "hello world"))
    HELLO-WORLD

    * (disassemble #'hello-world)
    ; disassembly for HELLO-WORLD
    ; Size: 36 bytes. Origin: #x100311C85C                        ; HELLO-WORLD
    ; 5C:       AA0A40F9         LDR R0, [THREAD, #16]            ; binding-stack-pointer
    ; 60:       4A0B00F9         STR R0, [CFP, #16]
    ; 64:       EAFDFF58         LDR R0, #x100311C820             ; "hello world"
    ; 68:       570080D2         MOVZ NARGS, #2
    ; 6C:       29EC80D2         MOVZ TMP, #1889
    ; 70:       BE6B69F8         LDR LR, [NULL, TMP]              ; WRITE-STRING
    ; 74:       DE130091         ADD LR, LR, #4
    ; 78:       C0031FD6         BR LR
    ; 7C:       E00120D4         BRK #15                          ; Invalid argument count trap
The actual code for this example is machine code (which references a string, which is a vector), here without linked lists.


No, you don't need to use linked lists to send a string to the standard output port in most Lisps. You just call a function.


(write-string "hello world") has linked list semantics, the fact that compilers can be smart enough to ignore this is not the point I'm making.

(write-string (cdr '(write-string "hello-world"))) also has to work, so it's pretty easy to materialize that semantics at any point.


> has linked list semantics

Nope; it has linked list syntax (that certainly isn't ignored even by very good compilers). Syntax isn't semantics.

The semantics is that a function write-string is called, with a string as its argument.

The second expression has linked list processing in its semantics because you stuck in a cdr, as well as a quote which makes a piece of the program available as run-time list datum. (This is semantics that could be easily optimized away in the executable form, but I would say that it has linked list processing in its abstract semantics.)


> Nope; it has linked list syntax (that certainly isn't ignored even by very good compilers)

We're looking at the same string and seeing different things. You're seeing `(write-string "hello world")` as a program, I'm seeing it as an expression.

It has linked list semantics, which you can preserve until runtime like this `'(write-string "hello world")`. Note that I didn't change the string, I changed its context. If the original were living in a string, and you called read on it, it would become a linked list. If you called eval on that list, it would become a function call. This is basic stuff which I'm well aware you know, so I'm not sure what all the quibbling is about.

You literally need a linked list to write a program in a language in which the code becomes linked lists. And you're going to have a bad time writing Lisp if you don't get the hang of cons cells, early and often.

Is "code is data" true, or false? You're trying to have it both ways here.

The "large number of programmers who have learned about linked lists but haven't run into many cases where they needed them in the world world" include approximately zero programmers who have wielded Lisp in anger, is my point. I thought that was pretty clear from context, but I guess not.


The compiler manipulating linked lists to get your program into executable form, versus that program manipulating linked lists to do its job, are different things.

You're also likely provoking list manipulation by running C hello world. The C grammar has lists, like lists of parameter declarators in a function, or argument expressions in a function call.

By the time you've compiled your C program, you've likely "used", lists, trees and hash tables.

Classic line-numbered BASIC interpreters stored the lines as a linked list. For instance in

  10 PRINT "Hello"
  20 GOTO 10
the 10 line is stored as a datum which has a pointer to the 20. Some BASIC implementations implemented a forward GOTO as a linear search through the linked list starting at the current line, and a backwards GOTO as a scan from the beginning.

So in addition to not being able to write C hello without linked lists, the same holds for BASIC.

The way you present your idea about Lisp is harmful because it is likely to be misinterpreted and become misinformation in the eyes of those who not so well informed.

The Lisp community still has to deal with nonsense like that the execution of Lisp programs is slow because linked lists are continuously being traversed, or that the only data structure is a list.

Think about how you might be playing into that. What do you think it looks like when you say that you can't write a hello world, without using linked lists.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: