Fork me on GitHub
#beginners
<
2016-01-14
>
trancehime03:01:00

I'm trying to run my web application on Immutant with a context for example /context but I'm not sure how to change my routes so that it will be reached at /context instead of hitting my Not Found handler

trancehime03:01:34

Uncaught Error: Assert failed: Invalid Hiccup form: [nil] (in helper_module.core.current_page) (valid-tag? tag) ...I don't get this problem if I run at ROOT context -_-

trancehime04:01:27

OK, I guess it's not really a route problem.

trancehime04:01:01

Seriously, how come it works in path: "/" but if I change it to path: "/context" it breaks

dantsui04:01:18

Hey all. Beginner here with a JS/frontend background. Getting my head around ClojureScript with Mike Walker's Koans, and will build something with FigWheel after. I'd appreciate any additional resources or suggestions.Thanks!

meow05:01:47

Have you looked at Devcards?

dantsui05:01:26

@meow: Looking now. Thank you.

meow05:01:20

there is a #C09GR9UJC channel as well

iae13:01:24

Hello, I would kindly like to ask for some assistance

iae13:01:56

I've converted raw html into the hickory format and have three functions to extract data from it: select-title, select-link, select-description

iae13:01:22

Now I would like to do some kind of mega-map wherein (map [select-title select-link select-description] hickory-html)

iae13:01:59

I think such a function exists in clojure.core, but I can't find it

jonahbenton13:01:31

welcome @iae. to what use do you intend to put the title, link and description data extracted from html?

iae13:01:00

Just console output, it's an exercise from rosetta code to display the first ten search results from yahoo

iae13:01:19

select-title and the others return the content as a string and I'd pipe it to out

iae13:01:56

So ideally one entry would be a vector of ["New Tomorrow (IMDB)" "" "Watch New Tomorrow on Hulu and...." ]

iae13:01:28

I have a working solution to let with three separate lists, one for titles, links, and so forth

iae13:01:39

But I want to refactor that to something more succinct

jonahbenton13:01:10

sure- so it sounds like you have a collection of results, onto each of which you want to apply a collection of functions

iae13:01:04

Yes; my current solution is like so:

jonahbenton13:01:48

yes- instead of open coding the repeated extraction of a specific piece of data from the list 3 times, you want to capture that operation in a functional way as well

jonahbenton13:01:49

so you'll want to have 2 layers- one that goes through each result, and for each result, runs each of a list of functions

jonahbenton13:01:15

could approach it like this- (defn extract-results [results extractors] ...) where extractors is [select-title select-link select-description]

jonahbenton14:01:18

and use 2 for loops

jonahbenton14:01:55

(for [r results] (for [e extractors] (e r))

jonahbenton14:01:53

can use map as well, though one of your collections is a collection of functions, so the semantics are the opposite of what you want- map applies a single function to each element in a collection, not multiple functions to a single piece of data.

iae14:01:48

Oh yeah, I forget that Clojure has for as well! My first thought was to map-map it sorta with (map #(into [] [(select-title %) (select-description %) (select-link %)])

iae14:01:54

But that wasn't too readable

iae14:01:40

Thanks for the tip! I think I was too focused on getting all the functions through in one layer

jonahbenton14:01:40

great! glad you posted

chadhs22:01:31

is anyone in here working on 4clojure problems? i figured out on by experimentation / guess check and don’t feel comfortable with my understanding of why the solution works

chadhs22:01:54

replicate a sequence #33

chadhs22:01:09

i actually think i just rubber duckie answered my question

mfikes22:01:11

@chadhs: I’ve done them. Happy to talk about that one if you’d like.

chadhs22:01:34

@mfikes: thanks thats very kind of you

chadhs22:01:46

i think what i didn’t understand was…

chadhs22:01:15

using mapcat is the same as (apply concat (map…

mfikes22:01:13

I could see how mapcat could be useful, perhaps actually even elegant for that problem.

chadhs22:01:19

my original approach was to just iterate concat across the coll to create a lazy seq and just take n

chadhs22:01:23

then flatten and sort

chadhs22:01:35

moving to pms simple_smile

mfikes22:01:30

Advice for beginners: Give fn a try. Even though # is appealing because it is compact, fn often leads to more readable code, letting you name your arguments, etc. simple_smile

akiva23:01:00

I fully agree. I used to rely on # constantly and now I almost always prefer fn unless it’s something incredibly terse and has only one argument. If you’re using %1 and %2 in a #, you should be using fn.