eriksilkensen
2019-2-23 09:03:30

@eriksilkensen has joined the channel


dnaeon
2019-2-23 11:35:35

@dnaeon has joined the channel


hoshom
2019-2-23 15:53:39

What’s the meaning of the error I’m getting? For this code: #lang typed/racket/base (require typed/racket/class) (define-type Foo<%> (All (A) (Class (field [bar A])))) (define-type Foo (All (A) (Instance (Foo<%> A)))) (define (baz [f : (All (A) (Foo A))]) (get-field bar f))


hoshom
2019-2-23 15:53:51

I get Type Checker: type mismatch; expected an object value for get-field given: Foo in: (get-field bar f)


hoshom
2019-2-23 15:54:41

My understanding is that since type Foo stands for an Instance of some class, get-field should be fine with it, no?


plragde
2019-2-23 16:44:38

@abbyrjones72 While SICP is an important and influential book, there are ways in which it is more difficult than it needs to be. Racket’s roots include, in part, the goal to improve on it. You might be interested in the paper “The Structure and Interpretation of the Computer Science Curriculum”, by Felleisen et al., which goes into more detail. https://www2.ccs.neu.edu/racket/pubs/jfp2004-fffk.pdf


abbyrjones72
2019-2-23 16:56:23

@plragde thank you for this. :slightly_smiling_face:


andreiformiga
2019-2-23 16:59:10

How to Design Programs is another free book, and is written by some of the people behind Racket


abbyrjones72
2019-2-23 17:13:11

Inertia is my friend here. I start my new job on Monday so I will have less time to write code, but I will have a few hours before sleep to do some reading.


abbyrjones72
2019-2-23 17:33:20

Yeah, reading this paper it’s clear that the SICP is great, but what I’m doing is the equivalent of studying C to become better at C++. Two different things. I’ll switch to HTDP/2e this weekend to give that a look.


krismicinski
2019-2-23 18:33:05

I think HtDP will give the general concepts and ergonomics for Racket, though. The methodology is what’s important. The particulars (knowing which for variant to use) aren’t quite as important. I think C/C++ isn’t quite the right comparison, since really HtDP is a subset of Racket that you could use thoughtfully very productively, while if you wrote K&R-style C in C++ it would be a terrible idea :stuck_out_tongue:


krismicinski
2019-2-23 18:34:56

That being said, I can empathize with the feeling that Racket is just a really big language that seemingly goes on forever, and it feels uneasy to use a subset that isn’t the “whole thing.” I felt that way when learning Racket from Scheme.


krismicinski
2019-2-23 18:35:27

The part of Racket that’s hard to learn as a beginner is the extensible features of the language, treating the language as a compiler and language building framework, rather than a static thing (the way we’re used to learning languages) .


krismicinski
2019-2-23 23:08:11

@samth you mentioned that with-syntax was just a macro on top of syntax-case, which makes sense after reading more about syntax case and syntax. Any pointers on places—short of the actual Racket source—that would help build more fine-grained intuition about the macro system in this way? I presume I just need to dig through some papers on it.


krismicinski
2019-2-23 23:09:24

the documentation has some good bits of insight scattered throughout.


krismicinski
2019-2-23 23:11:27

I suspect I won’t really get this until I write a hygienic macro expander myself..


notjack
2019-2-23 23:12:34

For me, understanding how to pass values between macros using define-syntax and syntax-local-value made a lot of other stuff click into place


krismicinski
2019-2-23 23:12:54

ok, that’s good advice


krismicinski
2019-2-23 23:13:03

How did you learn how to do that, just play around with a bunch of examples?


krismicinski
2019-2-23 23:13:18

I haven’t seen syntax-local-value, is that something that messes with the scope sets on syntax objects?


krismicinski
2019-2-23 23:17:18

okay, I see what’s going on here. I also feel like I’d get what’s going on if I could see how it all expands down to fully-expanded racket. Looks like all of this ends up expanding down to define-syntaxes and such.


notjack
2019-2-23 23:17:34

