[ClojureScript] Re: map with anonymous function
As others have said, #() is like a function body, so the first item in its list must be callable or a macro. But no one mentioned you can use "do": #(do [:th %]) On Sunday, August 3, 2014 7:53:47 AM UTC-5, Paul Cowan wrote: > I am using om and soblano and I have a map function that works when I declare > at like this, on the last line of the function below: > > > > (defn ical [data] > (reify > om/IDisplayName > > (display-name [_] > (or (:react-name opts) "calendar")) > om/IRender > (render [this] > (html/html [:div > [:div.calendar-toolbar > > [:div.btn-group.pull-right > [:a.right {:href "#"} "Right"] > [:a.left {:href "#"} "Left"]] > > [:h3 "August 2014"]] > [:table.table > [:thead > [:tr (map (fn [day] [:th day]) weekdays) > > > > But when I try and use the map with the anonymous function syntax like this: > > > [:table.table > [:thead > [:tr (map ([:th %]) weekdays) > > > I get the following error: > > Uncaught Error: Invalid arity: 1 > > > > > > Cheers > > Paul Cowan > > Cutting-Edge Solutions (Scotland) > > > blog: http://thesoftwaresimpleton.com/ > > website: http://www.cuttingedgesolutionsscotland.com/ -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript.
Re: [ClojureScript] Re: map with anonymous function
Rather than use identity, I usually do this: #(vector :th %) On 3 August 2014 21:11, Shaun Gilchrist wrote: > identity is just a function that returns its argument. It may be more > readable to do #(vec [:th %]). And just for golf-sake you could also do > (map (partial conj [:th]) weekdays). All that said I think the "for" > approach is the easiest to read. > > > On Sun, Aug 3, 2014 at 12:54 PM, Paul Cowan wrote: > >> Right in both counts, thanks! >> >> Could you explain why identity is needed in this instance, I'm new to >> clojure and I don't quite get why it is need specifically here. >> >> Cheers >> >> Paul Cowan >> >> Cutting-Edge Solutions (Scotland) >> >> blog: http://thesoftwaresimpleton.com/ >> website: http://www.cuttingedgesolutionsscotland.com/ >> >> >> On 3 August 2014 19:31, Shaun Gilchrist wrote: >> >>> Consider that what you are doing expands to the application of a vector >>> to nothing (thus the error): >>> >>> (fn [x] ([:th x])) >>> >>> What you are most likely after is #(identity [:th %]] >>> >>> But perhaps more readably - [:tr (for [day weekdays] [:th day])] >>> >>> >>> >>> On Sun, Aug 3, 2014 at 11:18 AM, Paul Cowan wrote: >>> Hi, Sorry that was a typo on my part, that is what I have and it still gives the same error: [:table.table.table-striped.table-bordered.table-hover [:thead [:tr (map #([:th %]) weekdays) And it gives the error: Uncaught Error: Invalid arity: 1 Is this a clojurescript error? Can you not use anonymous functions in clojurescript Cheers Paul Cowan Cutting-Edge Solutions (Scotland) blog: http://thesoftwaresimpleton.com/ website: http://www.cuttingedgesolutionsscotland.com/ On 3 August 2014 18:08, Johann Bestowrous wrote: > Hey Paul-- > > try this: > > [:table.table > [:thead > [:tr (map #([:th %]) weekdays) > > #() is an anonymous function literal. > > On Sunday, August 3, 2014 5:53:47 AM UTC-7, Paul Cowan wrote: > > I am using om and soblano and I have a map function that works when > I declare at like this, on the last line of the function below: > > > > > > > > (defn ical [data] > > (reify > > om/IDisplayName > > > > (display-name [_] > > (or (:react-name opts) "calendar")) > > om/IRender > > (render [this] > > (html/html [:div > >[:div.calendar-toolbar > > > > [:div.btn-group.pull-right > > [:a.right {:href "#"} "Right"] > > [:a.left {:href "#"} "Left"]] > > > > [:h3 "August 2014"]] > > [:table.table > > [:thead > > [:tr (map (fn [day] [:th day]) > weekdays) > > > > > > > > But when I try and use the map with the anonymous function syntax > like this: > > > > > > [:table.table > > [:thead > > [:tr (map ([:th %]) weekdays) > > > > > > I get the following error: > > > > Uncaught Error: Invalid arity: 1 > > > > > > > > > > > > Cheers > > > > Paul Cowan > > > > Cutting-Edge Solutions (Scotland) > > > > > > blog: http://thesoftwaresimpleton.com/ > > > > website: http://www.cuttingedgesolutionsscotland.com/ > > -- > Note that posts from new members are moderated - please be patient > with your first post. > --- > You received this message because you are subscribed to the Google > Groups "ClojureScript" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to clojurescript+unsubscr...@googlegroups.com. > To post to this group, send email to clojurescript@googlegroups.com. > Visit this group at http://groups.google.com/group/clojurescript. > -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript. >>> >>> -- >>> Note that posts from new members are moderated - please be patient with >>> your first post. >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "ClojureScript" group. >>> To u
Re: [ClojureScript] Re: map with anonymous function
identity is just a function that returns its argument. It may be more readable to do #(vec [:th %]). And just for golf-sake you could also do (map (partial conj [:th]) weekdays). All that said I think the "for" approach is the easiest to read. On Sun, Aug 3, 2014 at 12:54 PM, Paul Cowan wrote: > Right in both counts, thanks! > > Could you explain why identity is needed in this instance, I'm new to > clojure and I don't quite get why it is need specifically here. > > Cheers > > Paul Cowan > > Cutting-Edge Solutions (Scotland) > > blog: http://thesoftwaresimpleton.com/ > website: http://www.cuttingedgesolutionsscotland.com/ > > > On 3 August 2014 19:31, Shaun Gilchrist wrote: > >> Consider that what you are doing expands to the application of a vector >> to nothing (thus the error): >> >> (fn [x] ([:th x])) >> >> What you are most likely after is #(identity [:th %]] >> >> But perhaps more readably - [:tr (for [day weekdays] [:th day])] >> >> >> >> On Sun, Aug 3, 2014 at 11:18 AM, Paul Cowan wrote: >> >>> Hi, >>> >>> Sorry that was a typo on my part, that is what I have and it still gives >>> the same error: >>> >>> >>> [:table.table.table-striped.table-bordered.table-hover >>> [:thead >>> [:tr (map #([:th %]) weekdays) >>> >>> And it gives the error: >>> >>> >>> Uncaught Error: Invalid arity: 1 >>> Is this a clojurescript error? Can you not use anonymous functions in >>> clojurescript >>> >>> >>> Cheers >>> >>> Paul Cowan >>> >>> Cutting-Edge Solutions (Scotland) >>> >>> blog: http://thesoftwaresimpleton.com/ >>> website: http://www.cuttingedgesolutionsscotland.com/ >>> >>> >>> On 3 August 2014 18:08, Johann Bestowrous >>> wrote: >>> Hey Paul-- try this: [:table.table [:thead [:tr (map #([:th %]) weekdays) #() is an anonymous function literal. On Sunday, August 3, 2014 5:53:47 AM UTC-7, Paul Cowan wrote: > I am using om and soblano and I have a map function that works when I declare at like this, on the last line of the function below: > > > > (defn ical [data] > (reify > om/IDisplayName > > (display-name [_] > (or (:react-name opts) "calendar")) > om/IRender > (render [this] > (html/html [:div >[:div.calendar-toolbar > > [:div.btn-group.pull-right > [:a.right {:href "#"} "Right"] > [:a.left {:href "#"} "Left"]] > > [:h3 "August 2014"]] > [:table.table > [:thead > [:tr (map (fn [day] [:th day]) weekdays) > > > > But when I try and use the map with the anonymous function syntax like this: > > > [:table.table > [:thead > [:tr (map ([:th %]) weekdays) > > > I get the following error: > > Uncaught Error: Invalid arity: 1 > > > > > > Cheers > > Paul Cowan > > Cutting-Edge Solutions (Scotland) > > > blog: http://thesoftwaresimpleton.com/ > > website: http://www.cuttingedgesolutionsscotland.com/ -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript. >>> >>> -- >>> Note that posts from new members are moderated - please be patient with >>> your first post. >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "ClojureScript" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to clojurescript+unsubscr...@googlegroups.com. >>> To post to this group, send email to clojurescript@googlegroups.com. >>> Visit this group at http://groups.google.com/group/clojurescript. >>> >> >> -- >> Note that posts from new members are moderated - please be patient with >> your first post. >> --- >> You received this message because you are subscribed to the Google Groups >> "ClojureScript" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojurescript+unsubscr...@googlegroups.com. >> To post to this group, send email to clojurescript@googlegroups.com. >> Visit this group at http://groups.google.com/group/clojurescript. >> > > -- > Note
Re: [ClojureScript] Re: map with anonymous function
Right in both counts, thanks! Could you explain why identity is needed in this instance, I'm new to clojure and I don't quite get why it is need specifically here. Cheers Paul Cowan Cutting-Edge Solutions (Scotland) blog: http://thesoftwaresimpleton.com/ website: http://www.cuttingedgesolutionsscotland.com/ On 3 August 2014 19:31, Shaun Gilchrist wrote: > Consider that what you are doing expands to the application of a vector to > nothing (thus the error): > > (fn [x] ([:th x])) > > What you are most likely after is #(identity [:th %]] > > But perhaps more readably - [:tr (for [day weekdays] [:th day])] > > > > On Sun, Aug 3, 2014 at 11:18 AM, Paul Cowan wrote: > >> Hi, >> >> Sorry that was a typo on my part, that is what I have and it still gives >> the same error: >> >> [:table.table.table-striped.table-bordered.table-hover >> [:thead >> [:tr (map #([:th %]) weekdays) >> >> And it gives the error: >> >> >> Uncaught Error: Invalid arity: 1 >> Is this a clojurescript error? Can you not use anonymous functions in >> clojurescript >> >> >> Cheers >> >> Paul Cowan >> >> Cutting-Edge Solutions (Scotland) >> >> blog: http://thesoftwaresimpleton.com/ >> website: http://www.cuttingedgesolutionsscotland.com/ >> >> >> On 3 August 2014 18:08, Johann Bestowrous >> wrote: >> >>> Hey Paul-- >>> >>> try this: >>> >>> [:table.table >>> [:thead >>> [:tr (map #([:th %]) weekdays) >>> >>> #() is an anonymous function literal. >>> >>> On Sunday, August 3, 2014 5:53:47 AM UTC-7, Paul Cowan wrote: >>> > I am using om and soblano and I have a map function that works when I >>> declare at like this, on the last line of the function below: >>> > >>> > >>> > >>> > (defn ical [data] >>> > (reify >>> > om/IDisplayName >>> > >>> > (display-name [_] >>> > (or (:react-name opts) "calendar")) >>> > om/IRender >>> > (render [this] >>> > (html/html [:div >>> >[:div.calendar-toolbar >>> > >>> > [:div.btn-group.pull-right >>> > [:a.right {:href "#"} "Right"] >>> > [:a.left {:href "#"} "Left"]] >>> > >>> > [:h3 "August 2014"]] >>> > [:table.table >>> > [:thead >>> > [:tr (map (fn [day] [:th day]) >>> weekdays) >>> > >>> > >>> > >>> > But when I try and use the map with the anonymous function syntax like >>> this: >>> > >>> > >>> > [:table.table >>> > [:thead >>> > [:tr (map ([:th %]) weekdays) >>> > >>> > >>> > I get the following error: >>> > >>> > Uncaught Error: Invalid arity: 1 >>> > >>> > >>> > >>> > >>> > >>> > Cheers >>> > >>> > Paul Cowan >>> > >>> > Cutting-Edge Solutions (Scotland) >>> > >>> > >>> > blog: http://thesoftwaresimpleton.com/ >>> > >>> > website: http://www.cuttingedgesolutionsscotland.com/ >>> >>> -- >>> Note that posts from new members are moderated - please be patient with >>> your first post. >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "ClojureScript" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to clojurescript+unsubscr...@googlegroups.com. >>> To post to this group, send email to clojurescript@googlegroups.com. >>> Visit this group at http://groups.google.com/group/clojurescript. >>> >> >> -- >> Note that posts from new members are moderated - please be patient with >> your first post. >> --- >> You received this message because you are subscribed to the Google Groups >> "ClojureScript" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojurescript+unsubscr...@googlegroups.com. >> To post to this group, send email to clojurescript@googlegroups.com. >> Visit this group at http://groups.google.com/group/clojurescript. >> > > -- > Note that posts from new members are moderated - please be patient with > your first post. > --- > You received this message because you are subscribed to the Google Groups > "ClojureScript" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojurescript+unsubscr...@googlegroups.com. > To post to this group, send email to clojurescript@googlegroups.com. > Visit this group at http://groups.google.com/group/clojurescript. > -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript.
Re: [ClojureScript] Re: map with anonymous function
Consider that what you are doing expands to the application of a vector to nothing (thus the error): (fn [x] ([:th x])) What you are most likely after is #(identity [:th %]] But perhaps more readably - [:tr (for [day weekdays] [:th day])] On Sun, Aug 3, 2014 at 11:18 AM, Paul Cowan wrote: > Hi, > > Sorry that was a typo on my part, that is what I have and it still gives > the same error: > > [:table.table.table-striped.table-bordered.table-hover > [:thead > [:tr (map #([:th %]) weekdays) > > And it gives the error: > > > Uncaught Error: Invalid arity: 1 > Is this a clojurescript error? Can you not use anonymous functions in > clojurescript > > > Cheers > > Paul Cowan > > Cutting-Edge Solutions (Scotland) > > blog: http://thesoftwaresimpleton.com/ > website: http://www.cuttingedgesolutionsscotland.com/ > > > On 3 August 2014 18:08, Johann Bestowrous > wrote: > >> Hey Paul-- >> >> try this: >> >> [:table.table >> [:thead >> [:tr (map #([:th %]) weekdays) >> >> #() is an anonymous function literal. >> >> On Sunday, August 3, 2014 5:53:47 AM UTC-7, Paul Cowan wrote: >> > I am using om and soblano and I have a map function that works when I >> declare at like this, on the last line of the function below: >> > >> > >> > >> > (defn ical [data] >> > (reify >> > om/IDisplayName >> > >> > (display-name [_] >> > (or (:react-name opts) "calendar")) >> > om/IRender >> > (render [this] >> > (html/html [:div >> >[:div.calendar-toolbar >> > >> > [:div.btn-group.pull-right >> > [:a.right {:href "#"} "Right"] >> > [:a.left {:href "#"} "Left"]] >> > >> > [:h3 "August 2014"]] >> > [:table.table >> > [:thead >> > [:tr (map (fn [day] [:th day]) >> weekdays) >> > >> > >> > >> > But when I try and use the map with the anonymous function syntax like >> this: >> > >> > >> > [:table.table >> > [:thead >> > [:tr (map ([:th %]) weekdays) >> > >> > >> > I get the following error: >> > >> > Uncaught Error: Invalid arity: 1 >> > >> > >> > >> > >> > >> > Cheers >> > >> > Paul Cowan >> > >> > Cutting-Edge Solutions (Scotland) >> > >> > >> > blog: http://thesoftwaresimpleton.com/ >> > >> > website: http://www.cuttingedgesolutionsscotland.com/ >> >> -- >> Note that posts from new members are moderated - please be patient with >> your first post. >> --- >> You received this message because you are subscribed to the Google Groups >> "ClojureScript" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojurescript+unsubscr...@googlegroups.com. >> To post to this group, send email to clojurescript@googlegroups.com. >> Visit this group at http://groups.google.com/group/clojurescript. >> > > -- > Note that posts from new members are moderated - please be patient with > your first post. > --- > You received this message because you are subscribed to the Google Groups > "ClojureScript" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojurescript+unsubscr...@googlegroups.com. > To post to this group, send email to clojurescript@googlegroups.com. > Visit this group at http://groups.google.com/group/clojurescript. > -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript.
Re: [ClojureScript] Re: map with anonymous function
Hi, Sorry that was a typo on my part, that is what I have and it still gives the same error: [:table.table.table-striped.table-bordered.table-hover [:thead [:tr (map #([:th %]) weekdays) And it gives the error: Uncaught Error: Invalid arity: 1 Is this a clojurescript error? Can you not use anonymous functions in clojurescript Cheers Paul Cowan Cutting-Edge Solutions (Scotland) blog: http://thesoftwaresimpleton.com/ website: http://www.cuttingedgesolutionsscotland.com/ On 3 August 2014 18:08, Johann Bestowrous wrote: > Hey Paul-- > > try this: > > [:table.table > [:thead > [:tr (map #([:th %]) weekdays) > > #() is an anonymous function literal. > > On Sunday, August 3, 2014 5:53:47 AM UTC-7, Paul Cowan wrote: > > I am using om and soblano and I have a map function that works when I > declare at like this, on the last line of the function below: > > > > > > > > (defn ical [data] > > (reify > > om/IDisplayName > > > > (display-name [_] > > (or (:react-name opts) "calendar")) > > om/IRender > > (render [this] > > (html/html [:div > >[:div.calendar-toolbar > > > > [:div.btn-group.pull-right > > [:a.right {:href "#"} "Right"] > > [:a.left {:href "#"} "Left"]] > > > > [:h3 "August 2014"]] > > [:table.table > > [:thead > > [:tr (map (fn [day] [:th day]) > weekdays) > > > > > > > > But when I try and use the map with the anonymous function syntax like > this: > > > > > > [:table.table > > [:thead > > [:tr (map ([:th %]) weekdays) > > > > > > I get the following error: > > > > Uncaught Error: Invalid arity: 1 > > > > > > > > > > > > Cheers > > > > Paul Cowan > > > > Cutting-Edge Solutions (Scotland) > > > > > > blog: http://thesoftwaresimpleton.com/ > > > > website: http://www.cuttingedgesolutionsscotland.com/ > > -- > Note that posts from new members are moderated - please be patient with > your first post. > --- > You received this message because you are subscribed to the Google Groups > "ClojureScript" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojurescript+unsubscr...@googlegroups.com. > To post to this group, send email to clojurescript@googlegroups.com. > Visit this group at http://groups.google.com/group/clojurescript. > -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript.
[ClojureScript] Re: map with anonymous function
Hey Paul-- try this: [:table.table [:thead [:tr (map #([:th %]) weekdays) #() is an anonymous function literal. On Sunday, August 3, 2014 5:53:47 AM UTC-7, Paul Cowan wrote: > I am using om and soblano and I have a map function that works when I declare > at like this, on the last line of the function below: > > > > (defn ical [data] > (reify > om/IDisplayName > > (display-name [_] > (or (:react-name opts) "calendar")) > om/IRender > (render [this] > (html/html [:div > [:div.calendar-toolbar > > [:div.btn-group.pull-right > [:a.right {:href "#"} "Right"] > [:a.left {:href "#"} "Left"]] > > [:h3 "August 2014"]] > [:table.table > [:thead > [:tr (map (fn [day] [:th day]) weekdays) > > > > But when I try and use the map with the anonymous function syntax like this: > > > [:table.table > [:thead > [:tr (map ([:th %]) weekdays) > > > I get the following error: > > Uncaught Error: Invalid arity: 1 > > > > > > Cheers > > Paul Cowan > > Cutting-Edge Solutions (Scotland) > > > blog: http://thesoftwaresimpleton.com/ > > website: http://www.cuttingedgesolutionsscotland.com/ -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript.