Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The problem with using objects and structs in Common Lisp is the verbosity of access, or of setting up shorter access using with-slots and with-accessors.

I fixed that in TXR Lisp:

  (defun time-to-move (from-pos to-pos)
     (max (time-to-rotate from-pos.azimuth to-pos.azimuth)
          (time-to-ascend from-pos.elevation to-pos.elevation)))
The remaining issues are self-inflicted verbose naming. I would make it

  ;; time to move
  (defun ttm (p0 p1)
    (max (ttr p0.az p1.az)
         (tta p0.el p1.el)))

If the entire program fits on a few pages, you can remember a few abbreviations.

The dot notation is a syntactic sugar for certain S-exps:

  a.b.(c x y).d   ->   (qref a b (c x y) d)

  .a.b.c          ->   (uref a b c)
there exist macros by these names which take care of the rest.

Starting in TXR 300, there can be whitespace after the dot. So while you cannot write in in the popular way:

  obj
  .(meth arg)
  .(next-meth 42)
you can do it like this:

  obj.
  (meth arg).
  (next-meth 42)
this has a lot do with Lisp already having a consing dot.

Lisp doesn't mean being against all syntactic sugars; e.g. we mostly write 'X rather than (quote 'X).

But note that even if we don't have this notation, how the author has tripped over himself to create verbosity. After two nestings of with-accessors he ends up with:

  (time-to-rotate from-az to-az) (time-to-ascend from-el to-el)
Here from-az is not a whole lot shorter than (az from)! If he used shorter names like el and az, he would have:

  (defun time-to-move (from to)
    (max (time-to-rotate (az p0) (az p1))
         (time-to-ascend (el p0) (el l1))))
Don't make names for yourself that you then have to shorten with clumsy macros that make the function longer overall.

Another thing is, why does time-to-move take two objects? But time-to-rotate and time-to-ascend work with destructured azimuths and elevations?

  (defun time-to-move (from to)
    (max (time-to-rotate from to)
         (time-to-ascend from to)))
Time to rote and time to ascend could be inseparable. If the device is mounted on an incline, the time to ascend may depend on the azimuth. It may be better to rotate it first than elevate or vice versa, or execute some optimal combined motion.

The moment of inertia of the thing may depend on its elevation; it may be easier to rotate in a high elevation. So just time-to-rotate alone needs the whole object.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: