Hacker News new | ask | show | jobs
by e12e 2437 days ago
Am I reading that right, that:

  (2 '(a b c))
Is equivalent to:

  (second '(a b c))
And that would work for strings as well:

  (5 "Hello, world!")
  > "o"
Which in turn means 'car and' 1 are equivalent? (probably means 'car should be thrown out, because surely '1 is clearer?

Ed: and with some notation to differenciate "element at N" and "tail behind N" you could get even more mileage out of integers? And then to generalize to lists of lists to reference elements and sub-sections (sub dimensions, like cubes) of matrices?

Not sure what would be nice, perhaps star or ellipsis?

  (1... '(a b c))
  >'(b c)

  ('(1..) '(0..2)
    '(
      (a b c)
      (d e f))
  >'(
    (b c)
    (d f))
Or something?
1 comments

It would not be clearer to use 1 instead of car when you were using a pair to represent a tree, rather than a list, and you were traversing the left and right branches using car and cdr.
Yes, I suppose that's something I've never grown quite used to with lisp - that it's lists (as a special form of "leaning" trees) and trees - not arrays and matrices.

I suppose even proper lists are incidental - it's really all about trees (and also parse trees).