Re: any?
some On Sunday, April 26, 2015 at 9:32:09 AM UTC+8, Colin Taylor wrote: > > Any reason why we don't have `any?`. Googled without much luck. > Trivially done as `comp boolean some` not doubt, but I know I use it more > than not-any at least. > It's particularly useful as a composable `or`. > > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: any?
The main use case for the non-boolean aspect of `some` is when you use it to find the first element of a sequence that is in a particular set. (some #{} []) The idea is that when you get a "hit", the return value is the specific element of the *set* that matched. This is a useful trick for turning values into something canonical that can be compared with your canonical values using identical? => (def a (with-meta [1 2] {:canonical true})) => (some #{a} [(list 1 2)]) [1 2] => (meta (some #{a} [(list 1 2)])) {:canonical true} => (identical? a (some #{a} [(list 1 2)])) true On Sun, Apr 26, 2015 at 12:02 AM, Isaac Zeng wrote: > some > > > On Sunday, April 26, 2015 at 9:32:09 AM UTC+8, Colin Taylor wrote: >> >> Any reason why we don't have `any?`. Googled without much luck. >> Trivially done as `comp boolean some` not doubt, but I know I use it more >> than not-any at least. >> It's particularly useful as a composable `or`. >> >> >> -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: any?
On 26 April 2015 at 06:08, Colin Taylor wrote: > So I was thinking of: > > user=> (any? true? [false true false]) > true > user=> (any? even? [1 2 3]) > true > ; touch "3" > user=> (any? #(.exists %) [(file "1") (file "2") (file "3")]) > true > Those examples all work with `some` as well: user=> (some true? [false true false]) true user=> (some even? [1 2 3]) true user=> (some #(.exists %) [(file "1") (file "2") (file "3")]) true Some motivations > > - my main one is Java interop where use of non booleans would be weird > That's a valid reason, but it's not a common enough case to justify its own function, IMO. Also, in cases where the type matters, having to add an explicit `boolean` onto the front makes the code clearer. > - similarly it is nicer for APIs to return booleans than a value that is > kinda arbitrary and potentially non deterministic. I might recall Rich > saying something like that..? > The `some` function isn't unusual. A lot of boolean logic functions in Clojure return a "truthy" or "falsey" value, rather than true or false explicitly. user=> (and true 1) 1 user=> (and nil true) nil user=> (or true 1) 1 > - the symmetry of `any` joining `not-any`, `every` and `not-every`. > That's true, but then you have two functions, `some` and `any?`, that do the same thing under most circumstances. That strikes me as somewhat confusing, especially as `any?` is essentially a niche-case operation. - James -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Performance of defmulti in both ClojureScript and Clojure
Thanks for that great rundown, Alex! I am also very interested in how the different approaches to dynamic dispatch compare in CLJS, if anyone is able to shed some light on that. Especially, whether or not case is const time — the doc string says it is, but your comments seem to suggest that it might not be the.. case. Ivan Reese -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: any?
Oh uggh wheres the delete post button. I'll blame the 3 mth old with reflux for that. On Monday, April 27, 2015 at 12:56:04 AM UTC+12, James Reeves wrote: > > Those examples all work with `some` as well: > > user=> (some true? [false true false]) > true > user=> (some even? [1 2 3]) > true > user=> (some #(.exists %) [(file "1") (file "2") (file "3")]) > true > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: ANN: ClojureScript 0.0-3211
Hey Davis, would you mind replying to this topic? Thanks! https://groups.google.com/forum/#!topic/clojure/7oROqb6dGSU On Saturday, April 25, 2015 at 7:12:31 PM UTC-4, David Nolen wrote: > > You need to make sure some other dependency isn't pulling in a different > version of tools.reader. > > David > > On Sat, Apr 25, 2015 at 11:11 PM, Allen Rohner > wrote: > >> >> >> On Saturday, April 25, 2015 at 12:02:08 PM UTC-5, Mike Fikes wrote: >>> >>> Hey Tony, try updating the version of Clojure in your project.clj to >>> 1.7.0-beta1, which is used by 0.0-3211. >>> >>> (In short, reader/read was given a second arity to allow options to be >>> passed, thus supporting #? conditional reading.) >> >> >> I'm seeing the same behavior on 1.7.0-beta2. Yes, I've cleaned. >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com >> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+u...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: ANN: ClojureScript 0.0-3211
Hey David, would you mind replying to this topic? Thanks! https://groups.google.com/forum/#!topic/clojure/7oROqb6dGSU Dang typo! On Saturday, April 25, 2015 at 7:12:31 PM UTC-4, David Nolen wrote: > > You need to make sure some other dependency isn't pulling in a different > version of tools.reader. > > David > > On Sat, Apr 25, 2015 at 11:11 PM, Allen Rohner > wrote: > >> >> >> On Saturday, April 25, 2015 at 12:02:08 PM UTC-5, Mike Fikes wrote: >>> >>> Hey Tony, try updating the version of Clojure in your project.clj to >>> 1.7.0-beta1, which is used by 0.0-3211. >>> >>> (In short, reader/read was given a second arity to allow options to be >>> passed, thus supporting #? conditional reading.) >> >> >> I'm seeing the same behavior on 1.7.0-beta2. Yes, I've cleaned. >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com >> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/clojure?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+u...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Performance of defmulti in both ClojureScript and Clojure
Nearly all the performance notes about Clojure multimethods apply to ClojureScript. On Saturday, April 25, 2015, Alex Miller wrote: > I should say all of that is for Clojure and likely bears no similarity to > the nuances in ClojureScript. > > On Saturday, April 25, 2015 at 9:39:06 PM UTC-5, Alex Miller wrote: >> >> On Saturday, April 25, 2015 at 9:33:18 AM UTC-5, Timur wrote: >>> >>> Hi everyone, >>> >>> There are situations where I want to dispatch functions using based on >>> their certain properties. I can also use case statements instead but it >>> looks more coupled and more change is required if I want to add new types. >>> >> >> case is useful for the particular situation where you have a finite set >> of compile-time constants that you are looking for (integers, characters, >> etc). Then case will leverage a special JVM bytecode that performs a >> *constant-time* look-up (not linear-time like checking a series of cond >> conditions, etc). This is one of the two bytecode options (tableswitch, >> rather than lookupswitch) underlying the Java switch/case feature. >> >> What I want to ask is if I need to avoid using multi-methods for >>> performance reasons? I read somewhere that they are not really fast but the >>> posts were old and the performance might have been improved in between. >>> Should I favor case and cond branches instead of defmulti when I need >>> performance? >>> >> >> multimethods are slower than protocols - they must effectively invoke the >> dispatch function, perform a linear search for a match across the cases, >> and then invoke the actual implementation function. Protocols leverage JVM >> internals to select the right implementation, then invoke it. However, the >> search part of multimethods is cached, making that step fast after the >> initial call. The last time I benchmarked multimethods with class dispatch >> vs protocols on Java 1.8 + Clojure 1.7 alphas (can't remember which one), I >> found multimethods were about 5x slower. >> >> If you want fastest type-based dispatch with open extension, then >> protocols are the best. >> If you want any other type of dispatch with open extension, then >> multimethods are the best. >> If you want a closed system of constant choices, then case is best >> (constant-time lookup!) >> If you want a closed system of arbitrary conditions, then cond is best. >> >> I have never compared the performance of cond vs multimethods for >> something like this. My guess is that multimethods are faster as they >> evaluate a single condition, then do a table lookup once cached vs >> evaluating a series of conditions every time. >> >> Alex >> >> -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ANN] Ring-swagger 0.20.0, Compojure-api 0.20.0 & other schema/web libs
Hi all, We here at Metosin have been developing some open source libs, mostly stuff related to web. Most of the libs have got big new releases lately, so though of promoting them here too. Here goes: * *Ring-Swagger 0.20.0* (https://github.com/metosin/ring-swagger) - support lib for generating Swagger 1.2 & 2.0 specs out of clojure web apps - build on top of Prismatic Schema with enhanced coercion, serialization & middlewares - extracts Swagger JSON Schemas out of deeply nested Prismatic Schemas - external routing lib adapters using ring-swagger: - Compojure-api - Fnhouse-swagger (https://github.com/metosin/fnhouse-swagger) - Pedestal-swagger (https://github.com/frankiesardo/pedestal-swagger) - just hit the 20k download mark, thanks for all the contributors! * *Compojure-api 0.20.0* (https://github.com/metosin/compojure-api) - started out as a macro learning experiment, but turned into a feature-rich api lib on top of Compojure - schema-based validation, doc-generation & extension points for adding your own stuff in - latest version now with naked Swagger 2.0 support, all known bugs fixed * *Ring-http-response 0.6.1* (https://github.com/metosin/ring-http-response) - complete set of http response functions and predicates, now partially also for ClojureScript * *Schema-tools 0.4.0* (https://github.com/metosin/schema-tools) - helpers for manipulating the Prismatic Schemas (schema-aware map-operations, walkers etc.) * *scjsv 0.2.0* (https://github.com/metosin/scjsv) - Simple Clojure JSON Schema Validator, tiny wrapper for https://github.com/fge/json-schema-validator * *Ring-swagger-ui* 2.1.1-M2 - just a jar-packaged and preconfigured (for ring-swagger) latest version of the Swagger-UI - all props to Reverb technologies for the awesomeness We are currently developing a macro-free Swagger-enabled CQRS lib and for that, abstracting & extracting stuff from our real projects & compojure-api back to ring-swagger & to maybe to new web-related schema-libs. Trying to go with the "one library does one thing good" -approach with small and extendable libraries. One target is to clean up a pluggable symmetric serialization & coercion for all common data types with out-of-the-box coverage the common wire-formats (json, edn, transit, (s/maybe xml)). Contributions welcome and we are happy to help others to adapt the stuff we have been doing, so feel free to ping us - firstname @metosin.fi or ikitommi / Deraen at freenode. Tommi & Juho -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.