notjack
2020-8-25 07:01:28

related, I wish there was a scribble form for documenting syntax classes and their attributes


sorawee
2020-8-25 07:11:09

there is, internally. I added it somewhere



sorawee
2020-8-25 07:14:56

(To be clear, the form for documenting syntax class was there already, but it didn’t support specifying attributes. Supporting attributes is what I added)


kellysmith12.21
2020-8-25 12:42:04

Is there a rule of thumb for deciding when to define attributes for a syntax class and when to define a transformation using syntax-parse?


cris2000.espinoza677
2020-8-25 16:34:59

if there’s a possibility of writing repetitive code for just one body of a function, should I write a macro for it? eg: (define (sql-row->person row #:order [order #(id name age number employer address ...)]) (define h (for/hash ([(k v) (in-dict order)]) (values v k))) (define (get key [default #f]) (if (dict-has-key? order key) (vector-ref row key) default)) (define id (get 'id)) (define name (get 'name)) ... ;; rest of procedure )


laurent.orseau
2020-8-25 16:37:33

Can you write a function instead?


cris2000.espinoza677
2020-8-25 16:38:11

i mean yes i guess “functions are better and you should avoid macros when you can” is something i just remembered reading


cris2000.espinoza677
2020-8-25 16:43:22

i think im very lazy seeing those (define identifier (get ’identifier)) and thinking “well well isn’t that just #'(define name (get 'name))” and can even be #'(define name (if (dict-has-key? order 'name) (vector-ref row 'name) default-expr)) and so it’s more a question of if i should… because im thinking that way a procedure wouldn’t be built (get ), so it goes “faster” but that speed gain must be insignificant honestly… i think i need to change my mentality if anything


laurent.orseau
2020-8-25 16:44:48

Yes, that’s one case where you could legitimately use a macro: (define-simple-macro (define-get id:id) (define id (get 'id))) (untested)


laurent.orseau
2020-8-25 16:45:11

then just write (define-get name)


laurent.orseau
2020-8-25 16:45:27

maybe define/get would be more idiomatic


laurent.orseau
2020-8-25 16:46:22

It’s likely that speed is not going to be the first issue here indeed


laurent.orseau
2020-8-25 16:46:59

(It’s legitimate because you’re playing with identifiers)


greg
2020-8-25 16:53:52

Is there a way for a lang like #lang pollen by @mbutterick to communicate that it uses a non-@ “command character”? Such that a tool could pass that to make-scribble-lexer https://docs.racket-lang.org/syntax-color/index.html#%28def._%28%28lib._syntax-color%2Fscribble-lexer..rkt%29._make-scribble-lexer%29%29 ? (I mean, ideally I’d like for there to exist such a way, and for module-lexer to use that to call make-scribble-lexer automatically. And so, this might end up being a PR. But first I’m double-checking, is there some get-info or other means to communicate the non-standard command character. Or is that another PR.)


greg
2020-8-25 16:56:46

(By “a tool”, I mean DrRacket or Racket Mode, etc.)


cris2000.espinoza677
2020-8-25 17:07:51

is define-simple-macro supposedly to be require’d by for-syntax ? right? i get an error even though i have (for-syntax racket/syntax syntax/parse syntax/parse/define) which of course only syntax/parse/define provides define-simple-macro … but idk im confused


cris2000.espinoza677
2020-8-25 17:08:06

it’s also in top level


laurent.orseau
2020-8-25 17:09:20

(require syntax/parse/define)


laurent.orseau
2020-8-25 17:09:40

yes, requires for macro can be a little confusing at times :slightly_smiling_face:


cris2000.espinoza677
2020-8-25 17:09:41

but why is it a runtime thing?


cris2000.espinoza677
2020-8-25 17:09:48

what…


laurent.orseau
2020-8-25 17:11:50

When you use define-simple-macro itself, you don’t use it inside a for-syntax, so you shouldn’t require it for-syntax


cris2000.espinoza677
2020-8-25 17:13:16

i see, so because it’s a macro itself that expands to a define-syntax?


laurent.orseau
2020-8-25 17:13:53

yes


cris2000.espinoza677
2020-8-25 17:14:19

but doesnt it mean it is a 0-level macro and the calls to it doesnt convert to a perfomance boost/compile-time transformation?


laurent.orseau
2020-8-25 17:15:43

You can test this by compiling your program with raco make ...


laurent.orseau
2020-8-25 17:15:54

you’ll see whether it has been transformed or not


cris2000.espinoza677
2020-8-25 17:16:06

i see…


cris2000.espinoza677
2020-8-25 17:16:46

should i define macros inside of functions? or is it better to have them on top level


sorawee
2020-8-25 17:17:04

For Pollen specifically, you can read pollen.rkt’s setup submodule and read the value of command-char: https://docs.racket-lang.org/pollen/Setup.html#%28def._%28%28lib._pollen%2Fsetup..rkt%29._setup~3acommand-char%29%29


laurent.orseau
2020-8-25 17:17:16

better at top level


cris2000.espinoza677
2020-8-25 17:17:56

mmm… ill do that raco make thing. how do i debug bytecode though?


sorawee
2020-8-25 17:18:08

Note that the value is user-customizable. I often set it back to @.


sorawee
2020-8-25 17:19:58

I don’t think it’s a business of DrRacket or Racket Mode to be aware of Pollen’s convention, though.


cris2000.espinoza677
2020-8-25 17:20:12

either way thank you for answering and clearing my doubts :blush:


laurent.orseau
2020-8-25 17:20:17

oh sorry, I meant raco expand ...


laurent.orseau
2020-8-25 17:20:34

raco make will give you bytecode indeed


cris2000.espinoza677
2020-8-25 17:20:42

ooh ok


sorawee
2020-8-25 17:21:27

If your macro usage is truly local to one function, defining a macro inside a function works too.


laurent.orseau
2020-8-25 17:22:23

It works, but it can get tricky for the compiler no?


laurent.orseau
2020-8-25 17:22:37

(in the sense of efficiency)


sorawee
2020-8-25 17:23:24

I don’t see why it’s going to be much more inefficient than the usual macro. Plus, it’s done at compile-time anyway.


cris2000.espinoza677
2020-8-25 17:23:44

i mean in this case it’s less about efficiency and more “i’m too lazy to type”


laurent.orseau
2020-8-25 17:29:25

@sorawee ok the compiler is smarter than I thought :slightly_smiling_face:


laurent.orseau
2020-8-25 17:29:50

(I thought it could be bothered by things like keywords or optional args)


greg
2020-8-25 17:40:10

If an editor tool uses a lexer to do syntax highlighting and indentation, it needs to know about scribble and the “command char”. e.g. Is @foo to be lexed/colored as a symbol or as text. And the indentation convention for scribble are different than plain sexps (as implemented by e.g. DrR).


greg
2020-8-25 17:41:12

So AFAICT it’s pretty crucial to know what is the “command char”, for those things to work.


greg
2020-8-25 17:42:30

(Generally Racket is pretty awesome in enabling a lang to supply this information directly. There are just a couple “holes” I’ve found so far. One is this.)


greg
2020-8-25 17:45:50

(Another is telling a lexer colorer about “delimiter pairs” that might be other than parens, braces, brackets. Currently this seems to be configuration external to the language itself. The only example of that I’ve found so far is “ProfessorJ”.


greg
2020-8-25 17:46:41

So the paradigm there seems to be, “A ‘language’ is drscheme:tool code loaded by DrRacket’s Choose Language command” — as opposed to, “A module language entirely determined by #lang and get-info”. I think? If so, this makes it unsuitable for use outside DrRacket (and not entirely satisfactory for lang implementors, either, I think?).


greg
2020-8-25 17:47:46

I’m guessing that just predates the concept of a module language.


popa.bogdanp
2020-8-25 17:50:16

You probably know this, but custom languages can provide color lexers that tools can access. Could Racket Mode use that to highlight custom language code on the fly? Would it be too slow?



popa.bogdanp
2020-8-25 17:52:11

Oh, whoops, I went searching for docs and totally missed your latest comments above.


soegaard2
2020-8-25 18:16:35

> I’m guessing that just predates the concept of a module language. At least it predates submodules.

Introducing an “indentation time” in analogy to “documentation time” (for-doc) would be an interesting way of communicating how forms are to be indented.


soegaard2
2020-8-25 18:17:13

Are you looking at introducing support for at-expressions to the racket-mode indenter?


greg
2020-8-25 19:31:41

I have a branch for Racket Mode that uses a lang-supplied lexer. It needs a lot of work but I’ve been dog-fooding it for awhile, on and off.


greg
2020-8-25 19:32:30

It’s been working well for syntax highlighting.


greg
2020-8-25 19:33:24

Indentation is tricky because the status quo get-info returns a drracket:indnetation and that presumes a GUI framework text<%>, which won’t really work well for e.g. Racket Mode.


greg
2020-8-25 19:33:54

So I’ve been fleshing out a non-GUI alternative, to offer as a proposal.


greg
2020-8-25 19:35:14

TL;DR if you write an indenter, you usually want it to work on an already-lexed data structure with a few basic operations like “up expression”, “next expression”, etc.


greg
2020-8-25 19:35:43

The text<%> interface offers that… but also pulls in a whole bunch of other, “heavy”, GUI things.


greg
2020-8-25 19:36:38

I need to find some time to write some prose about all this. Probably not a blog post, yet, because one goal of writing it down is for Robby to help point out things I’ve misunderstood, so I can revise it. :smile:


greg
2020-8-25 19:37:23

Oh, also, I want to make it work well for non-sexp langs. As I mentioned above it I think the status quo is a bit weak for that, IIUC.


greg
2020-8-25 19:37:54

Not that I really love non-sexp langs, but if people going to make them, I’d like to support them. :smile:


soegaard2
2020-8-25 19:39:41

Lately I have used at-expression to generate JavaScript using React components (via Urlang). It looks like this:


popa.bogdanp
2020-8-25 19:46:16

If you need #langs to test with north has a fairly weird custom lang (that comes with a color lexer).


soegaard2
2020-8-25 19:49:30

In a nested at-expression like @foo[ @bar[ ...]] The current (I think it is current) racket-mode indenter wants to indent it like: @foo[ @bar[ ... ]] Similarly in pairs like: name1: property1 name2: property2 name3: property3 the second line is indented like this: name1: property1 name2: property2 name3: property3 fortunately, after indenting line2 manually, line 3 and forth is indented as I want it.

Note: This is just a data point - I know the current idententer doesn’t hanle at-expressions.


greg
2020-8-25 19:59:11

Ugh I just realized I posted this in #beginners not #general. Sorry all. Maybe I should step away from the keyboard for awhile.


soegaard2
2020-8-25 19:59:55

No worries.


yilin.wei10
2020-8-25 20:19:21

Hello, why does scribble strip out the underscore in this bit of code @defthing[_internal-allocation-type ctype?]{What?}?


yilin.wei10
2020-8-25 20:20:02


sorawee
2020-8-25 20:21:49

> _id typesets as id, but colored as a variable (like racketvarfont); this escape applies only if _id has no for-label binding and is not specifically colored as a subform non-terminal via defform, a variable via defproc, etc.


sorawee
2020-8-25 20:22:35

So it looks like if you require for-label the identifier, it should work fine?


yilin.wei10
2020-8-25 20:23:09

Hmm - I see; at the moment the bindings which is probably the issue.


yilin.wei10
2020-8-25 20:24:31

Thank you; the behaviour is super surprising to me based on the documentation for defthing


thurtu811
2020-8-26 02:14:18

@thurtu811 has joined the channel