Fork me on GitHub
#beginners
<
2017-05-22
>
noisesmith01:05:42

a message of "foo cannot be cast to clojure.lan.IFn" means that somewhere in your code you have a foo in parens

noisesmith01:05:28

notice ((let ...))

noisesmith01:05:42

your function is returning a string from the let, and then trying to call the string

vitruvia01:05:00

that was it

vitruvia01:05:04

again a parenthesis problem

noisesmith01:05:15

also, truthy? can be replaced by another function that already exists, called identity

vitruvia01:05:48

how do you guys manage to keep your parens in check so well? 😂

vitruvia01:05:56

that is good to know

noisesmith01:05:06

@vitruvia there's things you eventually know to look out for

noisesmith01:05:16

((...)) is pretty much always suspicious to me

noisesmith01:05:36

I mean, sometimes I directly use a function that returns another function, but that's not the normal way to do things

noisesmith01:05:07

and the error messages - as soon as I see "cannot be cast to IFn" I look for extra parens, because that's what that message pretty much always means

vitruvia01:05:56

I say IFn and thought it had something to do with a function

noisesmith01:05:08

right, (x) means x needs to be a function

noisesmith01:05:22

that error is saying "hey, x isn't a function, it's a String"

vitruvia01:05:48

by the way is there a way to return "falsey"as a value instead of a string?

noisesmith01:05:03

or nil, that would work too

vitruvia01:05:26

yes but if I had to return some personalized falsey value, would there be a way?

noisesmith01:05:00

a common way to do that would be falsey - which is a keyword namespaced to the current namespace

noisesmith01:05:14

which indicates that it belongs to, or is particularly relevant to, that namespace

vitruvia01:05:48

Thanks. I'll play around with that

lilactown03:05:23

@vitruvia a good editor/plugin can help as well - I've used parinfer for visual studio code, and currently use the emacs setup that Brave Clojure offered

vitruvia03:05:29

I'm working on learning vim

vitruvia03:05:45

hopefully it will help, but for this intro course that I'm doing I`ll finish with lighttable

noisesmith03:05:35

if something wants you to return "falsey" you should return false or nil

grounded_sage06:05:14

I've got some semi-colons in a string

grounded_sage06:05:37

How do I have it register as a semi-colon and not a comment...

akiroz06:05:18

@grounded_sage how did you get semicolons in a string to register as a comment?

grounded_sage06:05:24

@akiroz I'm doing :dangerouslySetInnerHTML in Rum. Got some embed code from another website and just pasted it in. It's registering it as a comment and completely messing up the embed lol. The semicolon is for the style tags

grounded_sage06:05:43

