Fork me on GitHub
#beginners
<
2016-04-27
>
urbanslug11:04:28

Hey, is there a function that checks for the truthiness of a function and when falsey it sets the result to nil ?

rauh11:04:04

@urbanslug: Can you make an example? A function is always truthy. Or do you mean the result of a call? when does return nil for falsey.

urbanslug11:04:12

rauh: yeah like when but when true I want the when to return true

urbanslug11:04:55

Currently what I have is: (when (bool-returning-function) true)

rauh11:04:18

@urbanslug: I'd say that's as short as it gets and it's very idiomatic. At least I can't think of anything shorter.

urbanslug11:04:03

@rauh: I was hoping there’s something in the standard libs for it 😄

urbanslug11:04:20

I guess clojure macros save the standard libs a lot of bloat.

rohitarondekar11:04:22

Slightly off topic but need recommendations for a good book to learn Java. Something modern/new and not for first time programmers. The only decent recommendation I've gotten so far is Thinking in Java (4ed) which was released quite a long back.

roberto11:04:50

@urbanslug: how about or?

roberto11:04:36

(or (bool-returning-function) nil) ?

urbanslug11:04:13

@roberto: Let me check that out

urbanslug11:04:36

Looks kinda obscure

roberto11:04:45

it actually isn’t for lisps

roberto11:04:54

and is the same way

urbanslug11:04:02

I was hoping (func (bool-returning-function)

roberto11:04:38

this is standard in other lisps

bones12:04:18

Not sure where to ask this but .. I was just wondering, I’m used to the Apache/PHP mix where you’ve a public_html dir and something in Apache will call the index.php to kick things off - is there an equivalent in Clojure? I’ve seen httpkit/jetty are these meant to be the http server replacements for apache?

roberto12:04:42

yes, clojure apps (and java apps) are not deployed to apache’s http server

roberto12:04:10

traditionally they were deployed to a container like Apache Tomcat

roberto12:04:31

nowadays, it is common to have an embedded server like jetty or netty(httpkit) in the application

curtis.summers13:04:38

@bones I deploy an uber jar with an embedded jetty that runs via a systemd startup script and is fronted by nginx for SSL/TLS. The luminus deploy docs actually give several good examples of deployment options: http://www.luminusweb.net/docs/deployment.md

codonnell14:04:41

That's what I do, as well.

audaxion19:04:00

For example, when a piece matches a

:waypoint
the next piece need to be added as a new key
:airway
for all waypoints until the next match

codonnell19:04:39

@audaxion: could you give a small example of input and desired output data?

audaxion19:04:53

@codonnell: with the first snippet i uploaded as inputs, this is what i’d expect the output to look like

codonnell19:04:46

so if the waypoint string shows up in your list at the bottom, you add the key :airway with value equal to the string following it?

audaxion19:04:18

and also to every waypoint following it until i hit another match

codonnell19:04:19

but then there is some special behavior for the ...'s?

audaxion19:04:17

the .. indicates the next string is another waypoint name, instead of an airway name

codonnell19:04:19

The first thing to do in my opinion is to convert your string into a better data structure.

codonnell19:04:47

I'm not sure exactly how your ...'s behave, but for the waypoint : airway pairs, it seems natural to store them in a map

codonnell19:04:23

for example, the first few would be {"MMMX" "PTJ5A", "PTJ5A" "PTJ", ...}

codonnell19:04:39

that way given a waypoint, you have an efficient way of finding its airway

jonschoning19:04:43

something wrong with grimoire? can I run it in an offline mode?

yogidevbear20:04:16

Hi everyone. I'm working through the Getting Started chapter in Brave Clojure (http://www.braveclojure.com/getting-started/) and I'm getting an error when trying to run the jar file created from the lein uberjar command:

Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/Var
        at clojure_noob.core.<clinit>(Unknown Source)
Caused by: java.lang.ClassNotFoundException: clojure.lang.Var
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Any ideas what could be causing the issue? (Not sure if I asked this last time I was working through this chapter)

audaxion20:04:25

@codonnell: how would you recommend i go about splitting up the string to create the map?

henripal20:04:30

@audaxion: (apply hash-map (.split (str (clojure.string/replace myinput ".." " none ") " none") " "))

henripal20:04:07

wher myinput is your input string

henripal20:04:43

(also a beginner, seeing this as a good exercise, let me know if I'm doing this clumsily)

curtis.summers20:04:47

@yogidevbear It looks like you are not running the -standalone.jar file

codonnell20:04:50

I think there needs to be a (partition 2 1 coll) in there somewhere

codonnell20:04:14

and another split

codonnell20:04:48

For example, you want to split "A B C..D" first into ["A B C", "D"]

codonnell20:04:04

Then you want to get all of the pairs out of "A B C", so you want to turn that into [["A" "B"], ["B" "C"]]

codonnell20:04:12

And the hash-map function will convert that seq into a hash map.

codonnell20:04:46

Try to focus on doing each of those steps individually, then figure out how to string them together.

codonnell20:04:16

You should need string/split, partition, mapcat, and hash-map.

yogidevbear20:04:05

@curtis.summers: Thank you. I didn't notice on first glance that two jars were created. 👍

audaxion20:04:15

thanks @codonnell i’ll see what i can come up with

codonnell20:04:43

No problem. If you have more questions, feel free to ping me.

curtis.summers20:04:03

@yogidevbear: Yes, it's gotten me many times before. I don't think I've ever used the other jar it creates. I wonder if there's a way to prevent it from creating both to begin with.

noisesmith21:04:07

@curtis.summers: it uses the foo.jar as an input to the process that makes foo-standalone.jar

noisesmith21:04:28

I mean you could change it so it just creates foo.jar in memory, or puts it in a tmp file or whatever

bones22:04:30

Great thanks @roberto @curtis.summers @codonnell

bones22:04:07

@roberto, @curtis.summers so instead of “deploying” your PHP files to a folder where the Apache can run them, when you say “embed” a server into your app, when you deploy, you’re deploying the whole thing web server and all?

bones22:04:47

If you want multiple applications on the same box how do they not all fight over port 80?

bones22:04:03

Again, complete beginner here, thanks for your help and patience

curtis.summers22:04:23

No, nginx handles port 80 and 443, and my virtual host for http://mywebsite.com uses a proxy to my jetty process running on a localhost port.

bones23:04:22

Ah! so it does a DNS-like thing and you tell it what local ports your apps are living on and what requests get forwarded to them?

bones23:04:37

so is nginx acting like a reverse proxy in that case?

curtis.summers23:04:36

Yes, that's basically it. It's very common to let nginx or Apache handle the virtual host, port 80, and TLS/SSL.

bones23:04:14

Cool, thanks very much