Fork me on GitHub
#beginners
<
2015-12-05
>
rcanepa02:12:34

Has anyone tried the LispCast Web Development videos?

rcanepa02:12:55

I am particularly interested in developing a REST API, so I would like to dig more in ring’s handlers, compojure, security/authentication, etc., does anyone knows if those videos could be a good starting point?

games03:12:45

i signed up for the monthly membership but havent watched any yet

eggsyntax03:12:42

@rcanepa: Collections, in Java, refers to a class hierarchy containing various interfaces & implementations of map/list/set/queue/deque. See https://docs.oracle.com/javase/tutorial/collections/

cjmurphy09:12:31

Did you post the question in beginners?

roelof09:12:42

nope, In #C03S1KBA2

roelof09:12:50

but I can repost it here again ?

cjmurphy09:12:56

Yes please.

roelof09:12:22

I have 2 refs which represent a account like cash or bank. Now I want to calculate the new amount of the accounts. A transaction could look like this [ { :account cash :withdraw 100} ] [ :account bank :deposit 100] } I know I have to use alter but how do I do it when everything step of a transaction is in a map. and the map could have more steps then 1 as my example have shown

roelof09:12:57

or can I do something like this ( map (alter ....... ) withdraws) and the same for the deposits

cjmurphy10:12:38

I have never (hardly) dealt with refs, but I know they are just like a db commit.

cjmurphy10:12:48

Can't you just have one ref?

roelof10:12:22

I could but then I have to rethink how I can take care the amount of a particular account

roelof10:12:44

now I have one ref which holds the amount of cash and one ref which holds the amount of the bank

cjmurphy10:12:15

Even an atom would work as long as you did the whole change in the swap!

roelof10:12:53

one atom whichs holds two values ??

cjmurphy10:12:14

You can hold the world in one atom.

roelof10:12:59

oke, I thought a atom or ref is like this (def cash {:atom 100})

roelof10:12:33

I do this for a financial app so I need transactions otherwise things will go wrong

cjmurphy10:12:54

(def default-state {:my-lines {} :hover-pos nil :last-mouse-moment nil :labels-visible? false :in-sticky-time? false :labels [] :current-label nil}) (def state (atom default-state))

trancehime10:12:10

{ :accounts {:cash VAL :bank VAL}}

trancehime10:12:19

or something

roelof10:12:22

and I have doubt for the best way to do the last step. Chancing the values of the refs

trancehime10:12:15

An atom can basically be whatever you need it to be

roelof10:12:32

oke, learned another thing

cjmurphy10:12:55

See @trancehime's example. But VAL can really be anything, like [{:what ""}{:what nil}]

trancehime10:12:25

Yeah, the atom can be modeled to suit your needs.

trancehime10:12:33

Modifying the atom's contents can be done using swap!

roelof10:12:15

oke Can I have transactions on atoms. I need to have that so if a transactions like [ { :account cash :withdraw 100} ] [ :account bank :deposit 100] } fails nothings has to happen

roelof10:12:45

for example if you want to withdraw more then the amounts of cash

trancehime10:12:27

that's what swap! is for

trancehime10:12:43

(swap! your-atom your-function)

cjmurphy10:12:08

Only one swap! ever happens at a time.

roelof10:12:29

oke, thanks for the help

roelof10:12:55

I will try that senario and some others

cjmurphy10:12:35

okay good luck

roelof11:12:54

Another question : I have a vector of maps like this [ {:arg1 test :arg2 test2}] Now I need to have the contents of arg1 and arg2 for another function. So I could use map to iterate over the vector and get the first element. So far so good. Then I need a anymous function which as far as I know needs 2 arguments. But the arguments are not known till the first element is chosen. I can named it "it" so I can do (get :arg1 it) but I see then that I need to have 2 arguments. How to solve this one ?

rcanepa11:12:43

@games: I am watching Web Development right now simple_smile

sveri11:12:28

@rcanepa: I stream here: https://www.livecoding.tv/sveri/ from time to time. I am happy to answer questions too if I can 😉

Chris O’Donnell14:12:06

@roelof: Something like this could work: ((juxt :a :b) {:a 1 :b 2} yields [1 2]

Chris O’Donnell14:12:27

oops missing close paren

Chris O’Donnell14:12:53

You could also do (map {:a 1 :b 2} [:a :b]), which gives you the list (1 2)

Tim17:12:03

@codonnell: thats a cool trick

Tim17:12:12

I haven’t seen that before

Tim17:12:32

how come stuff like map, filter return lazy-sequences?

Tim17:12:52

I don’t see why that is necessary/advantageous?

Chris O’Donnell17:12:43

If you don't want a lazy seq, you can use mapv. Lazy and non-lazy have their own advantages and disadvantages.

Chris O’Donnell17:12:24

You can handle things like infinite sequences with lazy operations.

Tim18:12:17

(list +) '(+)

Tim18:12:37

how come (list +) returns (#object[clojure.core$_PLUS_ 0x4415ab68

Tim18:12:51

but ‘(+) returns (+)

Tim18:12:41

for that matter

(list 'foo 'bar)

'('foo ‘bar)

Tim18:12:08

returns (foo bar) and ((quote foo) (quote bar)) respectively

Chris O’Donnell18:12:40

Quoting stops the REPL from evaluatin what's inside. So the type of the + in '(+) is a symbol, while in (list +), the + is evaluated and becomes a function type.

Tim18:12:00

thank you

Tim18:12:04

very helpful

rcanepa19:12:03

@sveri: Cool!… I will check it for sure!!

rcanepa19:12:16

I am fighting with a simple problem and I can’t find the problem. I am sure that I am missing some detail, can anyone take a look a this?. It is a simple handler that I created to learn about ring and compojure. For some reason, I can’t coerce a string (request parameters) to an Integer.

rcanepa19:12:54

I am getting this error:

rcanepa19:12:55

No implementation of method: :render of protocol: #'compojure.response/Renderable found for class: java.lang.Long

sveri19:12:20

@rcanepa: I guess compojure expects something it can render as return value of "calc"

sveri19:12:32

But it gets Long, thats where the error comes from

sveri19:12:33

Btw. I start another stream in a few minutes, I can show you what I mean there, if you want

rcanepa19:12:44

@sveri: Yeah… you are right… I wasn’t returning a response map.

rcanepa19:12:49

Just a number!