[:div { :dangerouslySetInnerHTML {:__html 
                                       "<div class=\"typeform-widget\" data-url=\"https://wade93m.typeform.com/to/bmlrGC\" 
       style="width: 100% =>}}]; height: 500px;" > </div> <script> (function() { var qs,js,q,s,d=document, gi=d.getElementById, ce=d.createElement, gt=d.getElementsByTagName, id="typef_orm", b=""; if(!gi.call(d,id)) { js=ce.call(d,"script"); js.id=id; js.src=b+"embed.js"; q=gt.call(d,"script")[0]; q.parentNode.insertBefore(js,q) } })() </script> <div style="font-family: Sans-Serif;font-size: 12px;color: #999;opacity: 0.5; padding-top: 5px;" > powered by <a href="https://www.typeform.com/examples/surveys/?utm_campaign=bmlrGC&amp;utm_source=typeform.com-393933-Basic&amp;utm_medium=typeform&amp;utm_content=typeform-embedded-onlinesurvey&amp;utm_term=EN" style="color: #999" target="_blank">Typeform</a> </div>"}}] 

akiroz06:05:30

I think you need to escape every "

grounded_sage06:05:55

The problem is thet the ; comments out the rest of the line

akiroz06:05:23

if you escape every " then the ; won't be treated as code

grounded_sage06:05:27

I started commenting them but didn't go into the commented out pieces. THANKS!

lepistane09:05:19

guys i've got sql question hope someone can help

lepistane09:05:25

create table forums( id int auto_increment primary key, name varchar(50) not null, description varchar(250), ownerUsername varchar(30) not null, -- owner creationDate datetime not null, -- creation date locked boolean not null, type varchar(30) not null, parentForumId int, -- nadforum, deleted boolean not null, FOREIGN KEY (ownerUsername) REFERENCES users(username), FOREIGN KEY (parentForumId) REFERENCES forums(id) );

lepistane09:05:28

this is my table

lepistane09:05:36

i have tree like structure

lepistane09:05:51

forum1 has (forum 2, forum 3( has forum 4, forum 5))

lepistane09:05:14

i wanna make statement or function that would delete all children if parent is 'deleted' (deleted set to 1 )

lepistane09:05:18

i am using mysql

lepistane09:05:30

and i kinda saw something i could use

lepistane09:05:41

i am just not sure how to make use of it

lepistane11:05:21

i gotta say something

lepistane11:05:27

who hasnt read and studied SICP

lepistane11:05:34

i strongly urge him to do so

lepistane11:05:38

it will make you better programmer

lepistane11:05:03

because without it i wouldn't have been able to deal with tree structure

lepistane11:05:39

i wrote java function that recursively asks for ids of all children deletes rows with those ids and repeats proces till null (root is found)

lepistane11:05:46

works like magic

lepistane11:05:02

tl:dr - STUDY SICP

petrus12:05:22

Having a hard time with sente + component system. Whenever I try to send an event from the client to the server, I get "Chsk send against closed chsk." Do I need to wait for a state update from the server? Is my socket not connecting properly? I seem to be getting events from the server, I just can't send from the client.

gekkostate14:05:07

Hi everyone! Just a quick question. I am using org-mode to do some literate programming. Is there a way for me to take a code block and paste it into my repl easily?

agile_geek15:05:04

@gekkostate other than mark the region and kill-ring-save?

noisesmith17:05:17

@petrus it’s possible to check the state of the socket from the client. In my app I run a block of core.async code that captures messages instead of sending them until the connection is confirmed active, then it sends the backlogged messages

noisesmith17:05:40

usually it’s just a question of pausing message sends until the the socket is established -it should be a short lived state

pmonks18:05:35

Random brain fart: am I right in suddenly realising that def and ns are super weird? By that I mean they are fundamentally mutable in nature (they directly modify "global state"), counter to virtually everything else in Clojure?

john18:05:44

@pmonks That's correct. The top level is pretty much your typical lisp, fully modifiable repl environment.

john18:05:44

Immutable namespaces would be an interesting exercise. I think some folks tried it. Didn't get much traction. Not sure why. Might be a lot of complexity.

pmonks18:05:20

Cool! Yeah namespaces are weird anyway - coming from a Java background it does my head in that they're not just a compile-time construct.

pmonks18:05:29

(i.e. more akin to Java packages)

john18:05:03

It's just that in most repling situations, you want to re-def things, so as to test different things.

pmonks18:05:25

Yeah - don't get me wrong, I love being able to def the same var as many times as I need while experimenting.

pmonks18:05:39

I guess it's probably a rather bad practice to do that in library code though.

pmonks18:05:07

e.g. using def within an fn.

john18:05:20

yeah, once the namespace is written, you generally don't want dynamic constructs mutating that namespace. So Clojure allows you to enjoy the benefits of both worlds, sort of.

john18:05:44

Though some interesting magical things are possible with immutable namespaces.

john18:05:35

but probably won't ever be a supported use case in clojure

mobileink18:05:45

@pmonks on the other hand, def, defn, etc. are just macros. nothing wrong with writing your own def-like macros in your lib.

pmonks18:05:42

@mobileink yeah, though I have a hard time coming up with a scenario where I'd do that vs, say, just having a (def ^:private my-mutable-state (atom ...)) that I mutate within a public fn using swap!.

pmonks18:05:15

atoms seem like the "safe" way to do this kind of thing, vs (ab)using def.

mobileink18:05:47

metaprogramming is my use case. my deffoo macros add private metadata to the var (among other things), so they behave just like clojure constructs, but my tools can do devious things with them.

noisesmith19:05:26

@pmonks right - don’t use namespaces / vars as data structures, if you need to create or update data at runtime use one of clojure’s nice concurrent mutable containers like atom or ref

noisesmith19:05:54

and sure, put that atom or ref inside a def, namespaces are nice to use from code