Fork me on GitHub
#beginners
<
2017-06-09
>
teodorlu13:06:31

Is the literal string \U valid JSON?

teodorlu13:06:13

Or should it crash due to the starting \U not being followed up by any unicode sequence?

dominicm14:06:21

@teodorlu Does "\u" escape?

teodorlu14:06:43

dominicm: Nope, same behavior from write-str as with "\U".

dominicm14:06:21

Reading the spec for JSON (https://tools.ietf.org/html/rfc7159), particularly https://tools.ietf.org/html/rfc7159#section-7 and https://tools.ietf.org/html/rfc7159#section-8.2 I'm inclined to think that Elm's behaviour may be incorrect.

dominicm14:06:39

Having said that, the browser also interprets capital U's, so clojure probably should too.

teodorlu14:06:22

Advice on how to get around the issue? Would you manually escape \U on the server, or make a more robust string parser client side?

retrazil17:06:26

hi, I am following helsinki mooc for clojure.

retrazil17:06:04

i basically have to make a function (blank? string-here) which tells if the string is blank

retrazil17:06:14

that is if the string is empty or nil, it should return blank

retrazil17:06:19

return true*

retrazil17:06:00

I am using java's Character/isWhiteSpace (as whitespace?)

retrazil17:06:22

(every whitespace? "foo")

retrazil17:06:30

and sure enough it returns false

retrazil17:06:36

but when I do

retrazil17:06:43

(every whitespace? "")

retrazil17:06:49

it returns true

retrazil17:06:12

shouldn't empty string return false in this case since there is no whitespace character in there ?

retrazil18:06:16

sorry it is every? instead of every

john18:06:29

I see your point. I guess, from the context of within a string, a lack of characters could be considered "white space"

retrazil18:06:23

could it ? because i thought i was missing something there. I went to wikipedia and it says whitespace is what it means, whitespace. That got me confused.

retrazil18:06:51

i guess no space whatsoever in this case would mean whitespace ?

donaldball18:06:18

Every character in the string is white space. It’s just trivially true: there are no characters in the string.

retrazil18:06:46

@donaldball i am sorry but i am not sure if i get you 😅

noisesmith18:06:55

according to logic, “for every e in E P(e)” is true for every P if E is empty, right?

john18:06:12

If "" is a string, and it's not 'blank,' what is it?

retrazil18:06:31

empty string ?

john18:06:44

would you say "this string is not blank"

retrazil18:06:53

it is blank

noisesmith18:06:17

maybe what you want is (not (some not-whitespace string))

noisesmith18:06:32

because regardless of your domain, every? is doing the right thing for its definition

retrazil18:06:28

@noisesmith the function works and i got the problem right with every?

retrazil18:06:37

i was just trying to understand why it behaves that way

john18:06:00

If all strings must go into only two categories, blank and not blank, "" is closer to the blank category

noisesmith18:06:14

sure, but you didn’t write the quiz 😄

john18:06:25

right 🙂

retrazil18:06:40

@john the string is blank but it doesn't contain whitespace is what i was saying

retrazil18:06:52

i got the quiz right haha

john18:06:01

oh, lol I see what you're saying.

retrazil18:06:06

i just didn't get this small part

john18:06:17

I think java is intentionally following those "blank" semantics though

retrazil18:06:22

i tested the java function

john18:06:23

so things like every? will work

retrazil18:06:26

it works like expected

retrazil18:06:49

isWhiteSpace doesn't return true for empty character

noisesmith18:06:09

there’s an empty character?

retrazil18:06:21

actually i am not sure if there is an empty character in java

retrazil18:06:46

i got error for ''

noisesmith18:06:19

well ' isn’t clojure syntax for characters, and isn’t a matching delimiter

noisesmith18:06:33

ugh - this bot sucks

noisesmith18:06:51

> (type 'foo)
clojure.lang.Symbol

noisesmith18:06:58

that returns foo - a symbol

noisesmith18:06:12

but \space is the space character

retrazil18:06:25

works fine for space

retrazil18:06:38

also \return works too

noisesmith18:06:48

and ‘foo’ is a symbol ending in ' that prints as foo'

retrazil18:06:57

i am just wondering why it doesn't work for ""

noisesmith18:06:02

“” isn’t a character

mobileink18:06:25

@retrazil blank != whitespace. the latter is a well-defined property of characters, not strings, see https://en.m.wikipedia.org/wiki/Whitespace_character .

retrazil18:06:33

but in case of (every? whitespace? "")

noisesmith18:06:48

right, that could be (every? number? “”)

noisesmith18:06:56

or (every? class? “”)

noisesmith18:06:02

or (every? coll? “”)

noisesmith18:06:08

all are true, because it’s empty

retrazil18:06:47

@noisesmith but whitespace? checks if there is whitespace in the string right

noisesmith18:06:10

@retrazil the function doesn’t even matter - every? knows that all predicates are true on every item of an empty collection

retrazil18:06:46

so you mean if i run every on an empty string

mobileink18:06:51

compare sth like (every? even? [])

retrazil18:06:53

i would get true regardless

donaldball18:06:55

No, I was goofing around with illogical predicates 😛

retrazil18:06:03

i got it 🙂

retrazil18:06:25

that is interesting

john18:06:26

I didn't know running every? on an empty coll returned true

noisesmith18:06:39

it’s a premise of mainstream logic

john18:06:20

@retrazil and every? is treating the string like a collection.

mobileink18:06:02

classic example of how counter-intuitive first-order logic can be.

john18:06:54

seems like every? really means "none false"

mobileink18:06:39

it doesn't really make much sense: intuitively, if P is true of every member of a collection, it must be true of some member. which is not possible with an empty collection.

mobileink18:06:11

it's a conflation of existence and truth.

mobileink18:06:07

like ex falso quodlibet: every true proposition follows from a contradiction.

mobileink18:06:21

@john: but what does "none false" mean? 😉

noisesmith18:06:23

I thought it was “every possible proposition is true, given a contradiction”

dpsutton18:06:50

> P is true of every member of a collection, it must be true of some member. not true. If P is not true for every member of a collection, then there must be some x in the collection for which P is not true

dpsutton18:06:05

give me an example where P is not true. If not, then P is true

mobileink18:06:21

if the collection is empty then the existential quantification fails.

dpsutton18:06:40

that's true. but to negate something you have to show an example where its false

dpsutton18:06:51

that's the way predicate logic is set up

mobileink18:06:04

after all, if "forall x in C, Px" is true for C empty, so is "forall x in C, ~Px".

dpsutton18:06:34

that's true

mobileink18:06:09

you don't have to give an example of false, all you have to do is derive a contradiction. in classic truth-conditional logic, at least. in constructive logic you do have to give an example.

dpsutton18:06:18

where's the contradiction?

dpsutton18:06:38

in your two statements above, if C is empty there is no contradiction

dpsutton18:06:47

> in constructive logic

dpsutton18:06:51

yeah i stay away from that

dpsutton18:06:55

if you mean constructivist

dpsutton18:06:07

i accept that there are infinite sets, thank you very much

mobileink18:06:50

my point is about negation, you only need a contradiction, not an example.

dpsutton18:06:26

well show me the contradiction then. i missed it

mobileink18:06:37

(maybe we should move to #off-topic ?)

seancorfield19:06:49

(or at least remember to use Slack’s threads when you go down a rabbit hole 🙂 )