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

This one seems backwards to me:

    (2 '(a b c))
In addition to being data structures, I like to think of lists/arrays as functions which map integers to the contents. This nicely generalizes to hash tables / associative arrays, and then further to actual functions. If that's all reasonable, then

    ('(a b c) 2)
is the right order for application.

However, maybe pg is just thinking of 2 as a shorthand for cadr or similar.




Initially I would have preferred that. I did it that way in Arc. But since functions are lists in Bel, I couldn't do that, or you wouldn't be able to call a function on a number.

As often happened with things I was forced into, though, I not only got used to putting numbers first but started to prefer it. It means for example you can compose them with other callable things.


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?


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).


It seems to be borrowing from clojure, in which both (field container) and (container field) do the same thing.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: