Adding a notation to access argument

89 views
Skip to first unread message

Hiroyuki Fudaba

unread,
Jun 12, 2016, 11:55:09 AM6/12/16
to Clojure Dev
Hi all,

In Clojure's anonymous function notation, arguments can be accessed by %, %& or %integer.
For example, it can access to an nth argument by %n.
However, there are some situations you want to access the first item of first arguments, and so on.
This can be done by writing like:

```
#((let [x (first %1)] ... x ...) ...)
```

But this may be better if we could write it more shortly, as follows

```
#(... %1.1 ...)
```

I wonder how people think about the idea.
Any suggestions and comments are welcome!

Thanks! :)

Hiroyuki Fudaba

Alex Miller

unread,
Jun 12, 2016, 11:57:21 AM6/12/16
to cloju...@googlegroups.com
You can use destructuring for that.
--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-dev...@googlegroups.com.
To post to this group, send email to cloju...@googlegroups.com.
Visit this group at https://groups.google.com/group/clojure-dev.
For more options, visit https://groups.google.com/d/optout.

Akhil Wali

unread,
Jun 13, 2016, 8:26:27 AM6/13/16
to Clojure Dev
Use destructuring, as follows:

```
#((let [[x & xs] %1] ... x ...) ...)
```
Reply all
Reply to author
Forward
0 new messages