[ClojureScript] Re: Using `not` for keywords

2015-01-15 Thread Yehonathan Sharvit
Because in my app , it is clearer from a semantic point of view, it is clearer 
as the value stands for a question asked to the user.

-- 
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: Using `not` for keywords

2015-01-15 Thread Francis Avila
There is no protocol for truthiness, which is what you want. nil and false 
are false, everything else is true.

Even if there were a protocol for truthiness, you could not use :yes and :no 
(keywords), you would have to create your own custom type and implement the 
protocol on it. (Think about it: what if the truthiness of a *specific* keyword 
depended on application code you didn't write? E.g. if some library globally 
redefined the truthiness protocol on keywords so that :no is false?)

Clojure is philosophically opposed to making truthiness user-definable. Many 
other languages (including lisp and scheme) have not-very-simple truthiness 
rules that Clojure deliberately simplified. Allowing user-definable truthiness 
would bring all that complexity back *and then some*.

You have a problem-domain-specific use of :yes and :no and a 
problem-domain-specific notion of truthiness. You can either use functions 
which implement that domain notion (which you have done, and which is the best 
approach I think), or you can write your *own* protocol for this and extend it 
either to custom YES NO types or keywords.

You could also create a boundary in your application where you convert from a 
:yes-:no representation to a more native true-false.

It smells like a bad design that you have the *same* function and code 
accepting both :yes and :no *and* true and false. Since this is a 
domain-specific problem and type, it seems like the same code shouldn't be used 
in both cases. I.e., your not function should be:

(defn a-not [answer]
  (case answer
:yes :no
:no :yes
(throw (ex-info (str Not a valid questionnaire answer:  (pr-str answer)) 
{}


On Wednesday, January 14, 2015 at 2:50:21 PM UTC-6, Yehonathan Sharvit wrote:
 In my app, I am using :yes and :no sometimes instead of true and false.
 
 
 
 
 I’d like to know what is the best way to extends the `not` function to be 
 able to handle :yes and :no properly.
 
 
 
 
 I was expecting some kind of Boolean protocol but I wasn’t able to find it.
 
 
 
 
 I could write this:
 
 
 
 
 
 
 (defn not [x]
 
   (case x
 
     :yes :no
 
     :no :yes
 
     (cljs.core.not x)))
 
 
 
 
 (map not [false true :yes :no]); (true false :no :yes)
 
 
 
 
 But I’m not sure it is the most idiomatic solution.
 
 Any ideas?
 
 
 
 —
 Sent from Mailbox

-- 
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: Using `not` for keywords

2015-01-15 Thread Thomas Heller
Boolean is not a protocol. It is a native datatype, just like in Clojure.

-- 
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: Using `not` for keywords

2015-01-15 Thread Thomas Heller
On Thursday, January 15, 2015 at 5:08:27 PM UTC+1, Yehonathan Sharvit wrote:
 Because in my app , it is clearer from a semantic point of view, it is 
 clearer as the value stands for a question asked to the user.

How about

(ns my-ns.util)

(def YES true)
(def NO false)

(ns my-ns
   (:use my-ns.util))

(map not [false true YES NO])


Using :yes/:no will really eat into your ability to use anything that expects 
true/false.

HTH

-- 
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: [ANN] Clojure/West 2015 Call for Presentations

2015-01-15 Thread Alex Miller
Just to be clear, Clojure should be read in a big tent way here to include 
ClojureScript and anything Clojure-related of course. ClojureScript talks 
desired!!

Alex

-- 
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] core.async equivalent of Clojurescript/NodeJS nested callbacks

2015-01-15 Thread Christian Weilbach
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 15.01.2015 12:57, gvim wrote:
 Here is a Clojurescript database connection in NodeJS and below it
 the JS I ported it from. 2 questions:
 
 1. I believe core.async is the way instead of replicating NodeJS
 nested callbacks. What is the equivalent using core.async? 2. I
 couldn't get ((.rows result) 0) to work for result.rows[0]. 
 result.rows worked as-is in cljs but I don't understand why.
 
 gvim

I am not sure whether I understand your problem correctly, but if the
js callback API guarantees transactional safety around your queries,
then you cannot use core.async internally, but only expose channels to
the outside. I have done the same thing for IndexedDB, core.async
didn't work, because the callbacks are basically transformed to the
heap and the actual transaction is over when the channel operations
continue (because it is closed with the stack in case of IndexedDB).

https://github.com/ghubber/konserve/blob/master/src/cljs/konserve/indexeddb.cljs

Btw. if the konserve kv-protocol fits your needs feel free to
implement it ;-).

Cheers,
Christian

 
 
 
 (ns ndpg.core (:require [cljs.nodejs :as n]))
 
 (n/enable-util-print!)
 
 (def pg (n/require pg)) (def con
 postgres://admin:p@localhost:5432/astro) (def client (pg.Client.
 con))
 
 (.connect client (fn [err] (if err (.error js/console Couldn't
 connect err) (.query client select * from births (fn [err
 result] (if err (.error js/console Query error err) (do (.log
 js/console result.rows) (.end client
 
 (defn -main [] (println (range 1 100)))
 
 (set! *main-cli-fn* -main)
 
 ;;; JS ;;
 
 var con = postgres://admin:p@localhost:5432/db;
 
 var client = new pg.Client(con); client.connect(function(err) { 
 if(err) { return console.error(Couldn't connect, err); } 
 client.query('SELECT * FROM births', function(err, result) { 
 if(err) { return console.error('Query error', err); } 
 console.log(result.rows[0]); client.end(); }); });
 

-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iQEcBAEBAgAGBQJUt7R+AAoJEKel+aujRZMkc7AH/jHOIyBZpmQewU7kwtA7yrYh
SGXajVI5TAtdICRsxE75Dea8UaGPc85sxIy4P7uSz73YyzgqJN5ZDRa1wcUOBdkQ
eYTmjdjhGqhEwtYi2EtRuxsXBkrQCk6bF4bEMEkiL3g9T/yoskTKwutqE4BvATO8
s5SCG17fBnqsDkwJnOTMy+FscMJkG0t4LOyAFONGbMovGhmhBEkYnGHrrNMEIzhs
92tEeV36GW7O9C72iXQtDqA/BmXBGgpCuF3cCTykuXpQn9JX5u0m3KCntvFBbbuB
NLEOG+j2TvXFstH0NVhBUwQ0LdM2cWhwE8txvsimp38W1PW5n2booaQPRYGwPLA=
=98DC
-END PGP SIGNATURE-

-- 
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.