->foo is new in 1.3. I'm surprised so many people are recommending it
without mentioning that. ->foo is like foo., except that it's a real
clojure function and as such can be passed as a function; you can call
apply on it; and so forth.
On Oct 6, 11:05 am, Razvan Rotaru wrote:
> This is what I'm
This is what I'm looking for. Thanks. I have not seen this kind of
expression before: ->foo. Is is created by defrecord or is it
implemented at reader level?
I realize now that I can also keep a generating function in the
variable stuff:
(let [stuff #(car. %1 %2)]
(stuff 1982 "Mercedes")
(stu
Hi,
use the factory function.
Clojure 1.3.0
user=> (defrecord car [year manufacturer])
user.car
user=> (defn create [stuff] (stuff 1982 "Mercedes Benz"))
#'user/create
user=> (create ->car)
#user.car{:year 1982, :manufacturer "Mercedes Benz"}
You can't pass car. around at runtime because it is a
Wow, that was fast. Thanks.
This could work but only partially.
(let [stuff car]
(new stuff 1982 "Mercedes")
(new stuff 2001 "Seat")
...)
I could take advantage of the fact that records are maps:
(let [stuff (car. 1982 "Mercedes")]
... use Mercedes...
(assoc stuff :year 2001 :manufac
is it ->record just a shortrand for record.?
2011/10/6 Aaron Bedra
> Assuming you want to do things with the record later, why not just
> create it in the let binding
>
> (let [foo (->car 1982 "Mercedes")]
> ...)
>
> or
>
> (let [foo (car. 1982 "Mercedes")]
> ...)
>
> or even
>
> (let [foo (ma
Assuming you want to do things with the record later, why not just
create it in the let binding
(let [foo (->car 1982 "Mercedes")]
...)
or
(let [foo (car. 1982 "Mercedes")]
...)
or even
(let [foo (map->car {:year 1982 :manufacturer "Mercedes"})]
...)
or if you must
(let [foo #user.car{