Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

The LISP

Name: Anonymous 2010-10-12 9:18

Why is the function car not called first-of?

Why is the function cdr not called last-of?

Because.... post a comment with the answer, faggot.

Name: Anonymous 2010-10-12 9:25

you obviously haven't read your SICP today.

Name: Anonymous 2010-10-12 9:33

think of the as register names.  car, cbr, ccr, cdr

Name: Anonymous 2010-10-12 9:35

>>3
No. Think of them as the contents of register names.

Name: Anonymous 2010-10-12 9:39

car isn't first and cdr isn't last.

In Common Lisp, you have synonyms for car and cdr called first and rest.

car and cdr are just accessors (readable and writable, although this is CL specific) for the 2 fields of the cons structure. Chains of conses make lists (proper or improper). The end of a proper list is marked by a NIL (or also known as '(), the empty list), such that the cdr (cdr points to the /rest/ of the list, while car points to the current/top element of the list) of the last cons in the list is NIL. When you're using chains of conses as lists (and for all intents and purposes, you don't need to use car/cdr to access them at all - there are more specific functions for operating on lists), it might make sense to use first/rest synonyms instead of car/cdr, so that you would be more clear that you're working on lists and not on plain conses (which are nothing more than pairs of 2 values, and can be used as such, for representing all kinds of data which fit the bill).

Name: Anonymous 2010-10-12 9:40

Better names for these would be head and tail which would be derived from the metaphor of a snake: a snake is made up of a head and the rest of body being its tail.

Name: Anonymous 2010-10-12 10:07

>>6
No, you're just an idiot.

Name: Anonymous 2010-10-12 10:11

>>6
I get it! Snakes have no internal organs, so they are just a head attached to a tail.

Name: Anonymous 2010-10-12 10:12

>>5

Fair enough, thank you!

Name: Anonymous 2010-10-12 11:02

>>9
Does this look like experts-fucking-exchange to you?

Name: Anonymous 2010-10-12 11:19

Syntax error: found 'fucking', expected 'gender':
experts-fucking-exchange
        ^------------------ here.

Name: Anonymous 2010-10-12 11:28

>>6
Yeah, because (head a-pair) & (tail a-pair) makes a lot of sense.

Name: Anonymous 2010-10-12 11:45

>>12
Then "pair" is a misnomer. It should be called "snake".

Name: Anonymous 2010-10-12 11:51

NOTHING MAY SHOW VISIBLE SIGNS OF ITS HISTORY.

Name: Anonymous 2010-10-12 12:14

>>10
I always read that site as expert sexchange.

Name: Anonymous 2010-10-12 12:17

>>15
That's the joke in >>11. Also, they added a - in because everyone read it like that.

Name: Anonymous 2010-10-12 12:22

That's such a piece of shit website.

Name: Anonymous 2010-10-12 13:32

Out of curiosity, I found that this website actually does exist. http://expert-sexchange.com/

Name: Anonymous 2010-10-12 14:42

>>18
It's a lot better than the real one.

Name: Anonymous 2010-10-12 15:16

I was thinking, what's stopping a cons cell having an arbitrary number of cells? Apart from space and complexity, of course.

Name: Anonymous 2010-10-12 15:46

>>20
Its definition.

Name: Anonymous 2010-10-12 15:51

>>20
Just make your own structure that has as many fields as you like containing anything you want. If they had more fields, they'd be something else, and that would come with extra complexity and more code that needs to be written to accomodate that (for example, you could make a doubly linked list using a 3 field structure).

Name: Anonymous 2010-10-12 16:13

>>21
Well, yeah.
>>22
Anyway I was thinking some more and with an arbitrary number of cells, it just becomes arrays of arrays. A cons cell is as simple as possible and no simpler.
You could write a doubly-linked list with two conses per value, substituting cadr for previous and cddr for next.

Name: Anonymous 2010-10-12 16:25

>>20
vector

Name: Anonymous 2010-10-12 17:28

>>20
Lisps have had these in the past.

Name: Anonymous 2010-10-12 19:00

I'd like a three-way cons. The third value could be called z.

Name: Anonymous 2010-10-12 20:54

>>26
My other czar?

Name: Anonymous 2010-10-12 21:38

>>27
got overthrown

Name: Anonymous 2010-10-13 0:43

>>26
QUANTUM COMPUTING DETECTED

Name: Anonymous 2010-10-13 10:16

>>26
Generalize that shit, good sir, and you have my axe.

Or a vector.

Name: Anonymous 2010-10-13 11:57

To write less. Do you like Java? Me neither.

Name: Anonymous 2010-10-13 15:05

>>1
Because a cons cell is not really a list with first and last elements. west and east would have been better names.

Name: Anonymous 2010-10-13 18:22

>>32
cadr, cdar, caddr, and friends
weeast, eawest, weeaeast, etc...

Name: Anonymous 2010-10-13 18:24

>>32
Wouldn't it be a little awkward if the orientation of your computer changed program semantics?

Name: Anonymous 2010-10-13 18:36

>>34
All real programmers program facing Mecca.

Name: Anonymous 2010-10-13 18:38

>>35
but the position of Mecca is relative the programmer's location

Name: Anonymous 2010-10-13 18:59

>>35
Hello, Fouad Teniou.

Name: Anonymous 2010-10-13 21:09

>>37
*F.O.A.D. Teniou

Name: Anonymous 2010-10-13 21:11

>>38
No.

Name: Anonymous 2010-10-13 21:37

>>39
FOAD.

Name: Anonymous 2010-10-13 23:17

FIOC Teniou

Name: Anonymous 2010-10-13 23:39


public final class Cons {
    /** extensive javadoc omitted for brevity... */
    private Object car;
    private Object cdr;
    public Object getFirstElementOfList() { return car; }
    public Object getTailOfList() { return cdr; }
    public void setFirstElementOfListBang...

Name: Anonymous 2010-10-14 0:10

(defun (first car))
(defun (last cdr))

Name: Anonymous 2010-10-14 1:29

>>42
Terrible!

Name: Anonymous 2010-10-14 2:15

>>43
What do you call cdadr?

Name: Anonymous 2010-10-14 2:50

>>45
You have never used cdadr in your life.

Name: Anonymous 2010-10-14 3:56

>>45,45
(defun (last-of-first-of-last cdadr))

Name: Anonymous 2010-10-14 12:02

(= (first-of) car)

(= (last-of xs)
    (if (null? (cdr xs))
        (first-of xs)
        (last-of (cdr xs)))

Name: Anonymous 2010-10-14 12:57

>>48
Hello, Paul Graham

Name: Anonymous 2010-10-14 15:55

>>45
eaweeawest

Name: Anonymous 2010-10-14 15:57

my other west is a wdst

Name: Anonymous 2010-10-14 16:50

ConsGetter cadr = ConsGetterFactory.makeConsGetterFromXMLString("<!DOCTYPE consgetter PUBLIC \"-//LISP//DTD CONSGETTER 1.0\"  \"http://www.lisp.org/lisp/lisp/DTD/consgetter.dtd\">" +
        "<consgetter> <elementgetter> <element>cdr</element> <!-- get rest of elements --> </elementgetter> <elementgetter> <element>car</element> <!-- get first element --> </elementgetter> </consgetter>");

Object myObject = cadr.apply(myCons);

Name: Anonymous 2010-10-14 17:00

I just puked a little inside.

Name: Anonymous 2010-10-14 19:26

>>52
You should update your ConsGetterFactory to support generics.

Name: JLISP 2010-10-14 21:07

package java.util.lisp;

import java.lang.reflect.*;
import java.util.ArrayList;
import javax.script.*;

public class List {
    private Node head;
   
    public List(Object head) {
        this.head = new Node(head);
    }
   
    public Object car() {
        if (head == null)
            throw new IllegalStateException();
        else
            return head;
    }
   
    public List cdr() {
        Node newHead = new Node(this.head);
        Node prev, next, newPrev, newNext;
        for (    prev = this.head, next = this.head.next;
                next != null;
                prev = prev.next, next = next.next) {
            newPrev = new Node(prev.object);
            newNext = new Node(next.object);
            newPrev.next = newNext;
        }
        return new List(newHead);
    }
   
    public static Object eval(String expression) {
        try {
            return new ScriptEngineManager(List.class.getClassLoader()).getEngineFactories().get(0).getScriptEngine().eval(expression);
        } catch (ScriptException e) {
            e.printStackTrace();
            return null;
        }
    }
   
    public static void apply(Method method, List[] arguments) {
        try {
            method.invoke(null, (Object[]) arguments);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}

class Node {
    public Object object;
    public Node next;
   
    public Node(Object object) {
        this.object = object;
    }
}

Name: Anonymous 2011-02-04 17:13


Don't change these.
Name: Email:
Entire Thread Thread List