Skip to content

Commit

Permalink
[#200] Define setters for -first-item and -last-item
Browse files Browse the repository at this point in the history
  • Loading branch information
Matus Goljer committed Nov 8, 2016
1 parent 53e641c commit bcc74b5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dash.el
Expand Up @@ -578,11 +578,15 @@ Alias: `-any'"
\(fn LIST)")

(gv-define-simple-setter -first-item setcar)

(defun -last-item (list)
"Return the last item of LIST, or nil on an empty list."
(declare (pure t) (side-effect-free t))
(car (last list)))

(gv-define-setter -last-item (val x) `(setcar (last ,x) ,val))

(defun -butlast (list)
"Return a list of all items in list except for the last."
;; no alias as we don't want magic optional argument
Expand Down

6 comments on commit bcc74b5

@Wilfred
Copy link
Contributor

@Wilfred Wilfred commented on bcc74b5 Nov 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

@Wilfred
Copy link
Contributor

@Wilfred Wilfred commented on bcc74b5 Nov 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, looks like this doesn't work on Emacs 23 -- it's broken the tests.

@Fuco1
Copy link
Collaborator

@Fuco1 Fuco1 commented on bcc74b5 Nov 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I've noticed too :( Do you know a fix? Apparently gv did not exist back then. But it's not a big deal as we'll be dropping emacs 23 tests soon (as per #195)

@Wilfred
Copy link
Contributor

@Wilfred Wilfred commented on bcc74b5 Nov 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there was equivalent functionality in Emacs 23, which we could use. Alternatively, why not just wrap in a (when (boundp 'gv-define-setter') ...) and treat this as an extra feature for recent Emacsen?

@Fuco1
Copy link
Collaborator

@Fuco1 Fuco1 commented on bcc74b5 Nov 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we would also need to guard tests and there it can be messy. If you know how to make this work in e23 I'd rather have that added.

@Wilfred
Copy link
Contributor

@Wilfred Wilfred commented on bcc74b5 Nov 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's define-setf-expander on Emacs 23 (which works on recent Emacsen too), or defsetf. I'm struggling: Emacs 23 segfaults during compile on my Arch Linux box, and the EVM binaries depend on versions of libtinfo which aren't compatible with Arch Linux's default ncurses install.

IIUC, I think this could be written:

(defsetf -last-item (lst) (v) `(setcar (last ,lst) ,v))

Please sign in to comment.