defrecord holding a incrementing `vector` / `java class`
up vote
0
down vote
favorite
Clojurians:
Thank you for your attention on this question !
Here is case I'm thinking about, I want to define a immutable bank account record
(defrecord account [ name balance statements])
(def cash-account (->account :cash 0.0 ))
I have a function that will deposit
money to that account ,and a new record of account
shall return
(.deposit cash-account 100.0 )
;; returns a new cash-account with attributes
;; name = :cash balance= 100, statment=[ [(2018,1,1),100 ] ]
With more and more deposit and withdraw happening , the field statement
list will expanding with more and more transactions inside.
My question will be :
after 1000 transactions, there are 1000 elements in the statment
field of latest account return.
When 1001th transaction happend:
will Clojure *copy* 1000 transactions in the statment
field of old account record ,and append new transaction, save them into new account record ?
or Clojure just *append* the new transaction to the old account record and provide a new pointer to it , make it look like new account record like persistent map ?
Appreciate your help & many thanks
clojure
add a comment |
up vote
0
down vote
favorite
Clojurians:
Thank you for your attention on this question !
Here is case I'm thinking about, I want to define a immutable bank account record
(defrecord account [ name balance statements])
(def cash-account (->account :cash 0.0 ))
I have a function that will deposit
money to that account ,and a new record of account
shall return
(.deposit cash-account 100.0 )
;; returns a new cash-account with attributes
;; name = :cash balance= 100, statment=[ [(2018,1,1),100 ] ]
With more and more deposit and withdraw happening , the field statement
list will expanding with more and more transactions inside.
My question will be :
after 1000 transactions, there are 1000 elements in the statment
field of latest account return.
When 1001th transaction happend:
will Clojure *copy* 1000 transactions in the statment
field of old account record ,and append new transaction, save them into new account record ?
or Clojure just *append* the new transaction to the old account record and provide a new pointer to it , make it look like new account record like persistent map ?
Appreciate your help & many thanks
clojure
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Clojurians:
Thank you for your attention on this question !
Here is case I'm thinking about, I want to define a immutable bank account record
(defrecord account [ name balance statements])
(def cash-account (->account :cash 0.0 ))
I have a function that will deposit
money to that account ,and a new record of account
shall return
(.deposit cash-account 100.0 )
;; returns a new cash-account with attributes
;; name = :cash balance= 100, statment=[ [(2018,1,1),100 ] ]
With more and more deposit and withdraw happening , the field statement
list will expanding with more and more transactions inside.
My question will be :
after 1000 transactions, there are 1000 elements in the statment
field of latest account return.
When 1001th transaction happend:
will Clojure *copy* 1000 transactions in the statment
field of old account record ,and append new transaction, save them into new account record ?
or Clojure just *append* the new transaction to the old account record and provide a new pointer to it , make it look like new account record like persistent map ?
Appreciate your help & many thanks
clojure
Clojurians:
Thank you for your attention on this question !
Here is case I'm thinking about, I want to define a immutable bank account record
(defrecord account [ name balance statements])
(def cash-account (->account :cash 0.0 ))
I have a function that will deposit
money to that account ,and a new record of account
shall return
(.deposit cash-account 100.0 )
;; returns a new cash-account with attributes
;; name = :cash balance= 100, statment=[ [(2018,1,1),100 ] ]
With more and more deposit and withdraw happening , the field statement
list will expanding with more and more transactions inside.
My question will be :
after 1000 transactions, there are 1000 elements in the statment
field of latest account return.
When 1001th transaction happend:
will Clojure *copy* 1000 transactions in the statment
field of old account record ,and append new transaction, save them into new account record ?
or Clojure just *append* the new transaction to the old account record and provide a new pointer to it , make it look like new account record like persistent map ?
Appreciate your help & many thanks
clojure
clojure
asked Nov 20 at 4:01
Shawn Zhang
9091616
9091616
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
From https://clojure.org/reference/datatypes#_deftype_and_defrecord :
- defrecord provides a complete implementation of a persistent map
- deftype supports mutable fields, defrecord does not
so, in your case, it will not copy the transactions, instead it will use a persistent data structure so it will look like the transaction was appended.
add a comment |
up vote
0
down vote
Here are some more docs you should also check:
- https://www.braveclojure.com/functional-programming/
- https://clojure.org/guides/learn/sequential_colls
- https://purelyfunctional.tv/guide/clojure-collections/
- https://youtu.be/lJr6ot8jGQE
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
From https://clojure.org/reference/datatypes#_deftype_and_defrecord :
- defrecord provides a complete implementation of a persistent map
- deftype supports mutable fields, defrecord does not
so, in your case, it will not copy the transactions, instead it will use a persistent data structure so it will look like the transaction was appended.
add a comment |
up vote
2
down vote
accepted
From https://clojure.org/reference/datatypes#_deftype_and_defrecord :
- defrecord provides a complete implementation of a persistent map
- deftype supports mutable fields, defrecord does not
so, in your case, it will not copy the transactions, instead it will use a persistent data structure so it will look like the transaction was appended.
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
From https://clojure.org/reference/datatypes#_deftype_and_defrecord :
- defrecord provides a complete implementation of a persistent map
- deftype supports mutable fields, defrecord does not
so, in your case, it will not copy the transactions, instead it will use a persistent data structure so it will look like the transaction was appended.
From https://clojure.org/reference/datatypes#_deftype_and_defrecord :
- defrecord provides a complete implementation of a persistent map
- deftype supports mutable fields, defrecord does not
so, in your case, it will not copy the transactions, instead it will use a persistent data structure so it will look like the transaction was appended.
answered Nov 20 at 4:19
Denis Fuenzalida
874614
874614
add a comment |
add a comment |
up vote
0
down vote
Here are some more docs you should also check:
- https://www.braveclojure.com/functional-programming/
- https://clojure.org/guides/learn/sequential_colls
- https://purelyfunctional.tv/guide/clojure-collections/
- https://youtu.be/lJr6ot8jGQE
add a comment |
up vote
0
down vote
Here are some more docs you should also check:
- https://www.braveclojure.com/functional-programming/
- https://clojure.org/guides/learn/sequential_colls
- https://purelyfunctional.tv/guide/clojure-collections/
- https://youtu.be/lJr6ot8jGQE
add a comment |
up vote
0
down vote
up vote
0
down vote
Here are some more docs you should also check:
- https://www.braveclojure.com/functional-programming/
- https://clojure.org/guides/learn/sequential_colls
- https://purelyfunctional.tv/guide/clojure-collections/
- https://youtu.be/lJr6ot8jGQE
Here are some more docs you should also check:
- https://www.braveclojure.com/functional-programming/
- https://clojure.org/guides/learn/sequential_colls
- https://purelyfunctional.tv/guide/clojure-collections/
- https://youtu.be/lJr6ot8jGQE
answered Nov 20 at 8:02
Alan Thompson
12.8k12433
12.8k12433
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386033%2fdefrecord-holding-a-incrementing-vector-java-class%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown