Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EuroClojure 2017 Slide 14 Possible Error #21

Closed
pwhittin opened this issue Aug 11, 2017 · 5 comments
Closed

EuroClojure 2017 Slide 14 Possible Error #21

pwhittin opened this issue Aug 11, 2017 · 5 comments

Comments

@pwhittin
Copy link
Collaborator

pwhittin commented Aug 11, 2017

On slide 14 the following code is displayed:

(require '[otplike.gen-server :as gs])

; provide initial state (required!)
(defn init []
   [:ok {}])

; handle sync requests
(defn handle-call [message from state]
  (match message 
    [::add a1 a2]
    [:reply (+ a1 a2) state]))

(defn add [server a1 a2]
  (gs/call server [::add a1 a2]))      

(let [[_ server] (gs/start-ns [])]
  (println "2 + 3 = " (add server 2 3)))

In order to get it to compile from a "clean" "lein repl" I had to add the line

(require '[clojure.core.match :refer [match]])

to the top of the code.

When I did, I received the following error:

Exception noproc  otplike.process/self (process.clj:425)

I don't know what this means.

@sskorokhodov sskorokhodov self-assigned this Aug 11, 2017
@sskorokhodov
Copy link
Collaborator

I think some statements (like requiring core.match) are omitted on the slides for the sake of brevity.

I'm checking the problem with exception now.

@pwhittin
Copy link
Collaborator Author

Do you know of an Erlang example that is fairly complex, but not very complex, that I can "port" to otplike? I need to understand how to use otplike for my current project, and starting with a well understood Erlang example might be a good approach. Of course, I would contribute the port to the otplike project when I get it working.

I'd probably need to ask you questions along the way. Is creating issues the way you would like me to ask questions?

@sskorokhodov
Copy link
Collaborator

sskorokhodov commented Aug 11, 2017

Is creating issues the way you would like me to ask questions?

Yes, it would be very nice of you! It also makes it easier for others to find answers to the questions that have already been asked.

@sskorokhodov
Copy link
Collaborator

sskorokhodov commented Aug 11, 2017

The problem with the example is here:

(gs/start-ns [])

gen-server can only be started by another process. It must be added to the docstring of gen-server/start. The reason why gen-server must be started by another process is that according to OTP principles gen-server must treat exit message from the parent process in a special way.

Exception with the reason "noproc" means that caller is supposed to be a process.

The problem can be fixed by wrapping the last let statement into a spawned function like this:

(process/spawn
  (process/proc-fn []
    (let [[_ server] (gs/start-ns [])]
      (println "2 + 3 = " (add server 2 3)))))

We'll think about fixing this slide.

@sskorokhodov
Copy link
Collaborator

Do you know of an Erlang example that is fairly complex, but not very complex, that I can "port" to otplike?

I think of examples from the learnyousomeerlang book. Every chapter has one or more good examples supplementing explanation of a concept. I would started from examples given in this chapter. The book is also useful because it guides you step by step through the OTP principles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants