Fork me on GitHub
#beginners
<
2016-11-16
>
Jon03:11:50

clojure
cljs.user=> (defrecord A [a b c])
cljs.user/A
cljs.user=> (A. 1 2 3)
#cljs.user.A{:a 1, :b 2, :c 3}
cljs.user=> (def a (A. 1 2 3))
#'cljs.user/a
cljs.user=> (pr-str a)
"#cljs.user.A{:a 1, :b 2, :c 3}"
cljs.user=> (def b (pr-str a))
#'cljs.user/b
cljs.user=> (read-string b)
WARNING: Use of undeclared Var cljs.user/read-string at line 1
TypeError: Cannot read property 'call' of undefined
cljs.user=> (require '[cljs.reader :refer [read-string]])
nil
cljs.user=> (read-string b)
Error: Could not find tag parser for cljs.user.A in ("inst" "uuid" "queue" "js")
cljs.user=>

Jon03:11:38

Does Clojure parse this thing? "#cljs.user.A{:a 1, :b 2, :c 3}"

Alex Miller (Clojure team)03:11:19

Sure, assuming you've installed a data reader for it or a default data reader

echristopherson04:11:25

I'm trying but failing to figure out which of the books in the series of The Little LISPer/Schemer have no-cost licensing. Sure, a lot of them are available online, but I can't tell if it's legally or not.

echristopherson04:11:53

If anyone knows, let me know. Thanks.

Jon04:11:33

Just found out it's a Clojure feature that no in ClojureScript 😞

Jon04:11:00

boot.user=> (defrecord A [a b])
boot.user.A
boot.user=> (def a (A. 1 2))
#'boot.user/a
boot.user=> (def b (pr-str a))
#'boot.user/b
boot.user=> (read-string b)
<#C053K90BR|boot>.user.A{:a 1, :b 2}
boot.user=> (= (type b) A)
false
boot.user=> (type b)
java.lang.String
boot.user=> (= (type a) A)
true

Jon04:11:14

I should read the whole page, it's different in cljs, but we do have an anwser http://stackoverflow.com/a/29133350/883571 thx @alexmiller

sb09:11:05

Hello, I would like to setup Clojure-NGINX.. on Ubuntu 14.04. I installed NGINX, works (http://gooapir.com - my test server). I would like to add the NGINX module.. I don’t know what is the problems: I untar the file with command tar -xzvf “nginx-clojure-0.4.4.tar.gz”.. after this I would like to run ./configure.. (as in the spec) but not works. Could you help me? What is the wrong? Maybe very trivial…

roelofw10:11:55

@sb does the configure ends or do you see a error message ?

sb10:11:10

I got this back: -bash: ./configure: No such file or directory

sb10:11:36

in the specification: ./configure —add-module=nginx-clojure/src/c

sb10:11:40

after this command

roelofw10:11:08

oke, can you check if there is a file named configure

roelofw10:11:16

it looks like that one is missing

sb10:11:23

I don’t have.. 😞

roelofw10:11:36

Can you paste somewhere the contents of the directory that schould contain configure ?

sb10:11:58

unzipped folder

sb10:11:29

maybe I start the command from a wrong folder or I don’t know

sb10:11:45

I installed before this Apache modules.. but I don’t have similar problem

sb10:11:04

Maybe very easy the answer.. 😞

roelofw10:11:28

moment, I will have a look

sb10:11:32

thanks!!

roelofw10:11:07

Can you goto the root dir

sb10:11:23

ok, Im there

roelofw10:11:34

Is there a configure file

roelofw10:11:42

on my download there is

sb10:11:12

I don’t have..

sb10:11:30

did you download with wget?

roelofw11:11:22

nope, I clicked on the link of the github page of clojure-ngnix

roelofw11:11:36

Did you download a zip file or a tar.gz file

sb11:11:48

ok, I downloaded

roelofw11:11:40

you downloaded what ?

sb11:11:48

I share with you the link

sb11:11:57

one moment

sb11:11:37

I downloaded to ubuntu 14.04 this file

roelofw11:11:15

I suspect that you have download a binary file. What happens if you do 'sh nginx-linux-i586 ` ?

sb11:11:40

sh: 0: Can't open nginx-linux-i586

roelofw11:11:09

what is the output of file nginx-linux-i586

sb11:11:35

one moment

sb11:11:17

nginx-linux-i586: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped

sb11:11:36

I hope do you would like to get this

roelofw11:11:09

oke, could you do ls -al nginx-linux-i586

sb11:11:43

-rwxr-xr-x 1 root root 2764620 Nov 16 10:22 nginx-linux-i586

sb11:11:33

sh this file I got nginx-linux-i586: 1: nginx-linux-i586: Syntax error: "(" unexpected

roelofw11:11:21

are you root at the moment

sb11:11:48

yes, I’m root. I logged in as a root

roelofw11:11:33

if you try it without the sh part so just nginx-linux-i586

sb11:11:57

nginx-linux-i58: command not found

sb11:11:14

similar nginx-linux-i586: command not found

roelofw11:11:56

I think you can better ask in a nginx or ubuntu community

roelofw11:11:04

Im out of ideas

sb11:11:14

Ok, thanks! Sorry!

roelofw11:11:46

Why do I see here two times nill :

(def the-world (ref "hello"))
(def bizarro-world (ref {}))
=> #'koan-engine.runner/the-world
=> #'koan-engine.runner/bizarro-world
(do
  (dosync
    (ref-set the-world {})
    (alter the-world assoc :jerry "Real Jerry")
    (alter bizarro-world assoc :jerry "Bizarro Jerry")
    [ (:jerry the-world) (:jerry bizarro-world)  ]))
=> [nil nil]

st11:11:10

@roelofw you might have forgotten to dereference with @

johnny.martin13:11:10

@sb @roelofw sometimes a "dot" and a "slash" can help, e.g.,

./nginx-linux-i586
which has to do with current directory not on your $PATH

roelofw14:11:02

@johnny.martin thanks for the tip. I hope sb get s things working

sb14:11:13

@johnny.martin @roelofw Thanks guys! You save my day! 👍 👍 💪

sb14:11:35

Yes, works fine! 🙃🙂

tosh14:11:45

what is the difference between + and +’

kauko14:11:47

(apply + (range 10000000000000 10000000001000))
;; ArithmeticException: integer overflow

(apply +' (range 10000000000000 10000000001000))
;;=> 1000000000499500

roelofw18:11:32

If I have this code : (defrecord Nobel [prize]) is it right that the price is returned back

seancorfield19:11:11

Not sure what you’re asking @roelofw ?

roelofw19:11:46

oke, I have made this record.

seancorfield19:11:48

When I type (defrecord Nobel [prize]) into a REPL, it prints the name of the class just defined (`boot.user.Nobel` in my case)

roelofw19:11:37

and now I do (.prize (Nobel. xxxx )) where x can be a any string. Is it right that the outcome will be xxxx

roelofw19:11:11

is my question now more clear ?

seancorfield19:11:40

It’s more idiomatic to write (:prize (->Nobel xxxx)) but, yes, if you construct a Nobel record with xxxx as the argument, that will be the value of the prize field.

roelofw19:11:04

oke, and that one will be the output

roelofw19:11:23

I try to understand the record chapter of the clojure koans

seancorfield19:11:32

It would be like this expression (:prize {:prize xxxx})

roelofw19:11:09

in repl I only see the xxx part. See :

(defrecord Nobel [prize])
(deftype Pulitzer [prize])

(defprotocol Award
  (present [this recipient]))

(defrecord Oscar [category]
  Award
  (present [this recipient]
    (print (str "Congratulations on your "
                (:category this) " Oscar, "
                recipient
                "!"))))
=> koan_engine.runner.Nobel
=> koan_engine.runner.Pulitzer
=> Award
=> koan_engine.runner.Oscar
(.prize (Nobel. "peace"))
=> "peace"   

roelofw19:11:17

@seancorfield : did I do something wrong or do I misunderstood you with my other outcome as you described ?

dpsutton19:11:00

did you do anything wrong?

dpsutton19:11:23

does it agree with what you want out of it?

roelofw19:11:22

I think it does , but according to the explanation of sean the outcome schould be (:prize {:prize peace) instead of just 'peace'

roelofw19:11:54

Like I said earlier I try to understand the things I learn from the record chapter of the clojure koans

dpsutton19:11:38

that's not an outcome

dpsutton19:11:45

here :prize acts as a function

dpsutton19:11:05

and would retrieve the value stored under the :prize keyword in the map

dpsutton19:11:15

he's giving you an easier and more idiomatic way to access fields on a record

manutter5119:11:35

@roelofw I think you misunderstood Sean, I think he was saying that the outcome of (.prize (Nobel. xxxx )) should be like the outcome of (:prize {:prize xxxx}). In other words, the action of getting a value out of a record is like the action of getting a value out of a map.

seancorfield19:11:44

☝️:skin-tone-2:

roelofw20:11:36

oke, then I think I can make the first challenges

roelofw20:11:53

This is the most challeging chapter so far

roelofw20:11:56

one last question : On this code :

(defprotocol Award
  (present [this recipient]))

(defrecord Oscar [category]
  Award
  (present [this recipient]
    (print (str "Congratulations on your "
                (:category this) " Oscar, "
                recipient
                "!"))))  

roelofw20:11:27

what exactly does the protocol on the Oscar record ?

manutter5120:11:09

The Award protocol says “Any record that implements the Award protocol will have a method named “present” that takes the arguments “this” and “recipient” and does something appropriate with them”. Then the definition for “Oscar” says “This record implements the Award protocol, and here is Oscar’s implementation of the “present” method.” So a protocol is something like a Java or C interface that lets you share behaviors between record types that are similar

manutter5120:11:28

For small, tutorial examples like Award and Oscar, it might not be apparent how much power this gives you, but it’s a good introduction to “here are the basic principles of how you define and use a protocol."

roelofw20:11:11

@manutter51 so with a protocol I can have methods that I can use in different records

roelofw20:11:33

Im not familair with Java or C interfaces

manutter5120:11:53

Right, you have the basic idea at least. It’s like having a contract that says “I know how to do ‘X’” and then you can have a number of different record types but they all know how to do “X” so they can all implement the same protocol.

roelofw20:11:03

oke, and this has to do with scope and recipient is the argument on which the record is called. In the first one that will be "peace"

roelofw20:11:33

Thanks for helping me with getting a basic idea of protocols , records