laurent.orseau
2021-1-1 09:38:49

I suppose it’s about basic facts, so don’t expect much. Without a macro, you’d have to encapsulate expr in a lambda to be able to evaluate it repeatedly.


anything
2021-1-1 14:58:59

I think I’m still encapsulating expr in a lambda above. I couldn’t expand it forever, after all. The title of the section is “Changing an Expression’s Dynamic Context”. I guess I don’t quite [get] the section. No worries, though.


greg
2021-1-1 15:23:54

@anything I only glanced at it quickly. But. I think section 1.5 is setting you up for section 1.6, where you’ll rewrite your forever macro to delegate most of the work to a plain old procedure. Leaving the macro doing just the work that only a macro can do. Which I think is the point of section 1.6?


greg
2021-1-1 15:25:23

I agree with you, though. The forever macro doesn’t seem like an example of “dynamic context”, really. Maybe just ignore that for now and plod ahead? :slightly_smiling_face:


greg
2021-1-1 15:27:19

I don’t know about “dynamic context” but section 1.6 talks about “dynamic behavior”. I understand that to mean “run time” — as opposed to the work your macro does at “compile time”. ¯_(ツ)_/¯


anything
2021-1-1 15:28:26

Hehe. Cool. Thanks so much. I’m continuing.


greg
2021-1-1 15:31:31

One quick thing I’ll mention in case it helps when you’re reading 1.6. Sometimes in Racket there will be a function named call-with-x and it takes a procedure as one of the arguments. And there will also be a with-x macro. Mainly that saves you having to wrap things in a lambda to give to call-with-x. It’s just “sugar”. And so, usually, it’s best to write the call-with-x function, first. And test it, etc. Then finally write the with-x macro. Also that naming convention — call-with- vs. with- — can be nice for people to keep it straight. IMHO.


anything
2021-1-1 15:32:45

Nice! Thanks!


anything
2021-1-1 15:54:36

I think your paragraph above is fantastically insightful!


louis
2021-1-1 21:09:34

@louis has joined the channel


anything
2021-1-2 01:14:00

I’m not sure what is the idiom here. I can’t write the procedure below because ~begin doesn’t accept that define~ I can’t write a define when an expression is apparently expected. It’s not clear what I’m violating here. (All I wanted to do was to write an else-clause for the if with more than one statement.)

(define (call-with-my-and ls-of-fn) (if (null? ls-of-fn) #f (begin (define first-boolean ((car ls-of-fn))) (if first-boolean first-boolean (call-with-my-and (rest ls-of-fn)))))) fact-example-syntax.rkt> ; fact-example-syntax.rkt::735: define: not allowed in an expression context ; in: (define first-boolean ((car ls-of-fn))) So I wrote it as… (define (call-with-my-and ls-of-fn) (cond [(null? ls-of-fn) #f] [else (define first-boolean ((car ls-of-fn))) (if first-boolean first-boolean (call-with-my-and (rest ls-of-fn)))]))


sorawee
2021-1-2 01:17:39

cond is the right thing to use here


sorawee
2021-1-2 01:18:07

But if you really want to use if, switch (begin ...) to (let () ...)


anything
2021-1-2 01:18:42

Got ya. Let me expand begin and see what it’s made of! (Just thought of that.)


anything
2021-1-2 01:19:26

It seems to be a primitive. It expands to itself.


sorawee
2021-1-2 01:20:24

What do you mean by that?


anything
2021-1-2 01:22:31

I mean expanding it doesn’t seem to change it into anything else. For example, if I write (f x) this get expanded to something like (#%app f x), but (begin 1 2 3) expands to (begin (quote 1) (quote 2) (quote 3)). (I thought of checking out what sort of macro begin was.)


sorawee
2021-1-2 01:22:53

Not exactly


sorawee
2021-1-2 01:22:56

begin is weird. I wrote about it here: https://github.com/racket/rhombus-brainstorming/issues/87. Might be of your interest.


anything
2021-1-2 01:23:43

Yes, I thought it was meant to group things. Cool. I’ll study this.


anything
2021-1-2 01:26:29

Maybe I shouldn’t as I’m kinda of just seeing the problem here, but I gave it a +1 there. I do like different names for different things and obvious names are great. For instance, block seems nicer than begin. I think I prefer progn over begin. I have been able to invent a meaning for progn in my mind, but I never did for begin. So maybe I would have voted for splicing-block. But I don’t really know what’s going on. So nevermind that.