Playing with examples, as well as learning that it’s used to implement these things:

  • match expanders
  • struct transformers (the static info about a struct)
  • syntax-parse pattern expanders (and probably syntax classes)

notjack
2019-2-23 23:19:36

Basically, whenever you need a way to pass around data at compile time between macros, syntax-local-value should be involved somewhere


krismicinski
2019-2-23 23:20:11

that makes sense


sorawee
2019-2-23 23:27:12

The best tutorial for syntax-local-value is https://www.cs.utah.edu/plt/publications/jfp12-draft-fcdf.pdf, section 2.1, IMO


notjack
2019-2-23 23:27:39

Also there’s a really really good chapter somewhere in the racket guide about how modules, phases, and define-syntax interact


krismicinski
2019-2-23 23:27:50

great, this is really helpful.


notjack
2019-2-23 23:33:06

Oh! One more thing that really helped me: the macros as sets of scopes paper and model. Specifically, it helped me a lot to think of identifiers as just strings plus sets of scopes. All of the information for keeping two identifiers with the same name distinct is encoded only in scopes. You don’t actually need gensym at all, and if you find yourself using it in a macro what you probably want to do instead is to create a new scope. You can make your own scopes using make-syntax-introducer, which is named that because the API existed before the set-of-scopes model. A more modern API would probably be something like make-scope combined with identifier-add-scope.


krismicinski
2019-2-23 23:33:32

Yeah, I watched a video by Matt Flatt a few times about this


krismicinski
2019-2-23 23:33:43

notjack
2019-2-23 23:33:49

Yup that one!


krismicinski
2019-2-23 23:33:51

watched this 3–4 times and then read examples..


krismicinski
2019-2-23 23:34:21

the scope sets idea is great, but I don’t have a clear idea about how scope sets relate back to what will get expanded using which set of bindings, etc..


notjack
2019-2-23 23:34:53

yeah I think it’s hard to connect the scope set ideas to the current racket syntax APIs


notjack
2019-2-23 23:35:33

The APIs would probably look a lot different if they were developed after scope sets were figured out


krismicinski
2019-2-23 23:36:06

yeah, this is one challenge I have. There are a few different layers here that all interact in fairly subtle ways


notjack
2019-2-23 23:37:44

It’s not just you. There’s a lot of things that could be done to make the macro system more accessible.


krismicinski
2019-2-24 01:13:11

Yes, this “macros that work together” paper is pretty good


krismicinski
2019-2-24 01:13:27

It’s much more uniform in its economy of using the macro API.


krismicinski
2019-2-24 01:20:06

I also get confused here because papers often use the term “compile-time”, but I realize this is just an approximation of what really happens: racket has multiple phases that expand various things, and so reconciling that high-level notion with the actual implementation is sometimes a bit tricky.


samth
2019-2-24 01:29:51

@krismicinski I find your comment a bit confusing, because there are a few different things in play here (1) the basics of Dybvig-style procedural macros, using define-syntax, syntax-case and syntax (2) Racket’s extensions to those (3) how hygiene works at a non-slogan level (4) the pragmatics of sophisticated metaprogramming in Racket


samth
2019-2-24 01:30:24

your confusion about with-syntax and syntax-case seems to be mostly in (1) but you’ve gotten answers mostly about the others


samth
2019-2-24 01:31:11

I would recommend Dybvig’s “writing hygenic macros in Scheme with syntax-case” as a great macro-writing tutorial


samth
2019-2-24 01:31:43

perhaps especially because it doesn’t treat any of the other more complex topics


notjack
2019-2-24 03:07:01

Has anyone else ever wanted an alternative to make-struct-type that uses keyword arguments?


krismicinski
2019-2-24 04:05:57

@samth yes, thanks for the pointers. I read through this over the past few hours and it has been a great reference. My apologies, I’ve never properly “learned” macro-based programming, only superficially hacked around it..


krismicinski
2019-2-24 04:09:46

I’ll think over this for a few days and work through the examples and see if I have more questions after that..!