-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"inc" naming #7
Comments
Sounds like a good idea to me. We were following Clojure here, but Common Lisp's interpretation makes more sense to me. |
Actually, if we do that, perhaps we should use Common Lisp's names, |
Eh, Another option would be to not have mutative increment/decrement functions. |
+1 to not changing the existing meaning of Using Maybe (defmacro incv [x]
`(+= ~x 1))
(setv xs [1 2 3])
(incv (get xs 2))
(print xs)
;; => [1, 2, 4] |
But there is; it's the same concept of lvalue that Python uses. Just as you can put a variety of things to the left of |
I'm betting that |
Personally I think it would be cool to do this as follows:
(setv x 1)
#! (succ x) ; expands to (setv x (succ x))
(setv l [5 4 3 2 1])
#! (sorted l) ; expands to (setv l (sorted l)) This would be a more general solution, bridging the mutative<->non-mutative gap in the other direction, which would be awesome. However, it's a little weird/hard to read. Also, the examples I gave are very simple and it's not clear how it should generalize to multiple values or multiple forms (if desired). |
It looks like it (7369588). Yeah, it's not clear how |
A solution would be to make it not a tag, so you'd have: (mut a (succ))
(mut b (sorted))
(mut c (filter even?))
; Multiple forms?
(mut d (map succ) (filter even?)) where the supplied argument is the last argument. |
Personally I actually like the @Quelklef wouldn't that just be a specialized form of threading macro? (defmacro ->! [lval &rest forms]
`(setv ~lval
(-> ~lval ~@forms)))
;; eg.
(setv x 1)
(->! x
(str)
(repeat 5)
(zip (range 10))
(list))
(print x)
;; => [('1', 0), ('1', 1), ('1', 2), ('1', 3), ('1', 4)]
|
Yeah. But I've been pondering this kind of macro for a while and I think it may be useful enough to warrant its own thing. |
I suppose it doesn't make sense to call My personal vote goes for:
This would also fit better with Python's "one way to do it" mantra. |
My vote would be for |
I get that Hy follows Clojure, but I would opine that Clojure's naming is a mistake. I presume that And by status quo more general than just Clojure, |
I'm not sure I should get a vote, but I can't help being opinionated here.
|
IMO,
inc
is poorly named. I had thought that(inc x)
is(+= x 1)
when it, in fact, is(+ x 1)
. "increment" seems to imply a mutative statement.I suggest that
(inc x)
be(+= x 1)
and(succ x)
be(+ x 1)
. Similarly,(dec x)
should be(-= x 1)
and(pred x)
be(- x 1)
.This would be in line with:
succ
andpred
mean what Hy'sinc
anddec
do.The text was updated successfully, but these errors were encountered: