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

Pages: 1-

(A) = A, or the other way to Lisp

Name: Anonymous 2011-06-25 12:00

Treating list of single element as the element itself means that, if (atom A) => T, then following axioms hold

  (car A) => A
  (cdr A) => nil
  (cons B A) => (B A)


This approach can conceptually simplify list processing, because everything becomes a list. Most list-functions would get ability to process single elements. A need for a few redundant helper entities, like unicode characters, would disappear, as they could be represented with the list itself. Lists could be entered and pretty-printed by just specifying their elements, without parentheses, required to discern single element from a list of single element.

The obvious pitfall is that "(list)" results into just "list", meaning that some other way to discern symbols from funcalls has to be found. One variant is to use naming convention for function symbols - for example, starting them from lowercase letter.

Problems will arise from removal of (atom A) => T requirement. For example,

  (car (car (cons (cons A B) nil)))

would result in A, instead of (A B), because of loss of structure.

Still, (car (car A)) works as expected, when (atom A) => T.

Name: Anonymous 2011-06-25 12:02

(A) = A

Stopped readicannot construct infinite typ*** Exception: stack overflow

Name: Anonymous 2011-06-25 12:05

>>2
Haskell cannot into recursive types?

Name: Anonymous 2011-06-25 12:15

>>1
That's as pointless as (car nil) => nil and (cdr nil) => nil.

I can't think of any advantage of doing this. Maybe map and folds now working on atoms, which just results in function application.

Name: Anonymous 2011-06-25 12:25

>>4
, because everything becomes a list. Most list-functions would get ability to process single elements. A need for a few redundant helper entities, like unicode characters, would disappear, as they could be represented with the list itself. Lists could be entered and pretty-printed by just specifying their elements, without parentheses, required to discern single element from a list of single element.

Name: Anonymous 2011-06-25 12:37

(cdr nil) => nil
wouldn't this be dereferencing a null pointer?

Name: Anonymous 2011-06-25 12:45

Forgot about lower memory consumption for lists of single element.

Name: Anonymous 2011-06-25 12:59

>>6
Not if nil is a special (different tag) cons of nil and nil.

Name: Anonymous 2011-06-25 13:27

>>6
Lisp does not have filthy NullPointerExceptions!

Name: Anonymous 2011-06-25 13:30


   ( ・∀・)   | | ガッ
  と    )    | |
    Y /ノ    人
     / )    <  >__Λ∩
   _/し' //. V`Д´)/ ←>>9
  (_フ彡        /

Name: Anonymous 2011-06-25 16:55

SRFI 1 makes the point that every non-pair, non-null object is an improper list of length 0. See http://srfi.schemers.org/srfi-1/srfi-1-reference.scm "A note on dotted lists".

It reminds me of tuples in ML. They are kind of neat at first but the missing one-tuple gets annoying fast.

It also reminds me of Python strings.
'hello'[0] == 'h'
'h'[0] == 'h'
'hello'[0][0] == 'h'

This is of course retarded but it can easily be ignored.

Name: Anonymous 2011-06-25 17:38


(defun /car (x) (if (consp x) (car x) x))
(defun /cdr (x) (if (consp x) (cdr x)))
(defun /cons (x y) (cond ((consp y) (cons x y))
                         ((null y) (if (consp x) (cons x nil) x))
                         (t (cons x (cons y nil)))))
(defun /list-rec (xs) (if xs (/cons (car xs) (/list-rec (cdr xs)))))
(defun /list (&rest xs) (/list-rec xs))
(defun /print (x)
  (unless (consp x) (setf x (list x)))
  (format t "~{~a~^ ~}" x))

Name: Anonymous 2011-06-25 18:23

>>11

Are you trying to do "hello".startswith('h')?

Name: Anonymous 2011-06-26 3:44

>>11
SRFI 1 makes the point that every non-pair, non-null object is an improper list
This lowers memory usage, as (cons 1 2) results into (list 1 2), meaning you can completly replace CONS with LIST.

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