startup-in-a-month

https://www.twitch.tv/a_fry_
bringe 2021-01-28T00:09:38.016300Z

So if you actually evaluate the whole comment form it doesn't evaluate any of the forms inside it. That's basically the point of it. When you use a comment form as a playground you need to evaluate each form inside it individually. In Calva, alt+enter if inside a form inside a comment form, will evaluate the top level form inside the comment.

bringe 2021-01-28T00:10:21.016500Z

So if you put your cursor in the first def like here: (def |hey "hey") and hit alt-enter the whole def form there will be evaluated, not the outer comment form.

bringe 2021-01-28T00:10:57.016700Z

It follows usual evaluation rules from within the comment form.

bringe 2021-01-28T00:11:17.016900Z

So if you wanted to eval all those defs at once for some reason, you could put them inside a do

bringe 2021-01-28T00:12:44.017100Z

Usually you'd be working with individual forms though. Maybe you want to try some code that has var names in it already - instead of using individual defs you could use one let.

(let [hey "hey"
        wat "wat"]
    (str hey wat))

bringe 2021-01-28T00:22:48.018300Z

Sounds like you got the hang of it!

pez 2021-01-28T07:46:01.018600Z

Just want to add about the top-level evaluation inside comment forms. The way it is designed is that the comment form creates a new top level context. Let’s look at your example, @andyfry01:

(comment
    (def hey "hey")
    (def wat "wat")
    (str hey w|at))
(The | represents the cursor.) Since the comment form created a new top level context, what the top-level evaluator “sees” is this:
(def hey "hey")
(def wat "wat")
(str hey w|at)
And since the current one top level form then is Which is then evaluated, and if hey is not defined, well, you’ve seen what happens.Just want to add about the top-level evaluation inside comment forms. The way it is designed is that the comment form creates a new top level context. Let’s look at your example, @andyfry01:
(comment
    (def hey "hey")
    (def wat "wat")
    (str hey w|at))
(The | represents the cursor.) Since the comment form created a new top level context, what the top-level evaluator “sees” is this:
(def hey "hey")
(def wat "wat")
(str hey w|at)
And since the current one top level form then is (str hey wat) that is then evaluated, and if hey is not defined, well, you’ve seen what happens. You expect the whole contents of the comment form to be evaluated. I can see why, but the thing is that if we didn’t treat comment forms special at all what would be evaluated is the whole comment form (not just it’s content) and that would give you nil. Calva tries to make it easy for you to be in complete control of what is evaluated. So inside that Rich comment block you can move between redefining hey and then evaluate the str expression. You might not want to evaluate the last mentioned one at the same time (it could be expensive in some way). So, you are in control. Sometimes we do want to evaluate a bunch of expressions in one go. For this Clojure gives us the do macro. So
(comment
  (do
    (def hey "hey")
    (def wat "wat")
    (str hey w|at)))
I hope I didn’t confuse things now… 😃

2021-01-28T12:30:03.018800Z

Ah, that's a really interesting way to think about comment: a new top-level context. Like a namespace inside a namespace, where you can get the advantage of using all of the other vars which are defined in the parent namespace, but you don't have to worry about anything in the comment form interfering with the parent namespace. I can dig that. Block scoped variables in ES6 Javascript is the parallel that springs to mind right away:

const parentNamespace = () => {
    const variable = "Hello from the outer context"

    const richComment = () => {
        const variable = "Hello from the inner context"
        console.log(variable) 
    }
    
    richComment() // -> "Hello from the inner context"
    console.log(variable)
}

parentNamespace() // -> "Hello from the outer context"

2021-01-28T12:32:54.019Z

And yeah, I can see the benefit of defining and loading individual vars within a comment form as opposed to loading the whole comment form all at once. I'll give that do thing a try when I've got some setup code that I want to run all at once.

2021-01-28T12:34:33.019200Z

You guys have been invaluable this month for my Clojure growing pains 😅 Thanks so much for all of the tips, it's really improving my workflow

pez 2021-01-28T12:52:48.019400Z

You are most welcome, sir!

pez 2021-01-28T12:55:40.019600Z

About namespacing. Note that this is only a structural thing regarding the text in the file. When you evaluate something in the comment block it will both be “from” the same namespace as the file and “to” the same namespace. So hey will be defined in the file’s namespace. Don’t know if you meant anything else, but just in case. 😃

pez 2021-01-28T12:56:41.019800Z

Looking at your ES6 example it seems like my clarification was needed. Haha.

pez 2021-01-28T12:59:37.020Z

Clojure has global bindings that can be scoped by namespaces, and local bindings that are lexically scoped, much like the ES6 example there.

bringe 2021-01-28T19:56:15.020200Z

> the thing is that if we didn’t treat `comment` forms special at all what would be evaluated is the whole `comment` form (not just it’s content) and that would give you `nil`. Just to clarify here, and maybe Peter meant this, but if the whole comment form is evaluated, the result is nil and none of the forms inside it are evaluated.

1➕
bringe 2021-01-28T19:56:53.020400Z

So if you have defs in there and they haven't been evaluated, and you evaluate the whole comment form, those vars will still not be defined.

1➕