Fork me on GitHub
#beginners
<
2016-06-19
>
emperorcezar02:06:45

How do I know when to quote a vector used with require?

emperorcezar02:06:43

If I quote it in the file, this seems to anger cursive, if I don't quote it in the repl, it won't work

richiardiandrea02:06:17

@emperorcezar: you always have to quote a (require 'some.ns) in the repl but never a (ns my.ns (:require some.ns))

yusup10:06:29

Hi , ('+ 1 2 ) , this doesnot throw any errors, and yet returns the last item in the list , why ?

plexus11:06:30

hi @yusup, I had to consult the code for this. Apparently symbols are like keywords, in that you can use them as a function that does a map lookup

plexus11:06:49

('x {'x 5 'y 6}) ;;=> 5

plexus11:06:25

if you pass an extra argument then this is used as a default value when the symbol is not present as a map

plexus11:06:02

('x {'y 6} :not-found) ;;=> :not-found

plexus11:06:26

in other words, when used in function position, a symbol behaves like a keyword

plexus11:06:50

putting anything by a map or a set as first argument will return nil, or the default value if you specify it

plexus11:06:07

('x 5) ;;=> nil

plexus11:06:19

('x 5 2) ;;=> 2

yusup13:06:40

@plexus: Thanks . Got it now.

yusup13:06:50

next time I will read the compiler code .

plexus13:06:47

:) or you can ask here. Now at least two people learned something

yusup15:06:23

yepp 🙂

zzamboni22:06:41

Now that I (almost) finished #C0M8PCF7U, I've been going through the 4clojure exercises. Quite stimulating - any other good sources of beginner-oriented exercises?